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:
parent
a553789bad
commit
543037b667
4 changed files with 100 additions and 84 deletions
|
@ -249,7 +249,9 @@ 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():
|
||||
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'))
|
||||
|
@ -321,6 +323,7 @@ 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():
|
||||
if article.changed_data:
|
||||
article.save()
|
||||
messages.success(request, "Type d'article modifié")
|
||||
return redirect(reverse('cotisations:index-article'))
|
||||
|
@ -359,6 +362,7 @@ 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():
|
||||
if paiement.changed_data:
|
||||
paiement.save()
|
||||
messages.success(request, "Type de paiement modifié")
|
||||
return redirect(reverse('cotisations:index-paiement'))
|
||||
|
@ -407,6 +411,7 @@ 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():
|
||||
if banque.changed_data:
|
||||
banque.save()
|
||||
messages.success(request, "Banque modifiée")
|
||||
return redirect(reverse('cotisations:index-banque'))
|
||||
|
|
|
@ -277,8 +277,11 @@ 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)
|
||||
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(
|
||||
|
@ -375,6 +378,7 @@ 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():
|
||||
if ipv6.changed_data:
|
||||
ipv6.save()
|
||||
messages.success(request, "Ipv6 modifiée")
|
||||
return redirect(reverse(
|
||||
|
@ -416,6 +420,7 @@ def edit_iptype(request, iptype_instance, iptypeid):
|
|||
|
||||
iptype = EditIpTypeForm(request.POST or None, instance=iptype_instance)
|
||||
if iptype.is_valid():
|
||||
if iptype.changed_data:
|
||||
iptype.save()
|
||||
messages.success(request, "Type d'ip modifié")
|
||||
return redirect(reverse('machines:index-iptype'))
|
||||
|
@ -451,9 +456,9 @@ 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():
|
||||
if machinetype.changed_data:
|
||||
machinetype.save()
|
||||
messages.success(request, "Type de machine modifié")
|
||||
return redirect(reverse('machines:index-machinetype'))
|
||||
|
@ -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,9 +492,9 @@ 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():
|
||||
if extension.changed_data:
|
||||
extension.save()
|
||||
messages.success(request, "Extension modifiée")
|
||||
return redirect(reverse('machines:index-extension'))
|
||||
|
@ -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,9 +528,9 @@ 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():
|
||||
if soa.changed_data:
|
||||
soa.save()
|
||||
messages.success(request, "SOA modifié")
|
||||
return redirect(reverse('machines:index-extension'))
|
||||
|
@ -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,9 +564,9 @@ 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():
|
||||
if mx.changed_data:
|
||||
mx.save()
|
||||
messages.success(request, "Mx modifié")
|
||||
return redirect(reverse('machines:index-extension'))
|
||||
|
@ -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,9 +600,9 @@ 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():
|
||||
if ns.changed_data:
|
||||
ns.save()
|
||||
messages.success(request, "Ns modifié")
|
||||
return redirect(reverse('machines:index-extension'))
|
||||
|
@ -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,9 +636,9 @@ 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():
|
||||
if txt.changed_data:
|
||||
txt.save()
|
||||
messages.success(request, "Txt modifié")
|
||||
return redirect(reverse('machines:index-extension'))
|
||||
|
@ -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,9 +672,9 @@ 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():
|
||||
if srv.changed_data:
|
||||
srv.save()
|
||||
messages.success(request, "Srv modifié")
|
||||
return redirect(reverse('machines:index-extension'))
|
||||
|
@ -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,9 +714,9 @@ 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():
|
||||
if alias.changed_data:
|
||||
domain_instance = alias.save()
|
||||
messages.success(request, "Alias modifié")
|
||||
return redirect(reverse(
|
||||
|
@ -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,9 +757,9 @@ 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():
|
||||
if service.changed_data:
|
||||
service.save()
|
||||
messages.success(request, "Service modifié")
|
||||
return redirect(reverse('machines:index-service'))
|
||||
|
@ -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,9 +793,9 @@ 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():
|
||||
if vlan.changed_data:
|
||||
vlan.save()
|
||||
messages.success(request, "Vlan modifié")
|
||||
return redirect(reverse('machines:index-vlan'))
|
||||
|
@ -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,9 +829,9 @@ 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():
|
||||
if nas.changed_data:
|
||||
nas.save()
|
||||
messages.success(request, "Nas modifié")
|
||||
return redirect(reverse('machines:index-nas'))
|
||||
|
@ -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():
|
||||
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,6 +1015,7 @@ 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():
|
||||
if interface.changed_data:
|
||||
interface.save()
|
||||
messages.success(request, "Configuration des ports mise à jour.")
|
||||
return redirect(reverse('machines:index'))
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -152,6 +152,7 @@ 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():
|
||||
if club.changed_data:
|
||||
club.save()
|
||||
messages.success(request, "Le club a bien été modifié")
|
||||
return redirect(reverse(
|
||||
|
@ -180,6 +181,7 @@ def edit_info(request, user, userid):
|
|||
user=request.user
|
||||
)
|
||||
if user.is_valid():
|
||||
if user.changed_data:
|
||||
user.save()
|
||||
messages.success(request, "L'user a bien été modifié")
|
||||
return redirect(reverse(
|
||||
|
@ -202,6 +204,7 @@ def state(request, user, userid):
|
|||
user.unarchive()
|
||||
elif state.cleaned_data['state'] == User.STATE_DISABLED:
|
||||
user.state = User.STATE_DISABLED
|
||||
if user.changed_data:
|
||||
user.save()
|
||||
messages.success(request, "Etat changé avec succès")
|
||||
return redirect(reverse(
|
||||
|
@ -216,6 +219,7 @@ def state(request, user, userid):
|
|||
def groups(request, user, userid):
|
||||
group = GroupForm(request.POST or None, instance=user)
|
||||
if group.is_valid():
|
||||
if group.changed_data:
|
||||
group.save()
|
||||
messages.success(request, "Groupes changés avec succès")
|
||||
return redirect(reverse(
|
||||
|
@ -233,6 +237,7 @@ 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():
|
||||
if u_form.changed_data:
|
||||
u_form.save()
|
||||
messages.success(request, "Le mot de passe a changé")
|
||||
return redirect(reverse(
|
||||
|
@ -277,6 +282,7 @@ 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'])
|
||||
if user.changed_data:
|
||||
user_object.save()
|
||||
messages.success(request, "L'user a bien été modifié")
|
||||
return redirect(reverse('users:index-serviceusers'))
|
||||
|
@ -329,6 +335,7 @@ 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():
|
||||
if ban.changed_data:
|
||||
ban.save()
|
||||
messages.success(request, "Bannissement modifié")
|
||||
return redirect(reverse('users:index'))
|
||||
|
@ -375,6 +382,7 @@ def edit_whitelist(request, whitelist_instance, whitelistid):
|
|||
instance=whitelist_instance
|
||||
)
|
||||
if whitelist.is_valid():
|
||||
if whitelist.changed_data:
|
||||
whitelist.save()
|
||||
messages.success(request, "Whitelist modifiée")
|
||||
return redirect(reverse('users:index'))
|
||||
|
@ -401,6 +409,7 @@ 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():
|
||||
if school.changed_data:
|
||||
school.save()
|
||||
messages.success(request, "Établissement modifié")
|
||||
return redirect(reverse('users:index-school'))
|
||||
|
@ -448,6 +457,7 @@ 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():
|
||||
if shell.changed_data:
|
||||
shell.save()
|
||||
messages.success(request, "Le shell a été modifié")
|
||||
return redirect(reverse('users:index-shell'))
|
||||
|
@ -492,6 +502,7 @@ def edit_listright(request, listright_instance, listrightid):
|
|||
instance=listright_instance
|
||||
)
|
||||
if listright.is_valid():
|
||||
if listright.changed_data:
|
||||
listright.save()
|
||||
messages.success(request, "Droit modifié")
|
||||
return redirect(reverse('users:index-listright'))
|
||||
|
|
Loading…
Reference in a new issue