html file:
<div class="row">
<div class="col-md">
<div class="card card-body">
<form action="" method="POST" enctype="multipart/form-data">
{% csrf_token %}
<h5>Informations</h5>
<hr>
<p>Nom: </p>
<fieldset>
<input name="LibELE_GROUPE" type="text" id="LibELE_GROUPE" value={{LibELE_GROUPE}} size="35" placeholder="Nom du groupe" tabindex="1" required>*
</fieldset>
<fieldset>
<input name="created_at" type="text" id="created_at" value={{created_at}} size="35" placeholder="" tabindex="2" style="display:None;">
</fieldset>
<fieldset>
<input name="updated_at" type="text" id="updated_at" value={{updated_at}} size="35" placeholder="" tabindex="3" style="display:None;">
</fieldset>
<fieldset>
<input name="UTIL_CREATION" type="text" id="UTIL_CREATION" value={{UTIL_CREATION}} size="35" placeholder="" tabindex="4" style="display:None;">
</fieldset>
<fieldset>
<input name="UTIL_MODIF" type="text" id="UTIL_MODIF" value={{UTIL_MODIF}} size="35" placeholder="" tabindex="5" style="display:None;">
</fieldset>
<fieldset>
<input name="Soc_sigle" type="text" id="Soc_sigle" value={{Soc_sigle}} size="35" placeholder="" tabindex="6" style="display:None;">
</fieldset>
</form>
</div>
</div>
<div class="col-md">
<div class="card card-body" style="width:200px; margin-left:70%;">
<!--<h5>Client:</h5>-->
<hr>
<input class="b4 btn-outline-success btn-sm btn-block" type="submit" value="Submit" style="font-size: 10px; " >
</div>
</div>
</div>
<br>
<div class="row">
<div class="col">
<div class="card card-body">
<form method="get">
<button class="btn btn-primary" type="submit">Search</button>
</form>
</div>
</div>
</div>
<br>
<div class="row">
<div class="col-md">
<div class="card card-body">
<table class="table table-sm">
<tr>
<th>Produit</th>
<th>Categorie</th>
<th>Date de Commande</th>
<th>Status</th>
<th>Mise à Jour</th>
<th>Supprimer</th>
</tr>
</table>
</div>
</div>
</div>
<!--https://stackoverflow.com/questions/72089986/how-to-toggle-between-button-display -->
<script>
</script>
{% endblock content%}
Views file:
def groupAddok(request):
if request.method == 'POST':
print('Je rentre dans group addok')
sEtat="modif"
created_at = localize(
datetime.now())
updated_at = localize(datetime.now())
UTIL_CREATION = settings.WCURUSER
UTIL_MODIF = settings.WCURUSER
Soc_sigle = settings.WSOCGEN
LibELE_GROUPE ='Traiter'
form = f_groupe_userForm(request.POST)
print(request.method)
if form.has_changed():
print("The following fields changed: %s" % ", ".join(form.changed_data))
#form.changed_data
if form.is_valid():
print(form.cleaned_data)
if LibELE_GROUPE is not None :
print('Libelle saisi')
f_groupe_user = f_groupe_user(LibELE_GROUPE = LibELE_GROUPE, created_at = created_at, updated_at = updated_at, UTIL_CREATION = UTIL_CREATION, UTIL_MODIF = UTIL_MODIF, Soc_sigle = Soc_sigle)
print('la valeur du groupe est ')
print('f_groupe_user')
if 'Ajouter' in request.POST:
print('Oui on peut ajouter')
f_groupe_user.save()
print('ajout effectué!!!')
return HttpResponseRedirect("CreateGroup/success")
else:
return HttpResponseRedirect("CreateGroup")
else:
return HttpResponse("Vous devriez vous assurer que tous les champs sont renseignés et validés!")
else:
print('form pas valide')
return render(request, 'appMenuAdministrator/list_groupes.html', {'form': form})
else:
print('La valeur de la methode est avec la form est invalide -- ')
print(request.method)
form = f_groupe_userForm()
return render(request, 'appMenuAdministrator/list_groupes.html', {'form': form})
forms file:
class f_groupe_userForm(forms.ModelForm):
class Meta:
model = f_groupe_user
fields = ['LibELE_GROUPE', 'UTIL_CREATION', 'UTIL_MODIF']
labels = {'LibELE_GROUPE': 'Nom*', 'created_at': 'Date de création', 'updated_at': 'Date de modification', 'UTIL_CREATION': 'UTIL CREATION', 'UTIL_MODIF': 'UTIL MODIF'}
#exclude = ["Soc_sigle"]
widgets={
'name' : forms.TextInput(attrs={'class':'form-control'}),
}
help_texts = {
"LibELE_GROUPE": _("Donner le nom du groupe utilisateur"),
}
error_messages = {
"name": {
"max_length": _("Ce nom du groupe est trop long."),
},
}
models file:
class f_groupe_user(models.Model):
IDF_GROUPE_USER=models.AutoField(primary_key=True)
LibELE_GROUPE= models.CharField(max_length=120)
Soc_sigle = models.CharField(max_length=120, editable=False)
created_at=models.DateTimeField(auto_now_add=True)
updated_at= models.DateTimeField(auto_now=True)
UTIL_CREATION= models.CharField(max_length=120)
UTIL_MODIF= models.CharField(max_length=120)
urls file:
path("groupAddok", views.groupAddok, name="groupAddok"),
But not put when submit button:
[03/Oct/2024 23:27:08] "GET /AccessAdmin/EspaceAdministrator HTTP/1.1" 200 6704
[03/Oct/2024 23:27:08] "GET /static/css/all.min.css HTTP/1.1" 404 1985
La valeur de la methode est avec la form est invalide --
GET
[03/Oct/2024 23:27:15] "GET /AccessAdmin/groupAddok HTTP/1.1" 200 6994
[03/Oct/2024 23:27:15] "GET /static/css/all.min.css HTTP/1.1" 404 1985
Please help to fix