79623712

Date: 2025-05-15 15:34:26
Score: 8.5 🚩
Natty:
Report link

@Mahrez, it seems the same error so nothing changed. I test the code and the problem is that the form is not valid. Your answer is when the form is valid before to apply the save code. please, could you check again or anyone can help me, please.

def Insert_group(request):
    print(f" The begining Request method is : {request.method}")
    sEtat = "crea"
    data = {
        "created_at": datetime.today(),
        "updated_at": datetime.today(),
        "UTIL_CREATION": settings.WCURUSER,
        "UTIL_MODIF": settings.WCURUSER,
        "Soc_sigle": settings.WSOCGEN,
    }
    if request.method == 'POST':
        print('Yes i am in  POST method')
        LibELE_GROUPE = request.POST.get("LibELE_GROUPE")

        form = f_groupe_userForm(request.POST)
        print(request.method)
        if form.has_changed():
            print("The following fields changed: %s" % ", ".join(form.changed_data))
        if form.is_valid():

            groupe = form.save(commit=False)
            groupe.updated_at         = datetime.today()
            groupe.created_at         = datetime.today()
            groupe.UTIL_CREATION      = settings.WCURUSER
            groupe.UTIL_MODIF         = settings.WCURUSER
            groupe.Soc_sigle          = settings.WSOCGEN

            if LibELE_GROUPE is not None:
                print(f"LibELE_GROUPE value is  : {LibELE_GROUPE}")
                if 'Ajouter' in request.POST:
                    print('Yes we can insert now')
                    groupe.save()
                    print('insert successful!!!')
                    return HttpResponseRedirect("CreateGroup/success")
                else:
                    return HttpResponseRedirect("CreateGroup")

            else:
                # In reality we'd use a form class
                # to get proper validation errors.
                return HttpResponse("fields libelle is empty!")
                # "Make sure all fields are entered and valid.")
            ## Process the form data
            # pass
            # return redirect('success')
        else:
            #print('form pas valide')
            print("The following fields are not valid : %s" % ", ".join(form.errors.as_data()))

            return render(request, 'appMenuAdministrator/L_liste_GroupeUtilisateur/FicheCreaGroupe1.html', {'form': form})
    else:
        form = f_groupe_userForm()
        data = data
        # print(f"La valeur de libellé est : {LibELE_GROUPE}")
        return render(request, 'appMenuAdministrator/L_liste_GroupeUtilisateur/FicheCreaGroupe1.html', {'form': form, 'sEtat': sEtat, 'data': data})


15/May/2025 15:19:43] "GET /static/css/all.min.css HTTP/1.1" 404 1985
 The begining Request method is : GET
[15/May/2025 15:19:45] "GET /AccessAdmin/Insert_group HTTP/1.1" 200 11230
[15/May/2025 15:19:45] "GET /static/css/all.min.css HTTP/1.1" 404 1985
 The begining Request method is : POST
Yes i am in  POST method
POST
The following fields changed: LibELE_GROUPE
The following fields are not valid : UTIL_CREATION, UTIL_MODIF, Soc_sigle, created_at, updated_at
[15/May/2025 15:19:55] "POST /AccessAdmin/Insert_group HTTP/1.1" 200 11181
[15/May/2025 15:19:55] "GET /static/css/all.min.css HTTP/1.1" 404 1985

Reasons:
  • Blacklisted phrase (1): help me
  • RegEx Blacklisted phrase (3): anyone can help me
  • RegEx Blacklisted phrase (2): help me, please
  • RegEx Blacklisted phrase (0.5): anyone can help
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @Mahrez
  • Self-answer (0.5):
  • Looks like a comment (1):
  • Low reputation (1):
Posted by: Fulbert KOFFI