8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-27 07:02:26 +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)
if facture_form.is_valid() and vente_form.is_valid():
facture_form.save()
vente_form.save()
if facture_form.changed_data:
facture_form.save()
if vente_form.changed_data:
vente_form.save()
messages.success(request, "La facture a bien été modifiée")
return redirect(reverse('cotisations:index'))
return form({
@ -321,8 +323,9 @@ def edit_article(request, article_instance, articleid):
Réservé au trésorier"""
article = ArticleForm(request.POST or None, instance=article_instance)
if article.is_valid():
article.save()
messages.success(request, "Type d'article modifié")
if article.changed_data:
article.save()
messages.success(request, "Type d'article modifié")
return redirect(reverse('cotisations:index-article'))
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"""
paiement = PaiementForm(request.POST or None, instance=paiement_instance)
if paiement.is_valid():
paiement.save()
messages.success(request, "Type de paiement modifié")
if paiement.changed_data:
paiement.save()
messages.success(request, "Type de paiement modifié")
return redirect(reverse('cotisations:index-paiement'))
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"""
banque = BanqueForm(request.POST or None, instance=banque_instance)
if banque.is_valid():
banque.save()
messages.success(request, "Banque modifiée")
if banque.changed_data:
banque.save()
messages.success(request, "Banque modifiée")
return redirect(reverse('cotisations:index-banque'))
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_interface = interface_form.save(commit=False)
new_domain = domain_form.save(commit=False)
new_machine.save()
new_interface.save()
new_domain.save()
if machine_form.changed_data:
new_machine.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")
return redirect(reverse(
'users:profil',
@ -375,8 +378,9 @@ def edit_ipv6list(request, ipv6list_instance, ipv6listid):
"""Edition d'une ipv6"""
ipv6 = Ipv6ListForm(request.POST or None, instance=ipv6list_instance, user=request.user)
if ipv6.is_valid():
ipv6.save()
messages.success(request, "Ipv6 modifiée")
if ipv6.changed_data:
ipv6.save()
messages.success(request, "Ipv6 modifiée")
return redirect(reverse(
'machines:index-ipv6',
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)
if iptype.is_valid():
iptype.save()
messages.success(request, "Type d'ip modifié")
if iptype.changed_data:
iptype.save()
messages.success(request, "Type d'ip modifié")
return redirect(reverse('machines:index-iptype'))
return form({'iptypeform': iptype, 'action_name' : 'Editer'}, 'machines/machine.html', request)
@ -451,11 +456,11 @@ def add_machinetype(request):
@login_required
@can_edit(MachineType)
def edit_machinetype(request, machinetype_instance, machinetypeid):
machinetype = MachineTypeForm(request.POST or None, instance=machinetype_instance)
if machinetype.is_valid():
machinetype.save()
messages.success(request, "Type de machine modifié")
if machinetype.changed_data:
machinetype.save()
messages.success(request, "Type de machine modifié")
return redirect(reverse('machines:index-machinetype'))
return form({'machinetypeform': machinetype, 'action_name' : 'Editer'}, 'machines/machine.html', request)
@ -477,7 +482,6 @@ def del_machinetype(request, instances):
@login_required
@can_create(Extension)
def add_extension(request):
extension = ExtensionForm(request.POST or None)
if extension.is_valid():
extension.save()
@ -488,11 +492,11 @@ def add_extension(request):
@login_required
@can_edit(Extension)
def edit_extension(request, extension_instance, extensionid):
extension = ExtensionForm(request.POST or None, instance=extension_instance)
if extension.is_valid():
extension.save()
messages.success(request, "Extension modifiée")
if extension.changed_data:
extension.save()
messages.success(request, "Extension modifiée")
return redirect(reverse('machines:index-extension'))
return form({'extensionform': extension, 'action_name' : 'Editer'}, 'machines/machine.html', request)
@ -514,7 +518,6 @@ def del_extension(request, instances):
@login_required
@can_create(SOA)
def add_soa(request):
soa = SOAForm(request.POST or None)
if soa.is_valid():
soa.save()
@ -525,11 +528,11 @@ def add_soa(request):
@login_required
@can_edit(SOA)
def edit_soa(request, soa_instance, soaid):
soa = SOAForm(request.POST or None, instance=soa_instance)
if soa.is_valid():
soa.save()
messages.success(request, "SOA modifié")
if soa.changed_data:
soa.save()
messages.success(request, "SOA modifié")
return redirect(reverse('machines:index-extension'))
return form({'soaform': soa, 'action_name' : 'Editer'}, 'machines/machine.html', request)
@ -551,7 +554,6 @@ def del_soa(request, instances):
@login_required
@can_create(Mx)
def add_mx(request):
mx = MxForm(request.POST or None)
if mx.is_valid():
mx.save()
@ -562,11 +564,11 @@ def add_mx(request):
@login_required
@can_edit(Mx)
def edit_mx(request, mx_instance, mxid):
mx = MxForm(request.POST or None, instance=mx_instance)
if mx.is_valid():
mx.save()
messages.success(request, "Mx modifié")
if mx.changed_data:
mx.save()
messages.success(request, "Mx modifié")
return redirect(reverse('machines:index-extension'))
return form({'mxform': mx, 'action_name' : 'Editer'}, 'machines/machine.html', request)
@ -588,7 +590,6 @@ def del_mx(request, instances):
@login_required
@can_create(Ns)
def add_ns(request):
ns = NsForm(request.POST or None)
if ns.is_valid():
ns.save()
@ -599,11 +600,11 @@ def add_ns(request):
@login_required
@can_edit(Ns)
def edit_ns(request, ns_instance, nsid):
ns = NsForm(request.POST or None, instance=ns_instance)
if ns.is_valid():
ns.save()
messages.success(request, "Ns modifié")
if ns.changed_data:
ns.save()
messages.success(request, "Ns modifié")
return redirect(reverse('machines:index-extension'))
return form({'nsform': ns, 'action_name' : 'Editer'}, 'machines/machine.html', request)
@ -625,7 +626,6 @@ def del_ns(request, instances):
@login_required
@can_create(Txt)
def add_txt(request):
txt = TxtForm(request.POST or None)
if txt.is_valid():
txt.save()
@ -636,11 +636,11 @@ def add_txt(request):
@login_required
@can_edit(Txt)
def edit_txt(request, txt_instance, txtid):
txt = TxtForm(request.POST or None, instance=txt_instance)
if txt.is_valid():
txt.save()
messages.success(request, "Txt modifié")
if txt.changed_data:
txt.save()
messages.success(request, "Txt modifié")
return redirect(reverse('machines:index-extension'))
return form({'txtform': txt, 'action_name' : 'Editer'}, 'machines/machine.html', request)
@ -662,7 +662,6 @@ def del_txt(request, instances):
@login_required
@can_create(Srv)
def add_srv(request):
srv = SrvForm(request.POST or None)
if srv.is_valid():
srv.save()
@ -673,11 +672,11 @@ def add_srv(request):
@login_required
@can_edit(Srv)
def edit_srv(request, srv_instance, srvid):
srv = SrvForm(request.POST or None, instance=srv_instance)
if srv.is_valid():
srv.save()
messages.success(request, "Srv modifié")
if srv.changed_data:
srv.save()
messages.success(request, "Srv modifié")
return redirect(reverse('machines:index-extension'))
return form({'srvform': srv, 'action_name' : 'Editer'}, 'machines/machine.html', request)
@ -700,7 +699,6 @@ def del_srv(request, instances):
@can_create(Domain)
@can_edit(Interface)
def add_alias(request, interface, interfaceid):
alias = AliasForm(request.POST or None, user=request.user)
if alias.is_valid():
alias = alias.save(commit=False)
@ -716,11 +714,11 @@ def add_alias(request, interface, interfaceid):
@login_required
@can_edit(Domain)
def edit_alias(request, domain_instance, domainid):
alias = AliasForm(request.POST or None, instance=domain_instance, user=request.user)
if alias.is_valid():
domain_instance = alias.save()
messages.success(request, "Alias modifié")
if alias.changed_data:
domain_instance = alias.save()
messages.success(request, "Alias modifié")
return redirect(reverse(
'machines:index-alias',
kwargs={'interfaceid':str(domain_instance.cname.interface_parent.id)}
@ -749,7 +747,6 @@ def del_alias(request, interface, interfaceid):
@login_required
@can_create(Service)
def add_service(request):
service = ServiceForm(request.POST or None)
if service.is_valid():
service.save()
@ -760,11 +757,11 @@ def add_service(request):
@login_required
@can_edit(Service)
def edit_service(request, service_instance, serviceid):
service = ServiceForm(request.POST or None, instance=service_instance)
if service.is_valid():
service.save()
messages.success(request, "Service modifié")
if service.changed_data:
service.save()
messages.success(request, "Service modifié")
return redirect(reverse('machines:index-service'))
return form({'serviceform': service, 'action_name' : 'Editer'}, 'machines/machine.html', request)
@ -786,7 +783,6 @@ def del_service(request, instances):
@login_required
@can_create(Vlan)
def add_vlan(request):
vlan = VlanForm(request.POST or None)
if vlan.is_valid():
vlan.save()
@ -797,11 +793,11 @@ def add_vlan(request):
@login_required
@can_edit(Vlan)
def edit_vlan(request, vlan_instance, vlanid):
vlan = VlanForm(request.POST or None, instance=vlan_instance)
if vlan.is_valid():
vlan.save()
messages.success(request, "Vlan modifié")
if vlan.changed_data:
vlan.save()
messages.success(request, "Vlan modifié")
return redirect(reverse('machines:index-vlan'))
return form({'vlanform': vlan, 'action_name' : 'Editer'}, 'machines/machine.html', request)
@ -823,7 +819,6 @@ def del_vlan(request, instances):
@login_required
@can_create(Nas)
def add_nas(request):
nas = NasForm(request.POST or None)
if nas.is_valid():
nas.save()
@ -834,11 +829,11 @@ def add_nas(request):
@login_required
@can_edit(Nas)
def edit_nas(request, nas_instance, nasid):
nas = NasForm(request.POST or None, instance=nas_instance)
if nas.is_valid():
nas.save()
messages.success(request, "Nas modifié")
if nas.changed_data:
nas.save()
messages.success(request, "Nas modifié")
return redirect(reverse('machines:index-nas'))
return form({'nasform': nas, 'action_name' : 'Editer'}, 'machines/machine.html', request)
@ -951,7 +946,6 @@ def index_portlist(request):
@login_required
@can_edit(OuverturePortList)
def edit_portlist(request, ouvertureportlist_instance, ouvertureportlistid):
port_list = EditOuverturePortListForm(request.POST or None, instance=ouvertureportlist_instance)
port_formset = modelformset_factory(
OuverturePort,
@ -962,7 +956,10 @@ def edit_portlist(request, ouvertureportlist_instance, ouvertureportlistid):
validate_min=True,
)(request.POST or None, queryset=ouvertureportlist_instance.ouvertureport_set.all())
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)
for to_delete in port_formset.deleted_objects:
to_delete.delete()
@ -983,7 +980,6 @@ def del_portlist(request, port_list_instance, ouvertureportlistid):
@login_required
@can_create(OuverturePortList)
def add_portlist(request):
port_list = EditOuverturePortListForm(request.POST or None)
port_formset = modelformset_factory(
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")
interface = EditOuverturePortConfigForm(request.POST or None, instance=interface_instance)
if interface.is_valid():
interface.save()
messages.success(request, "Configuration des ports mise à jour.")
if interface.changed_data:
interface.save()
messages.success(request, "Configuration des ports mise à jour.")
return redirect(reverse('machines:index'))
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"),
)
def __str__(self):
return str(self.interface_set.first())
class Switch(AclMixin, Machine):
""" 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"""
club = ClubAdminandMembersForm(request.POST or None, instance=club_instance)
if club.is_valid():
club.save()
messages.success(request, "Le club a bien été modifié")
if club.changed_data:
club.save()
messages.success(request, "Le club a bien été modifié")
return redirect(reverse(
'users:profil',
kwargs={'userid':str(club_instance.id)}
@ -180,8 +181,9 @@ def edit_info(request, user, userid):
user=request.user
)
if user.is_valid():
user.save()
messages.success(request, "L'user a bien été modifié")
if user.changed_data:
user.save()
messages.success(request, "L'user a bien été modifié")
return redirect(reverse(
'users:profil',
kwargs={'userid':str(userid)}
@ -202,8 +204,9 @@ def state(request, user, userid):
user.unarchive()
elif state.cleaned_data['state'] == User.STATE_DISABLED:
user.state = User.STATE_DISABLED
user.save()
messages.success(request, "Etat changé avec succès")
if user.changed_data:
user.save()
messages.success(request, "Etat changé avec succès")
return redirect(reverse(
'users:profil',
kwargs={'userid':str(userid)}
@ -216,8 +219,9 @@ def state(request, user, userid):
def groups(request, user, userid):
group = GroupForm(request.POST or None, instance=user)
if group.is_valid():
group.save()
messages.success(request, "Groupes changés avec succès")
if group.changed_data:
group.save()
messages.success(request, "Groupes changés avec succès")
return redirect(reverse(
'users:profil',
kwargs={'userid':str(userid)}
@ -233,8 +237,9 @@ def password(request, user, userid):
pour tous si droit bureau """
u_form = PassForm(request.POST or None, instance=user, user=request.user)
if u_form.is_valid():
u_form.save()
messages.success(request, "Le mot de passe a changé")
if u_form.changed_data:
u_form.save()
messages.success(request, "Le mot de passe a changé")
return redirect(reverse(
'users:profil',
kwargs={'userid':str(user.id)}
@ -277,7 +282,8 @@ def edit_serviceuser(request, user, userid):
user_object = user.save(commit=False)
if 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é")
return redirect(reverse('users:index-serviceusers'))
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"""
ban = BanForm(request.POST or None, instance=ban_instance)
if ban.is_valid():
ban.save()
messages.success(request, "Bannissement modifié")
if ban.changed_data:
ban.save()
messages.success(request, "Bannissement modifié")
return redirect(reverse('users:index'))
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
)
if whitelist.is_valid():
whitelist.save()
messages.success(request, "Whitelist modifiée")
if whitelist.changed_data:
whitelist.save()
messages.success(request, "Whitelist modifiée")
return redirect(reverse('users:index'))
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"""
school = SchoolForm(request.POST or None, instance=school_instance)
if school.is_valid():
school.save()
messages.success(request, "Établissement modifié")
if school.changed_data:
school.save()
messages.success(request, "Établissement modifié")
return redirect(reverse('users:index-school'))
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"""
shell = ShellForm(request.POST or None, instance=shell_instance)
if shell.is_valid():
shell.save()
messages.success(request, "Le shell a été modifié")
if shell.changed_data:
shell.save()
messages.success(request, "Le shell a été modifié")
return redirect(reverse('users:index-shell'))
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
)
if listright.is_valid():
listright.save()
messages.success(request, "Droit modifié")
if listright.changed_data:
listright.save()
messages.success(request, "Droit modifié")
return redirect(reverse('users:index-listright'))
return form({'userform': listright, 'action_name': 'Editer'}, 'users/user.html', request)