8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-22 03:13:12 +00:00

Save que si l'objet a été modifié

This commit is contained in:
Gabriel Detraz 2018-04-01 00:06:44 +02:00 committed by chirac
parent a553789bad
commit 543037b667
4 changed files with 100 additions and 84 deletions

View file

@ -249,8 +249,10 @@ def edit_facture(request, facture, factureid):
) )
vente_form = vente_form_set(request.POST or None, queryset=ventes_objects) vente_form = vente_form_set(request.POST or None, queryset=ventes_objects)
if facture_form.is_valid() and vente_form.is_valid(): if facture_form.is_valid() and vente_form.is_valid():
facture_form.save() if facture_form.changed_data:
vente_form.save() facture_form.save()
if vente_form.changed_data:
vente_form.save()
messages.success(request, "La facture a bien été modifiée") messages.success(request, "La facture a bien été modifiée")
return redirect(reverse('cotisations:index')) return redirect(reverse('cotisations:index'))
return form({ return form({
@ -321,8 +323,9 @@ def edit_article(request, article_instance, articleid):
Réservé au trésorier""" Réservé au trésorier"""
article = ArticleForm(request.POST or None, instance=article_instance) article = ArticleForm(request.POST or None, instance=article_instance)
if article.is_valid(): if article.is_valid():
article.save() if article.changed_data:
messages.success(request, "Type d'article modifié") article.save()
messages.success(request, "Type d'article modifié")
return redirect(reverse('cotisations:index-article')) return redirect(reverse('cotisations:index-article'))
return form({'factureform': article, 'action_name' : 'Editer'}, 'cotisations/facture.html', request) return form({'factureform': article, 'action_name' : 'Editer'}, 'cotisations/facture.html', request)
@ -359,8 +362,9 @@ def edit_paiement(request, paiement_instance, paiementid):
"""Edition d'un moyen de paiement""" """Edition d'un moyen de paiement"""
paiement = PaiementForm(request.POST or None, instance=paiement_instance) paiement = PaiementForm(request.POST or None, instance=paiement_instance)
if paiement.is_valid(): if paiement.is_valid():
paiement.save() if paiement.changed_data:
messages.success(request, "Type de paiement modifié") paiement.save()
messages.success(request, "Type de paiement modifié")
return redirect(reverse('cotisations:index-paiement')) return redirect(reverse('cotisations:index-paiement'))
return form({'factureform': paiement, 'action_name' : 'Editer'}, 'cotisations/facture.html', request) return form({'factureform': paiement, 'action_name' : 'Editer'}, 'cotisations/facture.html', request)
@ -407,8 +411,9 @@ def edit_banque(request, banque_instance, banqueid):
"""Edite le nom d'une banque""" """Edite le nom d'une banque"""
banque = BanqueForm(request.POST or None, instance=banque_instance) banque = BanqueForm(request.POST or None, instance=banque_instance)
if banque.is_valid(): if banque.is_valid():
banque.save() if banque.changed_data:
messages.success(request, "Banque modifiée") banque.save()
messages.success(request, "Banque modifiée")
return redirect(reverse('cotisations:index-banque')) return redirect(reverse('cotisations:index-banque'))
return form({'factureform': banque, 'action_name' : 'Editer'}, 'cotisations/facture.html', request) return form({'factureform': banque, 'action_name' : 'Editer'}, 'cotisations/facture.html', request)

View file

@ -277,9 +277,12 @@ def edit_interface(request, interface_instance, interfaceid):
new_machine = machine_form.save(commit=False) new_machine = machine_form.save(commit=False)
new_interface = interface_form.save(commit=False) new_interface = interface_form.save(commit=False)
new_domain = domain_form.save(commit=False) new_domain = domain_form.save(commit=False)
new_machine.save() if machine_form.changed_data:
new_interface.save() new_machine.save()
new_domain.save() if interface_form.changed_data:
new_interface.save()
if domain_form.changed_data:
new_domain.save()
messages.success(request, "La machine a été modifiée") messages.success(request, "La machine a été modifiée")
return redirect(reverse( return redirect(reverse(
'users:profil', 'users:profil',
@ -375,8 +378,9 @@ def edit_ipv6list(request, ipv6list_instance, ipv6listid):
"""Edition d'une ipv6""" """Edition d'une ipv6"""
ipv6 = Ipv6ListForm(request.POST or None, instance=ipv6list_instance, user=request.user) ipv6 = Ipv6ListForm(request.POST or None, instance=ipv6list_instance, user=request.user)
if ipv6.is_valid(): if ipv6.is_valid():
ipv6.save() if ipv6.changed_data:
messages.success(request, "Ipv6 modifiée") ipv6.save()
messages.success(request, "Ipv6 modifiée")
return redirect(reverse( return redirect(reverse(
'machines:index-ipv6', 'machines:index-ipv6',
kwargs={'interfaceid':str(ipv6list_instance.interface.id)} kwargs={'interfaceid':str(ipv6list_instance.interface.id)}
@ -416,8 +420,9 @@ def edit_iptype(request, iptype_instance, iptypeid):
iptype = EditIpTypeForm(request.POST or None, instance=iptype_instance) iptype = EditIpTypeForm(request.POST or None, instance=iptype_instance)
if iptype.is_valid(): if iptype.is_valid():
iptype.save() if iptype.changed_data:
messages.success(request, "Type d'ip modifié") iptype.save()
messages.success(request, "Type d'ip modifié")
return redirect(reverse('machines:index-iptype')) return redirect(reverse('machines:index-iptype'))
return form({'iptypeform': iptype, 'action_name' : 'Editer'}, 'machines/machine.html', request) return form({'iptypeform': iptype, 'action_name' : 'Editer'}, 'machines/machine.html', request)
@ -451,11 +456,11 @@ def add_machinetype(request):
@login_required @login_required
@can_edit(MachineType) @can_edit(MachineType)
def edit_machinetype(request, machinetype_instance, machinetypeid): def edit_machinetype(request, machinetype_instance, machinetypeid):
machinetype = MachineTypeForm(request.POST or None, instance=machinetype_instance) machinetype = MachineTypeForm(request.POST or None, instance=machinetype_instance)
if machinetype.is_valid(): if machinetype.is_valid():
machinetype.save() if machinetype.changed_data:
messages.success(request, "Type de machine modifié") machinetype.save()
messages.success(request, "Type de machine modifié")
return redirect(reverse('machines:index-machinetype')) return redirect(reverse('machines:index-machinetype'))
return form({'machinetypeform': machinetype, 'action_name' : 'Editer'}, 'machines/machine.html', request) return form({'machinetypeform': machinetype, 'action_name' : 'Editer'}, 'machines/machine.html', request)
@ -477,7 +482,6 @@ def del_machinetype(request, instances):
@login_required @login_required
@can_create(Extension) @can_create(Extension)
def add_extension(request): def add_extension(request):
extension = ExtensionForm(request.POST or None) extension = ExtensionForm(request.POST or None)
if extension.is_valid(): if extension.is_valid():
extension.save() extension.save()
@ -488,11 +492,11 @@ def add_extension(request):
@login_required @login_required
@can_edit(Extension) @can_edit(Extension)
def edit_extension(request, extension_instance, extensionid): def edit_extension(request, extension_instance, extensionid):
extension = ExtensionForm(request.POST or None, instance=extension_instance) extension = ExtensionForm(request.POST or None, instance=extension_instance)
if extension.is_valid(): if extension.is_valid():
extension.save() if extension.changed_data:
messages.success(request, "Extension modifiée") extension.save()
messages.success(request, "Extension modifiée")
return redirect(reverse('machines:index-extension')) return redirect(reverse('machines:index-extension'))
return form({'extensionform': extension, 'action_name' : 'Editer'}, 'machines/machine.html', request) return form({'extensionform': extension, 'action_name' : 'Editer'}, 'machines/machine.html', request)
@ -514,7 +518,6 @@ def del_extension(request, instances):
@login_required @login_required
@can_create(SOA) @can_create(SOA)
def add_soa(request): def add_soa(request):
soa = SOAForm(request.POST or None) soa = SOAForm(request.POST or None)
if soa.is_valid(): if soa.is_valid():
soa.save() soa.save()
@ -525,11 +528,11 @@ def add_soa(request):
@login_required @login_required
@can_edit(SOA) @can_edit(SOA)
def edit_soa(request, soa_instance, soaid): def edit_soa(request, soa_instance, soaid):
soa = SOAForm(request.POST or None, instance=soa_instance) soa = SOAForm(request.POST or None, instance=soa_instance)
if soa.is_valid(): if soa.is_valid():
soa.save() if soa.changed_data:
messages.success(request, "SOA modifié") soa.save()
messages.success(request, "SOA modifié")
return redirect(reverse('machines:index-extension')) return redirect(reverse('machines:index-extension'))
return form({'soaform': soa, 'action_name' : 'Editer'}, 'machines/machine.html', request) return form({'soaform': soa, 'action_name' : 'Editer'}, 'machines/machine.html', request)
@ -551,7 +554,6 @@ def del_soa(request, instances):
@login_required @login_required
@can_create(Mx) @can_create(Mx)
def add_mx(request): def add_mx(request):
mx = MxForm(request.POST or None) mx = MxForm(request.POST or None)
if mx.is_valid(): if mx.is_valid():
mx.save() mx.save()
@ -562,11 +564,11 @@ def add_mx(request):
@login_required @login_required
@can_edit(Mx) @can_edit(Mx)
def edit_mx(request, mx_instance, mxid): def edit_mx(request, mx_instance, mxid):
mx = MxForm(request.POST or None, instance=mx_instance) mx = MxForm(request.POST or None, instance=mx_instance)
if mx.is_valid(): if mx.is_valid():
mx.save() if mx.changed_data:
messages.success(request, "Mx modifié") mx.save()
messages.success(request, "Mx modifié")
return redirect(reverse('machines:index-extension')) return redirect(reverse('machines:index-extension'))
return form({'mxform': mx, 'action_name' : 'Editer'}, 'machines/machine.html', request) return form({'mxform': mx, 'action_name' : 'Editer'}, 'machines/machine.html', request)
@ -588,7 +590,6 @@ def del_mx(request, instances):
@login_required @login_required
@can_create(Ns) @can_create(Ns)
def add_ns(request): def add_ns(request):
ns = NsForm(request.POST or None) ns = NsForm(request.POST or None)
if ns.is_valid(): if ns.is_valid():
ns.save() ns.save()
@ -599,11 +600,11 @@ def add_ns(request):
@login_required @login_required
@can_edit(Ns) @can_edit(Ns)
def edit_ns(request, ns_instance, nsid): def edit_ns(request, ns_instance, nsid):
ns = NsForm(request.POST or None, instance=ns_instance) ns = NsForm(request.POST or None, instance=ns_instance)
if ns.is_valid(): if ns.is_valid():
ns.save() if ns.changed_data:
messages.success(request, "Ns modifié") ns.save()
messages.success(request, "Ns modifié")
return redirect(reverse('machines:index-extension')) return redirect(reverse('machines:index-extension'))
return form({'nsform': ns, 'action_name' : 'Editer'}, 'machines/machine.html', request) return form({'nsform': ns, 'action_name' : 'Editer'}, 'machines/machine.html', request)
@ -625,7 +626,6 @@ def del_ns(request, instances):
@login_required @login_required
@can_create(Txt) @can_create(Txt)
def add_txt(request): def add_txt(request):
txt = TxtForm(request.POST or None) txt = TxtForm(request.POST or None)
if txt.is_valid(): if txt.is_valid():
txt.save() txt.save()
@ -636,11 +636,11 @@ def add_txt(request):
@login_required @login_required
@can_edit(Txt) @can_edit(Txt)
def edit_txt(request, txt_instance, txtid): def edit_txt(request, txt_instance, txtid):
txt = TxtForm(request.POST or None, instance=txt_instance) txt = TxtForm(request.POST or None, instance=txt_instance)
if txt.is_valid(): if txt.is_valid():
txt.save() if txt.changed_data:
messages.success(request, "Txt modifié") txt.save()
messages.success(request, "Txt modifié")
return redirect(reverse('machines:index-extension')) return redirect(reverse('machines:index-extension'))
return form({'txtform': txt, 'action_name' : 'Editer'}, 'machines/machine.html', request) return form({'txtform': txt, 'action_name' : 'Editer'}, 'machines/machine.html', request)
@ -662,7 +662,6 @@ def del_txt(request, instances):
@login_required @login_required
@can_create(Srv) @can_create(Srv)
def add_srv(request): def add_srv(request):
srv = SrvForm(request.POST or None) srv = SrvForm(request.POST or None)
if srv.is_valid(): if srv.is_valid():
srv.save() srv.save()
@ -673,11 +672,11 @@ def add_srv(request):
@login_required @login_required
@can_edit(Srv) @can_edit(Srv)
def edit_srv(request, srv_instance, srvid): def edit_srv(request, srv_instance, srvid):
srv = SrvForm(request.POST or None, instance=srv_instance) srv = SrvForm(request.POST or None, instance=srv_instance)
if srv.is_valid(): if srv.is_valid():
srv.save() if srv.changed_data:
messages.success(request, "Srv modifié") srv.save()
messages.success(request, "Srv modifié")
return redirect(reverse('machines:index-extension')) return redirect(reverse('machines:index-extension'))
return form({'srvform': srv, 'action_name' : 'Editer'}, 'machines/machine.html', request) return form({'srvform': srv, 'action_name' : 'Editer'}, 'machines/machine.html', request)
@ -700,7 +699,6 @@ def del_srv(request, instances):
@can_create(Domain) @can_create(Domain)
@can_edit(Interface) @can_edit(Interface)
def add_alias(request, interface, interfaceid): def add_alias(request, interface, interfaceid):
alias = AliasForm(request.POST or None, user=request.user) alias = AliasForm(request.POST or None, user=request.user)
if alias.is_valid(): if alias.is_valid():
alias = alias.save(commit=False) alias = alias.save(commit=False)
@ -716,11 +714,11 @@ def add_alias(request, interface, interfaceid):
@login_required @login_required
@can_edit(Domain) @can_edit(Domain)
def edit_alias(request, domain_instance, domainid): def edit_alias(request, domain_instance, domainid):
alias = AliasForm(request.POST or None, instance=domain_instance, user=request.user) alias = AliasForm(request.POST or None, instance=domain_instance, user=request.user)
if alias.is_valid(): if alias.is_valid():
domain_instance = alias.save() if alias.changed_data:
messages.success(request, "Alias modifié") domain_instance = alias.save()
messages.success(request, "Alias modifié")
return redirect(reverse( return redirect(reverse(
'machines:index-alias', 'machines:index-alias',
kwargs={'interfaceid':str(domain_instance.cname.interface_parent.id)} kwargs={'interfaceid':str(domain_instance.cname.interface_parent.id)}
@ -749,7 +747,6 @@ def del_alias(request, interface, interfaceid):
@login_required @login_required
@can_create(Service) @can_create(Service)
def add_service(request): def add_service(request):
service = ServiceForm(request.POST or None) service = ServiceForm(request.POST or None)
if service.is_valid(): if service.is_valid():
service.save() service.save()
@ -760,11 +757,11 @@ def add_service(request):
@login_required @login_required
@can_edit(Service) @can_edit(Service)
def edit_service(request, service_instance, serviceid): def edit_service(request, service_instance, serviceid):
service = ServiceForm(request.POST or None, instance=service_instance) service = ServiceForm(request.POST or None, instance=service_instance)
if service.is_valid(): if service.is_valid():
service.save() if service.changed_data:
messages.success(request, "Service modifié") service.save()
messages.success(request, "Service modifié")
return redirect(reverse('machines:index-service')) return redirect(reverse('machines:index-service'))
return form({'serviceform': service, 'action_name' : 'Editer'}, 'machines/machine.html', request) return form({'serviceform': service, 'action_name' : 'Editer'}, 'machines/machine.html', request)
@ -786,7 +783,6 @@ def del_service(request, instances):
@login_required @login_required
@can_create(Vlan) @can_create(Vlan)
def add_vlan(request): def add_vlan(request):
vlan = VlanForm(request.POST or None) vlan = VlanForm(request.POST or None)
if vlan.is_valid(): if vlan.is_valid():
vlan.save() vlan.save()
@ -797,11 +793,11 @@ def add_vlan(request):
@login_required @login_required
@can_edit(Vlan) @can_edit(Vlan)
def edit_vlan(request, vlan_instance, vlanid): def edit_vlan(request, vlan_instance, vlanid):
vlan = VlanForm(request.POST or None, instance=vlan_instance) vlan = VlanForm(request.POST or None, instance=vlan_instance)
if vlan.is_valid(): if vlan.is_valid():
vlan.save() if vlan.changed_data:
messages.success(request, "Vlan modifié") vlan.save()
messages.success(request, "Vlan modifié")
return redirect(reverse('machines:index-vlan')) return redirect(reverse('machines:index-vlan'))
return form({'vlanform': vlan, 'action_name' : 'Editer'}, 'machines/machine.html', request) return form({'vlanform': vlan, 'action_name' : 'Editer'}, 'machines/machine.html', request)
@ -823,7 +819,6 @@ def del_vlan(request, instances):
@login_required @login_required
@can_create(Nas) @can_create(Nas)
def add_nas(request): def add_nas(request):
nas = NasForm(request.POST or None) nas = NasForm(request.POST or None)
if nas.is_valid(): if nas.is_valid():
nas.save() nas.save()
@ -834,11 +829,11 @@ def add_nas(request):
@login_required @login_required
@can_edit(Nas) @can_edit(Nas)
def edit_nas(request, nas_instance, nasid): def edit_nas(request, nas_instance, nasid):
nas = NasForm(request.POST or None, instance=nas_instance) nas = NasForm(request.POST or None, instance=nas_instance)
if nas.is_valid(): if nas.is_valid():
nas.save() if nas.changed_data:
messages.success(request, "Nas modifié") nas.save()
messages.success(request, "Nas modifié")
return redirect(reverse('machines:index-nas')) return redirect(reverse('machines:index-nas'))
return form({'nasform': nas, 'action_name' : 'Editer'}, 'machines/machine.html', request) return form({'nasform': nas, 'action_name' : 'Editer'}, 'machines/machine.html', request)
@ -951,7 +946,6 @@ def index_portlist(request):
@login_required @login_required
@can_edit(OuverturePortList) @can_edit(OuverturePortList)
def edit_portlist(request, ouvertureportlist_instance, ouvertureportlistid): def edit_portlist(request, ouvertureportlist_instance, ouvertureportlistid):
port_list = EditOuverturePortListForm(request.POST or None, instance=ouvertureportlist_instance) port_list = EditOuverturePortListForm(request.POST or None, instance=ouvertureportlist_instance)
port_formset = modelformset_factory( port_formset = modelformset_factory(
OuverturePort, OuverturePort,
@ -962,7 +956,10 @@ def edit_portlist(request, ouvertureportlist_instance, ouvertureportlistid):
validate_min=True, validate_min=True,
)(request.POST or None, queryset=ouvertureportlist_instance.ouvertureport_set.all()) )(request.POST or None, queryset=ouvertureportlist_instance.ouvertureport_set.all())
if port_list.is_valid() and port_formset.is_valid(): if port_list.is_valid() and port_formset.is_valid():
pl = port_list.save() if port_list.changed_data:
pl = port_list.save()
else:
pl = ouvertureportlist_instance
instances = port_formset.save(commit=False) instances = port_formset.save(commit=False)
for to_delete in port_formset.deleted_objects: for to_delete in port_formset.deleted_objects:
to_delete.delete() to_delete.delete()
@ -983,7 +980,6 @@ def del_portlist(request, port_list_instance, ouvertureportlistid):
@login_required @login_required
@can_create(OuverturePortList) @can_create(OuverturePortList)
def add_portlist(request): def add_portlist(request):
port_list = EditOuverturePortListForm(request.POST or None) port_list = EditOuverturePortListForm(request.POST or None)
port_formset = modelformset_factory( port_formset = modelformset_factory(
OuverturePort, OuverturePort,
@ -1019,8 +1015,9 @@ def configure_ports(request, interface_instance, interfaceid):
messages.error(request, "Attention, l'ipv4 n'est pas publique, l'ouverture n'aura pas d'effet en v4") messages.error(request, "Attention, l'ipv4 n'est pas publique, l'ouverture n'aura pas d'effet en v4")
interface = EditOuverturePortConfigForm(request.POST or None, instance=interface_instance) interface = EditOuverturePortConfigForm(request.POST or None, instance=interface_instance)
if interface.is_valid(): if interface.is_valid():
interface.save() if interface.changed_data:
messages.success(request, "Configuration des ports mise à jour.") interface.save()
messages.success(request, "Configuration des ports mise à jour.")
return redirect(reverse('machines:index')) return redirect(reverse('machines:index'))
return form({'interfaceform' : interface, 'action_name' : 'Editer la configuration'}, 'machines/machine.html', request) return form({'interfaceform' : interface, 'action_name' : 'Editer la configuration'}, 'machines/machine.html', request)

View file

@ -102,6 +102,9 @@ class AccessPoint(AclMixin, Machine):
("view_accesspoint", "Peut voir une borne"), ("view_accesspoint", "Peut voir une borne"),
) )
def __str__(self):
return str(self.interface_set.first())
class Switch(AclMixin, Machine): class Switch(AclMixin, Machine):
""" Definition d'un switch. Contient un nombre de ports (number), """ Definition d'un switch. Contient un nombre de ports (number),

View file

@ -152,8 +152,9 @@ def edit_club_admin_members(request, club_instance, clubid):
membres d'un club""" membres d'un club"""
club = ClubAdminandMembersForm(request.POST or None, instance=club_instance) club = ClubAdminandMembersForm(request.POST or None, instance=club_instance)
if club.is_valid(): if club.is_valid():
club.save() if club.changed_data:
messages.success(request, "Le club a bien été modifié") club.save()
messages.success(request, "Le club a bien été modifié")
return redirect(reverse( return redirect(reverse(
'users:profil', 'users:profil',
kwargs={'userid':str(club_instance.id)} kwargs={'userid':str(club_instance.id)}
@ -180,8 +181,9 @@ def edit_info(request, user, userid):
user=request.user user=request.user
) )
if user.is_valid(): if user.is_valid():
user.save() if user.changed_data:
messages.success(request, "L'user a bien été modifié") user.save()
messages.success(request, "L'user a bien été modifié")
return redirect(reverse( return redirect(reverse(
'users:profil', 'users:profil',
kwargs={'userid':str(userid)} kwargs={'userid':str(userid)}
@ -202,8 +204,9 @@ def state(request, user, userid):
user.unarchive() user.unarchive()
elif state.cleaned_data['state'] == User.STATE_DISABLED: elif state.cleaned_data['state'] == User.STATE_DISABLED:
user.state = User.STATE_DISABLED user.state = User.STATE_DISABLED
user.save() if user.changed_data:
messages.success(request, "Etat changé avec succès") user.save()
messages.success(request, "Etat changé avec succès")
return redirect(reverse( return redirect(reverse(
'users:profil', 'users:profil',
kwargs={'userid':str(userid)} kwargs={'userid':str(userid)}
@ -216,8 +219,9 @@ def state(request, user, userid):
def groups(request, user, userid): def groups(request, user, userid):
group = GroupForm(request.POST or None, instance=user) group = GroupForm(request.POST or None, instance=user)
if group.is_valid(): if group.is_valid():
group.save() if group.changed_data:
messages.success(request, "Groupes changés avec succès") group.save()
messages.success(request, "Groupes changés avec succès")
return redirect(reverse( return redirect(reverse(
'users:profil', 'users:profil',
kwargs={'userid':str(userid)} kwargs={'userid':str(userid)}
@ -233,8 +237,9 @@ def password(request, user, userid):
pour tous si droit bureau """ pour tous si droit bureau """
u_form = PassForm(request.POST or None, instance=user, user=request.user) u_form = PassForm(request.POST or None, instance=user, user=request.user)
if u_form.is_valid(): if u_form.is_valid():
u_form.save() if u_form.changed_data:
messages.success(request, "Le mot de passe a changé") u_form.save()
messages.success(request, "Le mot de passe a changé")
return redirect(reverse( return redirect(reverse(
'users:profil', 'users:profil',
kwargs={'userid':str(user.id)} kwargs={'userid':str(user.id)}
@ -277,7 +282,8 @@ def edit_serviceuser(request, user, userid):
user_object = user.save(commit=False) user_object = user.save(commit=False)
if user.cleaned_data['password']: if user.cleaned_data['password']:
user_object.set_password(user.cleaned_data['password']) user_object.set_password(user.cleaned_data['password'])
user_object.save() if user.changed_data:
user_object.save()
messages.success(request, "L'user a bien été modifié") messages.success(request, "L'user a bien été modifié")
return redirect(reverse('users:index-serviceusers')) return redirect(reverse('users:index-serviceusers'))
return form({'userform': user, 'action_name':'Editer un serviceuser'}, 'users/user.html', request) return form({'userform': user, 'action_name':'Editer un serviceuser'}, 'users/user.html', request)
@ -329,8 +335,9 @@ def edit_ban(request, ban_instance, banid):
Syntaxe : JJ/MM/AAAA , heure optionnelle, prend effet immédiatement""" Syntaxe : JJ/MM/AAAA , heure optionnelle, prend effet immédiatement"""
ban = BanForm(request.POST or None, instance=ban_instance) ban = BanForm(request.POST or None, instance=ban_instance)
if ban.is_valid(): if ban.is_valid():
ban.save() if ban.changed_data:
messages.success(request, "Bannissement modifié") ban.save()
messages.success(request, "Bannissement modifié")
return redirect(reverse('users:index')) return redirect(reverse('users:index'))
return form({'userform': ban, 'action_name': 'Editer un ban'}, 'users/user.html', request) return form({'userform': ban, 'action_name': 'Editer un ban'}, 'users/user.html', request)
@ -375,8 +382,9 @@ def edit_whitelist(request, whitelist_instance, whitelistid):
instance=whitelist_instance instance=whitelist_instance
) )
if whitelist.is_valid(): if whitelist.is_valid():
whitelist.save() if whitelist.changed_data:
messages.success(request, "Whitelist modifiée") whitelist.save()
messages.success(request, "Whitelist modifiée")
return redirect(reverse('users:index')) return redirect(reverse('users:index'))
return form({'userform': whitelist, 'action_name': 'Editer une whitelist'}, 'users/user.html', request) return form({'userform': whitelist, 'action_name': 'Editer une whitelist'}, 'users/user.html', request)
@ -401,8 +409,9 @@ def edit_school(request, school_instance, schoolid):
la base de donnée, need cableur""" la base de donnée, need cableur"""
school = SchoolForm(request.POST or None, instance=school_instance) school = SchoolForm(request.POST or None, instance=school_instance)
if school.is_valid(): if school.is_valid():
school.save() if school.changed_data:
messages.success(request, "Établissement modifié") school.save()
messages.success(request, "Établissement modifié")
return redirect(reverse('users:index-school')) return redirect(reverse('users:index-school'))
return form({'userform': school, 'action_name':'Editer'}, 'users/user.html', request) return form({'userform': school, 'action_name':'Editer'}, 'users/user.html', request)
@ -448,8 +457,9 @@ def edit_shell(request, shell_instance, listshellid):
""" Editer un shell à partir du listshellid""" """ Editer un shell à partir du listshellid"""
shell = ShellForm(request.POST or None, instance=shell_instance) shell = ShellForm(request.POST or None, instance=shell_instance)
if shell.is_valid(): if shell.is_valid():
shell.save() if shell.changed_data:
messages.success(request, "Le shell a été modifié") shell.save()
messages.success(request, "Le shell a été modifié")
return redirect(reverse('users:index-shell')) return redirect(reverse('users:index-shell'))
return form({'userform': shell, 'action_name':'Editer'}, 'users/user.html', request) return form({'userform': shell, 'action_name':'Editer'}, 'users/user.html', request)
@ -492,8 +502,9 @@ def edit_listright(request, listright_instance, listrightid):
instance=listright_instance instance=listright_instance
) )
if listright.is_valid(): if listright.is_valid():
listright.save() if listright.changed_data:
messages.success(request, "Droit modifié") listright.save()
messages.success(request, "Droit modifié")
return redirect(reverse('users:index-listright')) return redirect(reverse('users:index-listright'))
return form({'userform': listright, 'action_name': 'Editer'}, 'users/user.html', request) return form({'userform': listright, 'action_name': 'Editer'}, 'users/user.html', request)