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

Utilisation de reverse dans les vues.

This commit is contained in:
LEVY-FALK Hugo 2017-10-26 17:58:41 +02:00 committed by root
parent 0efe0c27d2
commit 42c364fb9a
5 changed files with 318 additions and 187 deletions

View file

@ -37,6 +37,7 @@ nombre d'objets par models, nombre d'actions par user, etc
from __future__ import unicode_literals from __future__ import unicode_literals
from django.urls import reverse
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.contrib import messages from django.contrib import messages
@ -169,7 +170,7 @@ def revert_action(request, revision_id):
if request.method == "POST": if request.method == "POST":
revision.revert() revision.revert()
messages.success(request, "L'action a été supprimée") messages.success(request, "L'action a été supprimée")
return redirect("/logs/") return redirect(reverse('logs:index'))
return form({ return form({
'objet': revision, 'objet': revision,
'objet_name': revision.__class__.__name__ 'objet_name': revision.__class__.__name__

View file

@ -28,6 +28,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.urls import reverse
from django.http import HttpResponse from django.http import HttpResponse
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
@ -213,7 +214,7 @@ def new_machine(request, userid):
user = User.objects.get(pk=userid) user = User.objects.get(pk=userid)
except User.DoesNotExist: except User.DoesNotExist:
messages.error(request, u"Utilisateur inexistant" ) messages.error(request, u"Utilisateur inexistant" )
return redirect("/machines/") return redirect(reverse('machines:index'))
options, created = OptionalMachine.objects.get_or_create() options, created = OptionalMachine.objects.get_or_create()
max_lambdauser_interfaces = options.max_lambdauser_interfaces max_lambdauser_interfaces = options.max_lambdauser_interfaces
if not request.user.has_perms(('cableur',)): if not request.user.has_perms(('cableur',)):
@ -221,10 +222,16 @@ def new_machine(request, userid):
messages.error( messages.error(
request, request,
"Vous ne pouvez pas ajouter une machine à un autre user que vous sans droit") "Vous ne pouvez pas ajouter une machine à un autre user que vous sans droit")
return redirect("/users/profil/" + str(request.user.id)) return redirect(reverse(
'users:profil',
kwargs={'userid':str(request.user.id)}
))
if user.user_interfaces().count() >= max_lambdauser_interfaces: if user.user_interfaces().count() >= max_lambdauser_interfaces:
messages.error(request, "Vous avez atteint le maximum d'interfaces autorisées que vous pouvez créer vous même (%s) " % max_lambdauser_interfaces) messages.error(request, "Vous avez atteint le maximum d'interfaces autorisées que vous pouvez créer vous même (%s) " % max_lambdauser_interfaces)
return redirect("/users/profil/" + str(request.user.id)) return redirect(reverse(
'users:profil',
kwargs={'userid':str(request.user.id)}
))
machine = NewMachineForm(request.POST or None) machine = NewMachineForm(request.POST or None)
interface = AddInterfaceForm(request.POST or None, infra=request.user.has_perms(('infra',))) interface = AddInterfaceForm(request.POST or None, infra=request.user.has_perms(('infra',)))
domain = DomainForm(request.POST or None, user=user) domain = DomainForm(request.POST or None, user=user)
@ -250,7 +257,10 @@ def new_machine(request, userid):
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Création") reversion.set_comment("Création")
messages.success(request, "La machine a été créée") messages.success(request, "La machine a été créée")
return redirect("/users/profil/" + str(user.id)) return redirect(reverse(
'users:profil',
kwargs={'userid':str(user.id)}
))
i_mbf_param = generate_ipv4_mbf_param( interface, False ) i_mbf_param = generate_ipv4_mbf_param( interface, False )
return form({'machineform': machine, 'interfaceform': interface, 'domainform': domain, 'i_mbf_param': i_mbf_param}, 'machines/machine.html', request) return form({'machineform': machine, 'interfaceform': interface, 'domainform': domain, 'i_mbf_param': i_mbf_param}, 'machines/machine.html', request)
@ -262,11 +272,14 @@ def edit_interface(request, interfaceid):
interface = Interface.objects.get(pk=interfaceid) interface = Interface.objects.get(pk=interfaceid)
except Interface.DoesNotExist: except Interface.DoesNotExist:
messages.error(request, u"Interface inexistante" ) messages.error(request, u"Interface inexistante" )
return redirect("/machines") return redirect(reverse('machines:index'))
if not request.user.has_perms(('infra',)): if not request.user.has_perms(('infra',)):
if not request.user.has_perms(('cableur',)) and interface.machine.user != request.user: if not request.user.has_perms(('cableur',)) and interface.machine.user != request.user:
messages.error(request, "Vous ne pouvez pas éditer une machine d'un autre user que vous sans droit") messages.error(request, "Vous ne pouvez pas éditer une machine d'un autre user que vous sans droit")
return redirect("/users/profil/" + str(request.user.id)) return redirect(reverse(
'users:profil',
kwargs={'userid':str(request.user.id)}
))
machine_form = BaseEditMachineForm(request.POST or None, instance=interface.machine) machine_form = BaseEditMachineForm(request.POST or None, instance=interface.machine)
interface_form = BaseEditInterfaceForm(request.POST or None, instance=interface, infra=False) interface_form = BaseEditInterfaceForm(request.POST or None, instance=interface, infra=False)
else: else:
@ -290,7 +303,10 @@ def edit_interface(request, interfaceid):
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in domain_form.changed_data)) reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in domain_form.changed_data))
messages.success(request, "La machine a été modifiée") messages.success(request, "La machine a été modifiée")
return redirect("/users/profil/" + str(interface.machine.user.id)) return redirect(reverse(
'users:profil',
kwargs={'userid':str(interface.machine.user.id)}
))
i_mbf_param = generate_ipv4_mbf_param( interface_form, False ) i_mbf_param = generate_ipv4_mbf_param( interface_form, False )
return form({'machineform': machine_form, 'interfaceform': interface_form, 'domainform': domain_form, 'i_mbf_param': i_mbf_param}, 'machines/machine.html', request) return form({'machineform': machine_form, 'interfaceform': interface_form, 'domainform': domain_form, 'i_mbf_param': i_mbf_param}, 'machines/machine.html', request)
@ -301,17 +317,23 @@ def del_machine(request, machineid):
machine = Machine.objects.get(pk=machineid) machine = Machine.objects.get(pk=machineid)
except Machine.DoesNotExist: except Machine.DoesNotExist:
messages.error(request, u"Machine inexistante" ) messages.error(request, u"Machine inexistante" )
return redirect("/machines") return redirect(reverse('machines:index'))
if not request.user.has_perms(('cableur',)): if not request.user.has_perms(('cableur',)):
if machine.user != request.user: if machine.user != request.user:
messages.error(request, "Vous ne pouvez pas éditer une machine d'un autre user que vous sans droit") messages.error(request, "Vous ne pouvez pas éditer une machine d'un autre user que vous sans droit")
return redirect("/users/profil/" + str(machine.user.id)) return redirect(reverse(
'users:profil',
kwargs={'userid':str(machine.user.id)}
))
if request.method == "POST": if request.method == "POST":
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
machine.delete() machine.delete()
reversion.set_user(request.user) reversion.set_user(request.user)
messages.success(request, "La machine a été détruite") messages.success(request, "La machine a été détruite")
return redirect("/users/profil/" + str(machine.user.id)) return redirect(reverse(
'users:profil',
kwargs={'userid':str(machine.user.id)}
))
return form({'objet': machine, 'objet_name': 'machine'}, 'machines/delete.html', request) return form({'objet': machine, 'objet_name': 'machine'}, 'machines/delete.html', request)
@login_required @login_required
@ -321,16 +343,22 @@ def new_interface(request, machineid):
machine = Machine.objects.get(pk=machineid) machine = Machine.objects.get(pk=machineid)
except Machine.DoesNotExist: except Machine.DoesNotExist:
messages.error(request, u"Machine inexistante" ) messages.error(request, u"Machine inexistante" )
return redirect("/machines") return redirect(reverse('machines:index'))
if not request.user.has_perms(('cableur',)): if not request.user.has_perms(('cableur',)):
options, created = OptionalMachine.objects.get_or_create() options, created = OptionalMachine.objects.get_or_create()
max_lambdauser_interfaces = options.max_lambdauser_interfaces max_lambdauser_interfaces = options.max_lambdauser_interfaces
if machine.user != request.user: if machine.user != request.user:
messages.error(request, "Vous ne pouvez pas ajouter une interface à une machine d'un autre user que vous sans droit") messages.error(request, "Vous ne pouvez pas ajouter une interface à une machine d'un autre user que vous sans droit")
return redirect("/users/profil/" + str(request.user.id)) return redirect(reverse(
'users:profil',
kwargs={'userid':str(request.user.id)}
))
if machine.user.user_interfaces().count() >= max_lambdauser_interfaces: if machine.user.user_interfaces().count() >= max_lambdauser_interfaces:
messages.error(request, "Vous avez atteint le maximum d'interfaces autorisées que vous pouvez créer vous même (%s) " % max_lambdauser_interfaces) messages.error(request, "Vous avez atteint le maximum d'interfaces autorisées que vous pouvez créer vous même (%s) " % max_lambdauser_interfaces)
return redirect("/users/profil/" + str(request.user.id)) return redirect(reverse(
'users:profil',
kwargs={'userid':str(request.user.id)}
))
interface_form = AddInterfaceForm(request.POST or None, infra=request.user.has_perms(('infra',))) interface_form = AddInterfaceForm(request.POST or None, infra=request.user.has_perms(('infra',)))
domain_form = DomainForm(request.POST or None) domain_form = DomainForm(request.POST or None)
if interface_form.is_valid(): if interface_form.is_valid():
@ -349,7 +377,10 @@ def new_interface(request, machineid):
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Création") reversion.set_comment("Création")
messages.success(request, "L'interface a été ajoutée") messages.success(request, "L'interface a été ajoutée")
return redirect("/users/profil/" + str(machine.user.id)) return redirect(reverse(
'users:profil',
kwargs={'userid':str(machine.user.id)}
))
i_mbf_param = generate_ipv4_mbf_param( interface_form, False ) i_mbf_param = generate_ipv4_mbf_param( interface_form, False )
return form({'interfaceform': interface_form, 'domainform': domain_form, 'i_mbf_param': i_mbf_param}, 'machines/machine.html', request) return form({'interfaceform': interface_form, 'domainform': domain_form, 'i_mbf_param': i_mbf_param}, 'machines/machine.html', request)
@ -360,11 +391,14 @@ def del_interface(request, interfaceid):
interface = Interface.objects.get(pk=interfaceid) interface = Interface.objects.get(pk=interfaceid)
except Interface.DoesNotExist: except Interface.DoesNotExist:
messages.error(request, u"Interface inexistante" ) messages.error(request, u"Interface inexistante" )
return redirect("/machines") return redirect(reverse('machines:index'))
if not request.user.has_perms(('cableur',)): if not request.user.has_perms(('cableur',)):
if interface.machine.user != request.user: if interface.machine.user != request.user:
messages.error(request, "Vous ne pouvez pas éditer une machine d'un autre user que vous sans droit") messages.error(request, "Vous ne pouvez pas éditer une machine d'un autre user que vous sans droit")
return redirect("/users/profil/" + str(request.user.id)) return redirect(reverse(
'users:profil',
kwargs={'userid':str(request.user.id)}
))
if request.method == "POST": if request.method == "POST":
machine = interface.machine machine = interface.machine
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
@ -373,7 +407,10 @@ def del_interface(request, interfaceid):
machine.delete() machine.delete()
reversion.set_user(request.user) reversion.set_user(request.user)
messages.success(request, "L'interface a été détruite") messages.success(request, "L'interface a été détruite")
return redirect("/users/profil/" + str(request.user.id)) return redirect(reverse(
'users:profil',
kwargs={'userid':str(request.user.id)}
))
return form({'objet': interface, 'objet_name': 'interface'}, 'machines/delete.html', request) return form({'objet': interface, 'objet_name': 'interface'}, 'machines/delete.html', request)
@login_required @login_required
@ -387,7 +424,7 @@ def add_iptype(request):
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Création") reversion.set_comment("Création")
messages.success(request, "Ce type d'ip a été ajouté") messages.success(request, "Ce type d'ip a été ajouté")
return redirect("/machines/index_iptype") return redirect(reverse('machines:index-iptype'))
return form({'iptypeform': iptype}, 'machines/machine.html', request) return form({'iptypeform': iptype}, 'machines/machine.html', request)
@login_required @login_required
@ -398,7 +435,7 @@ def edit_iptype(request, iptypeid):
iptype_instance = IpType.objects.get(pk=iptypeid) iptype_instance = IpType.objects.get(pk=iptypeid)
except IpType.DoesNotExist: except IpType.DoesNotExist:
messages.error(request, u"Entrée inexistante" ) messages.error(request, u"Entrée inexistante" )
return redirect("/machines/index_iptype/") return redirect(reverse('machines:index-iptype'))
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():
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
@ -406,7 +443,7 @@ def edit_iptype(request, iptypeid):
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in iptype.changed_data)) reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in iptype.changed_data))
messages.success(request, "Type d'ip modifié") messages.success(request, "Type d'ip modifié")
return redirect("/machines/index_iptype/") return redirect(reverse('machines:index-iptype'))
return form({'iptypeform': iptype}, 'machines/machine.html', request) return form({'iptypeform': iptype}, 'machines/machine.html', request)
@login_required @login_required
@ -424,7 +461,7 @@ def del_iptype(request):
messages.success(request, "Le type d'ip a été supprimé") messages.success(request, "Le type d'ip a été supprimé")
except ProtectedError: except ProtectedError:
messages.error(request, "Le type d'ip %s est affectée à au moins une machine, vous ne pouvez pas le supprimer" % iptype_del) messages.error(request, "Le type d'ip %s est affectée à au moins une machine, vous ne pouvez pas le supprimer" % iptype_del)
return redirect("/machines/index_iptype") return redirect(reverse('machines:index-iptype'))
return form({'iptypeform': iptype}, 'machines/machine.html', request) return form({'iptypeform': iptype}, 'machines/machine.html', request)
@login_required @login_required
@ -437,7 +474,7 @@ def add_machinetype(request):
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Création") reversion.set_comment("Création")
messages.success(request, "Ce type de machine a été ajouté") messages.success(request, "Ce type de machine a été ajouté")
return redirect("/machines/index_machinetype") return redirect(reverse('machines:index-machinetype'))
return form({'machinetypeform': machinetype}, 'machines/machine.html', request) return form({'machinetypeform': machinetype}, 'machines/machine.html', request)
@login_required @login_required
@ -447,7 +484,7 @@ def edit_machinetype(request, machinetypeid):
machinetype_instance = MachineType.objects.get(pk=machinetypeid) machinetype_instance = MachineType.objects.get(pk=machinetypeid)
except MachineType.DoesNotExist: except MachineType.DoesNotExist:
messages.error(request, u"Entrée inexistante" ) messages.error(request, u"Entrée inexistante" )
return redirect("/machines/index_machinetype/") return redirect(reverse('machines:index-machinetype'))
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():
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
@ -455,7 +492,7 @@ def edit_machinetype(request, machinetypeid):
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in machinetype.changed_data)) reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in machinetype.changed_data))
messages.success(request, "Type de machine modifié") messages.success(request, "Type de machine modifié")
return redirect("/machines/index_machinetype/") return redirect(reverse('machines:index-machinetype'))
return form({'machinetypeform': machinetype}, 'machines/machine.html', request) return form({'machinetypeform': machinetype}, 'machines/machine.html', request)
@login_required @login_required
@ -472,7 +509,7 @@ def del_machinetype(request):
messages.success(request, "Le type de machine a été supprimé") messages.success(request, "Le type de machine a été supprimé")
except ProtectedError: except ProtectedError:
messages.error(request, "Le type de machine %s est affectée à au moins une machine, vous ne pouvez pas le supprimer" % machinetype_del) messages.error(request, "Le type de machine %s est affectée à au moins une machine, vous ne pouvez pas le supprimer" % machinetype_del)
return redirect("/machines/index_machinetype") return redirect(reverse('machines:index-machinetype'))
return form({'machinetypeform': machinetype}, 'machines/machine.html', request) return form({'machinetypeform': machinetype}, 'machines/machine.html', request)
@login_required @login_required
@ -485,7 +522,7 @@ def add_extension(request):
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Création") reversion.set_comment("Création")
messages.success(request, "Cette extension a été ajoutée") messages.success(request, "Cette extension a été ajoutée")
return redirect("/machines/index_extension") return redirect(reverse('machines:index-extension'))
return form({'extensionform': extension}, 'machines/machine.html', request) return form({'extensionform': extension}, 'machines/machine.html', request)
@login_required @login_required
@ -495,7 +532,7 @@ def edit_extension(request, extensionid):
extension_instance = Extension.objects.get(pk=extensionid) extension_instance = Extension.objects.get(pk=extensionid)
except Extension.DoesNotExist: except Extension.DoesNotExist:
messages.error(request, u"Entrée inexistante" ) messages.error(request, u"Entrée inexistante" )
return redirect("/machines/index_extension/") return redirect(reverse('machines:index-extension'))
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():
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
@ -503,7 +540,7 @@ def edit_extension(request, extensionid):
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in extension.changed_data)) reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in extension.changed_data))
messages.success(request, "Extension modifiée") messages.success(request, "Extension modifiée")
return redirect("/machines/index_extension/") return redirect(reverse('machines:index-extension'))
return form({'extensionform': extension}, 'machines/machine.html', request) return form({'extensionform': extension}, 'machines/machine.html', request)
@login_required @login_required
@ -520,7 +557,7 @@ def del_extension(request):
messages.success(request, "L'extension a été supprimée") messages.success(request, "L'extension a été supprimée")
except ProtectedError: except ProtectedError:
messages.error(request, "L'extension %s est affectée à au moins un type de machine, vous ne pouvez pas la supprimer" % extension_del) messages.error(request, "L'extension %s est affectée à au moins un type de machine, vous ne pouvez pas la supprimer" % extension_del)
return redirect("/machines/index_extension") return redirect(reverse('machines:index-extension'))
return form({'extensionform': extension}, 'machines/machine.html', request) return form({'extensionform': extension}, 'machines/machine.html', request)
@login_required @login_required
@ -533,7 +570,7 @@ def add_soa(request):
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Création") reversion.set_comment("Création")
messages.success(request, "Cet enregistrement SOA a été ajouté") messages.success(request, "Cet enregistrement SOA a été ajouté")
return redirect("/machines/index_extension") return redirect(reverse('machines:index-extension'))
return form({'soaform': soa}, 'machines/machine.html', request) return form({'soaform': soa}, 'machines/machine.html', request)
@login_required @login_required
@ -543,7 +580,7 @@ def edit_soa(request, soaid):
soa_instance = SOA.objects.get(pk=soaid) soa_instance = SOA.objects.get(pk=soaid)
except SOA.DoesNotExist: except SOA.DoesNotExist:
messages.error(request, u"Entrée inexistante" ) messages.error(request, u"Entrée inexistante" )
return redirect("/machines/index_extension/") return redirect(reverse('machines:index-extension'))
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():
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
@ -551,7 +588,7 @@ def edit_soa(request, soaid):
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in soa.changed_data)) reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in soa.changed_data))
messages.success(request, "SOA modifié") messages.success(request, "SOA modifié")
return redirect("/machines/index_extension/") return redirect(reverse('machines:index-extension'))
return form({'soaform': soa}, 'machines/machine.html', request) return form({'soaform': soa}, 'machines/machine.html', request)
@login_required @login_required
@ -568,7 +605,7 @@ def del_soa(request):
messages.success(request, "Le SOA a été supprimée") messages.success(request, "Le SOA a été supprimée")
except ProtectedError: except ProtectedError:
messages.error(request, "Erreur le SOA suivant %s ne peut être supprimé" % soa_del) messages.error(request, "Erreur le SOA suivant %s ne peut être supprimé" % soa_del)
return redirect("/machines/index_extension") return redirect(reverse('machines:index-extension'))
return form({'soaform': soa}, 'machines/machine.html', request) return form({'soaform': soa}, 'machines/machine.html', request)
@login_required @login_required
@ -581,7 +618,7 @@ def add_mx(request):
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Création") reversion.set_comment("Création")
messages.success(request, "Cet enregistrement mx a été ajouté") messages.success(request, "Cet enregistrement mx a été ajouté")
return redirect("/machines/index_extension") return redirect(reverse('machines:index-extension'))
return form({'mxform': mx}, 'machines/machine.html', request) return form({'mxform': mx}, 'machines/machine.html', request)
@login_required @login_required
@ -591,7 +628,7 @@ def edit_mx(request, mxid):
mx_instance = Mx.objects.get(pk=mxid) mx_instance = Mx.objects.get(pk=mxid)
except Mx.DoesNotExist: except Mx.DoesNotExist:
messages.error(request, u"Entrée inexistante" ) messages.error(request, u"Entrée inexistante" )
return redirect("/machines/index_extension/") return redirect(reverse('machines:index-extension'))
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():
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
@ -599,7 +636,7 @@ def edit_mx(request, mxid):
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in mx.changed_data)) reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in mx.changed_data))
messages.success(request, "Mx modifié") messages.success(request, "Mx modifié")
return redirect("/machines/index_extension/") return redirect(reverse('machines:index-extension'))
return form({'mxform': mx}, 'machines/machine.html', request) return form({'mxform': mx}, 'machines/machine.html', request)
@login_required @login_required
@ -616,7 +653,7 @@ def del_mx(request):
messages.success(request, "L'mx a été supprimée") messages.success(request, "L'mx a été supprimée")
except ProtectedError: except ProtectedError:
messages.error(request, "Erreur le Mx suivant %s ne peut être supprimé" % mx_del) messages.error(request, "Erreur le Mx suivant %s ne peut être supprimé" % mx_del)
return redirect("/machines/index_extension") return redirect(reverse('machines:index-extension'))
return form({'mxform': mx}, 'machines/machine.html', request) return form({'mxform': mx}, 'machines/machine.html', request)
@login_required @login_required
@ -629,7 +666,7 @@ def add_ns(request):
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Création") reversion.set_comment("Création")
messages.success(request, "Cet enregistrement ns a été ajouté") messages.success(request, "Cet enregistrement ns a été ajouté")
return redirect("/machines/index_extension") return redirect(reverse('machines:index-extension'))
return form({'nsform': ns}, 'machines/machine.html', request) return form({'nsform': ns}, 'machines/machine.html', request)
@login_required @login_required
@ -639,7 +676,7 @@ def edit_ns(request, nsid):
ns_instance = Ns.objects.get(pk=nsid) ns_instance = Ns.objects.get(pk=nsid)
except Ns.DoesNotExist: except Ns.DoesNotExist:
messages.error(request, u"Entrée inexistante" ) messages.error(request, u"Entrée inexistante" )
return redirect("/machines/index_extension/") return redirect(reverse('machines:index-extension'))
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():
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
@ -647,7 +684,7 @@ def edit_ns(request, nsid):
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in ns.changed_data)) reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in ns.changed_data))
messages.success(request, "Ns modifié") messages.success(request, "Ns modifié")
return redirect("/machines/index_extension/") return redirect(reverse('machines:index-extension'))
return form({'nsform': ns}, 'machines/machine.html', request) return form({'nsform': ns}, 'machines/machine.html', request)
@login_required @login_required
@ -664,7 +701,7 @@ def del_ns(request):
messages.success(request, "Le ns a été supprimée") messages.success(request, "Le ns a été supprimée")
except ProtectedError: except ProtectedError:
messages.error(request, "Erreur le Ns suivant %s ne peut être supprimé" % ns_del) messages.error(request, "Erreur le Ns suivant %s ne peut être supprimé" % ns_del)
return redirect("/machines/index_extension") return redirect(reverse('machines:index-extension'))
return form({'nsform': ns}, 'machines/machine.html', request) return form({'nsform': ns}, 'machines/machine.html', request)
@login_required @login_required
@ -677,7 +714,7 @@ def add_txt(request):
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Création") reversion.set_comment("Création")
messages.success(request, "Cet enregistrement text a été ajouté") messages.success(request, "Cet enregistrement text a été ajouté")
return redirect("/machines/index_extension") return redirect(reverse('machines:index-extension'))
return form({'txtform': txt}, 'machines/machine.html', request) return form({'txtform': txt}, 'machines/machine.html', request)
@login_required @login_required
@ -687,7 +724,7 @@ def edit_txt(request, txtid):
txt_instance = Text.objects.get(pk=txtid) txt_instance = Text.objects.get(pk=txtid)
except Text.DoesNotExist: except Text.DoesNotExist:
messages.error(request, u"Entrée inexistante" ) messages.error(request, u"Entrée inexistante" )
return redirect("/machines/index_extension/") return redirect(reverse('machines:index-extension'))
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():
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
@ -695,7 +732,7 @@ def edit_txt(request, txtid):
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in txt.changed_data)) reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in txt.changed_data))
messages.success(request, "Txt modifié") messages.success(request, "Txt modifié")
return redirect("/machines/index_extension/") return redirect(reverse('machines:index-extension'))
return form({'txtform': txt}, 'machines/machine.html', request) return form({'txtform': txt}, 'machines/machine.html', request)
@login_required @login_required
@ -712,7 +749,7 @@ def del_txt(request):
messages.success(request, "Le txt a été supprimé") messages.success(request, "Le txt a été supprimé")
except ProtectedError: except ProtectedError:
messages.error(request, "Erreur le Txt suivant %s ne peut être supprimé" % txt_del) messages.error(request, "Erreur le Txt suivant %s ne peut être supprimé" % txt_del)
return redirect("/machines/index_extension") return redirect(reverse('machines:index-extension'))
return form({'txtform': txt}, 'machines/machine.html', request) return form({'txtform': txt}, 'machines/machine.html', request)
@login_required @login_required
@ -721,16 +758,22 @@ def add_alias(request, interfaceid):
interface = Interface.objects.get(pk=interfaceid) interface = Interface.objects.get(pk=interfaceid)
except Interface.DoesNotExist: except Interface.DoesNotExist:
messages.error(request, u"Interface inexistante" ) messages.error(request, u"Interface inexistante" )
return redirect("/machines") return redirect(reverse('machines:index'))
if not request.user.has_perms(('cableur',)): if not request.user.has_perms(('cableur',)):
options, created = OptionalMachine.objects.get_or_create() options, created = OptionalMachine.objects.get_or_create()
max_lambdauser_aliases = options.max_lambdauser_aliases max_lambdauser_aliases = options.max_lambdauser_aliases
if interface.machine.user != request.user: if interface.machine.user != request.user:
messages.error(request, "Vous ne pouvez pas ajouter un alias à une machine d'un autre user que vous sans droit") messages.error(request, "Vous ne pouvez pas ajouter un alias à une machine d'un autre user que vous sans droit")
return redirect("/users/profil/" + str(request.user.id)) return redirect(reverse(
'users:profil',
kwargs={'userid':str(request.user.id)}
))
if Domain.objects.filter(cname__in=Domain.objects.filter(interface_parent__in=interface.machine.user.user_interfaces())).count() >= max_lambdauser_aliases: if Domain.objects.filter(cname__in=Domain.objects.filter(interface_parent__in=interface.machine.user.user_interfaces())).count() >= max_lambdauser_aliases:
messages.error(request, "Vous avez atteint le maximum d'alias autorisées que vous pouvez créer vous même (%s) " % max_lambdauser_aliases) messages.error(request, "Vous avez atteint le maximum d'alias autorisées que vous pouvez créer vous même (%s) " % max_lambdauser_aliases)
return redirect("/users/profil/" + str(request.user.id)) return redirect(reverse(
'users:profil',
kwargs={'userid':str(request.user.id)}
))
alias = AliasForm(request.POST or None, infra=request.user.has_perms(('infra',))) alias = AliasForm(request.POST or None, infra=request.user.has_perms(('infra',)))
if alias.is_valid(): if alias.is_valid():
alias = alias.save(commit=False) alias = alias.save(commit=False)
@ -740,7 +783,10 @@ def add_alias(request, interfaceid):
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Création") reversion.set_comment("Création")
messages.success(request, "Cet alias a été ajouté") messages.success(request, "Cet alias a été ajouté")
return redirect("/machines/index_alias/" + str(interfaceid)) return redirect(reverse(
'machines:index-alias',
kwargs={'interfaceid':str(interfaceid)}
))
return form({'aliasform': alias}, 'machines/machine.html', request) return form({'aliasform': alias}, 'machines/machine.html', request)
@login_required @login_required
@ -749,10 +795,13 @@ def edit_alias(request, aliasid):
alias_instance = Domain.objects.get(pk=aliasid) alias_instance = Domain.objects.get(pk=aliasid)
except Domain.DoesNotExist: except Domain.DoesNotExist:
messages.error(request, u"Entrée inexistante" ) messages.error(request, u"Entrée inexistante" )
return redirect("/machines/index_extension/") return redirect(reverse('machines:index-extension'))
if not request.user.has_perms(('cableur',)) and alias_instance.cname.interface_parent.machine.user != request.user: if not request.user.has_perms(('cableur',)) and alias_instance.cname.interface_parent.machine.user != request.user:
messages.error(request, "Vous ne pouvez pas ajouter un alias à une machine d'un autre user que vous sans droit") messages.error(request, "Vous ne pouvez pas ajouter un alias à une machine d'un autre user que vous sans droit")
return redirect("/users/profil/" + str(request.user.id)) return redirect(reverse(
'users:profil',
kwargs={'userid':str(request.user.id)}
))
alias = AliasForm(request.POST or None, instance=alias_instance, infra=request.user.has_perms(('infra',))) alias = AliasForm(request.POST or None, instance=alias_instance, infra=request.user.has_perms(('infra',)))
if alias.is_valid(): if alias.is_valid():
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
@ -760,7 +809,10 @@ def edit_alias(request, aliasid):
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in alias.changed_data)) reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in alias.changed_data))
messages.success(request, "Alias modifié") messages.success(request, "Alias modifié")
return redirect("/machines/index_alias/" + str(alias_instance.cname.interface_parent.id)) return redirect(reverse(
'machines:index-alias',
kwargs={'interfaceid':str(alias_instance.cname.interface_parent.id)}
))
return form({'aliasform': alias}, 'machines/machine.html', request) return form({'aliasform': alias}, 'machines/machine.html', request)
@login_required @login_required
@ -769,10 +821,13 @@ def del_alias(request, interfaceid):
interface = Interface.objects.get(pk=interfaceid) interface = Interface.objects.get(pk=interfaceid)
except Interface.DoesNotExist: except Interface.DoesNotExist:
messages.error(request, u"Interface inexistante" ) messages.error(request, u"Interface inexistante" )
return redirect("/machines") return redirect(reverse('machines:index'))
if not request.user.has_perms(('cableur',)) and interface.machine.user != request.user: if not request.user.has_perms(('cableur',)) and interface.machine.user != request.user:
messages.error(request, "Vous ne pouvez pas ajouter un alias à une machine d'un autre user que vous sans droit") messages.error(request, "Vous ne pouvez pas ajouter un alias à une machine d'un autre user que vous sans droit")
return redirect("/users/profil/" + str(request.user.id)) return redirect(reverse(
'users:profil',
kwargs={'userid':str(request.user.id)}
))
alias = DelAliasForm(request.POST or None, interface=interface) alias = DelAliasForm(request.POST or None, interface=interface)
if alias.is_valid(): if alias.is_valid():
alias_dels = alias.cleaned_data['alias'] alias_dels = alias.cleaned_data['alias']
@ -784,7 +839,10 @@ def del_alias(request, interfaceid):
messages.success(request, "L'alias %s a été supprimé" % alias_del) messages.success(request, "L'alias %s a été supprimé" % alias_del)
except ProtectedError: except ProtectedError:
messages.error(request, "Erreur l'alias suivant %s ne peut être supprimé" % alias_del) messages.error(request, "Erreur l'alias suivant %s ne peut être supprimé" % alias_del)
return redirect("/machines/index_alias/" + str(interfaceid)) return redirect(reverse(
'machines:index-alias',
kwargs={'interfaceid':str(interfaceid)}
))
return form({'aliasform': alias}, 'machines/machine.html', request) return form({'aliasform': alias}, 'machines/machine.html', request)
@ -798,7 +856,7 @@ def add_service(request):
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Création") reversion.set_comment("Création")
messages.success(request, "Cet enregistrement service a été ajouté") messages.success(request, "Cet enregistrement service a été ajouté")
return redirect("/machines/index_service") return redirect(reverse('machines:index-service'))
return form({'serviceform': service}, 'machines/machine.html', request) return form({'serviceform': service}, 'machines/machine.html', request)
@login_required @login_required
@ -808,7 +866,7 @@ def edit_service(request, serviceid):
service_instance = Service.objects.get(pk=serviceid) service_instance = Service.objects.get(pk=serviceid)
except Ns.DoesNotExist: except Ns.DoesNotExist:
messages.error(request, u"Entrée inexistante" ) messages.error(request, u"Entrée inexistante" )
return redirect("/machines/index_extension/") return redirect(reverse('machines:index-extension'))
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():
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
@ -816,7 +874,7 @@ def edit_service(request, serviceid):
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in service.changed_data)) reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in service.changed_data))
messages.success(request, "Service modifié") messages.success(request, "Service modifié")
return redirect("/machines/index_service/") return redirect(reverse('machines:index-service'))
return form({'serviceform': service}, 'machines/machine.html', request) return form({'serviceform': service}, 'machines/machine.html', request)
@login_required @login_required
@ -833,7 +891,7 @@ def del_service(request):
messages.success(request, "Le service a été supprimée") messages.success(request, "Le service a été supprimée")
except ProtectedError: except ProtectedError:
messages.error(request, "Erreur le service suivant %s ne peut être supprimé" % service_del) messages.error(request, "Erreur le service suivant %s ne peut être supprimé" % service_del)
return redirect("/machines/index_service") return redirect(reverse('machines:index-service'))
return form({'serviceform': service}, 'machines/machine.html', request) return form({'serviceform': service}, 'machines/machine.html', request)
@login_required @login_required
@ -846,7 +904,7 @@ def add_vlan(request):
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Création") reversion.set_comment("Création")
messages.success(request, "Cet enregistrement vlan a été ajouté") messages.success(request, "Cet enregistrement vlan a été ajouté")
return redirect("/machines/index_vlan") return redirect(reverse('machines:index-vlan'))
return form({'vlanform': vlan}, 'machines/machine.html', request) return form({'vlanform': vlan}, 'machines/machine.html', request)
@login_required @login_required
@ -856,7 +914,7 @@ def edit_vlan(request, vlanid):
vlan_instance = Vlan.objects.get(pk=vlanid) vlan_instance = Vlan.objects.get(pk=vlanid)
except Vlan.DoesNotExist: except Vlan.DoesNotExist:
messages.error(request, u"Entrée inexistante" ) messages.error(request, u"Entrée inexistante" )
return redirect("/machines/index_vlan/") return redirect(reverse('machines:index-vlan'))
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():
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
@ -864,7 +922,7 @@ def edit_vlan(request, vlanid):
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in vlan.changed_data)) reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in vlan.changed_data))
messages.success(request, "Vlan modifié") messages.success(request, "Vlan modifié")
return redirect("/machines/index_vlan/") return redirect(reverse('machines:index-vlan'))
return form({'vlanform': vlan}, 'machines/machine.html', request) return form({'vlanform': vlan}, 'machines/machine.html', request)
@login_required @login_required
@ -881,7 +939,7 @@ def del_vlan(request):
messages.success(request, "Le vlan a été supprimée") messages.success(request, "Le vlan a été supprimée")
except ProtectedError: except ProtectedError:
messages.error(request, "Erreur le Vlan suivant %s ne peut être supprimé" % vlan_del) messages.error(request, "Erreur le Vlan suivant %s ne peut être supprimé" % vlan_del)
return redirect("/machines/index_vlan") return redirect(reverse('machines:index-vlan'))
return form({'vlanform': vlan}, 'machines/machine.html', request) return form({'vlanform': vlan}, 'machines/machine.html', request)
@login_required @login_required
@ -894,7 +952,7 @@ def add_nas(request):
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Création") reversion.set_comment("Création")
messages.success(request, "Cet enregistrement nas a été ajouté") messages.success(request, "Cet enregistrement nas a été ajouté")
return redirect("/machines/index_nas") return redirect(reverse('machines:index-nas'))
return form({'nasform': nas}, 'machines/machine.html', request) return form({'nasform': nas}, 'machines/machine.html', request)
@login_required @login_required
@ -904,7 +962,7 @@ def edit_nas(request, nasid):
nas_instance = Nas.objects.get(pk=nasid) nas_instance = Nas.objects.get(pk=nasid)
except Nas.DoesNotExist: except Nas.DoesNotExist:
messages.error(request, u"Entrée inexistante" ) messages.error(request, u"Entrée inexistante" )
return redirect("/machines/index_nas/") return redirect(reverse('machines:index-nas'))
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():
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
@ -912,7 +970,7 @@ def edit_nas(request, nasid):
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in nas.changed_data)) reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in nas.changed_data))
messages.success(request, "Nas modifié") messages.success(request, "Nas modifié")
return redirect("/machines/index_nas/") return redirect(reverse('machines:index-nas'))
return form({'nasform': nas}, 'machines/machine.html', request) return form({'nasform': nas}, 'machines/machine.html', request)
@login_required @login_required
@ -929,7 +987,7 @@ def del_nas(request):
messages.success(request, "Le nas a été supprimé") messages.success(request, "Le nas a été supprimé")
except ProtectedError: except ProtectedError:
messages.error(request, "Erreur le Nas suivant %s ne peut être supprimé" % nas_del) messages.error(request, "Erreur le Nas suivant %s ne peut être supprimé" % nas_del)
return redirect("/machines/index_nas") return redirect(reverse('machines:index-nas'))
return form({'nasform': nas}, 'machines/machine.html', request) return form({'nasform': nas}, 'machines/machine.html', request)
@login_required @login_required
@ -996,10 +1054,13 @@ def index_alias(request, interfaceid):
interface = Interface.objects.get(pk=interfaceid) interface = Interface.objects.get(pk=interfaceid)
except Interface.DoesNotExist: except Interface.DoesNotExist:
messages.error(request, u"Interface inexistante" ) messages.error(request, u"Interface inexistante" )
return redirect("/machines") return redirect(reverse('machines:index'))
if not request.user.has_perms(('cableur',)) and interface.machine.user != request.user: if not request.user.has_perms(('cableur',)) and interface.machine.user != request.user:
messages.error(request, "Vous ne pouvez pas éditer une machine d'un autre user que vous sans droit") messages.error(request, "Vous ne pouvez pas éditer une machine d'un autre user que vous sans droit")
return redirect("/users/profil/" + str(request.user.id)) return redirect(reverse(
'users:profil',
kwargs={'userid':str(request.user.id)}
))
alias_list = Domain.objects.filter(cname=Domain.objects.filter(interface_parent=interface)).order_by('name') alias_list = Domain.objects.filter(cname=Domain.objects.filter(interface_parent=interface)).order_by('name')
return render(request, 'machines/index_alias.html', {'alias_list':alias_list, 'interface_id': interfaceid}) return render(request, 'machines/index_alias.html', {'alias_list':alias_list, 'interface_id': interfaceid})
@ -1017,91 +1078,100 @@ def history(request, object, id):
object_instance = Machine.objects.get(pk=id) object_instance = Machine.objects.get(pk=id)
except Machine.DoesNotExist: except Machine.DoesNotExist:
messages.error(request, "Machine inexistante") messages.error(request, "Machine inexistante")
return redirect("/machines/") return redirect(reverse('machines:index'))
if not request.user.has_perms(('cableur',)) and object_instance.user != request.user: if not request.user.has_perms(('cableur',)) and object_instance.user != request.user:
messages.error(request, "Vous ne pouvez pas afficher l'historique d'une machine d'un autre user que vous sans droit cableur") messages.error(request, "Vous ne pouvez pas afficher l'historique d'une machine d'un autre user que vous sans droit cableur")
return redirect("/users/profil/" + str(request.user.id)) return redirect(reverse(
'users:profil',
kwargs={'userid':str(request.user.id)}
))
elif object == 'interface': elif object == 'interface':
try: try:
object_instance = Interface.objects.get(pk=id) object_instance = Interface.objects.get(pk=id)
except Interface.DoesNotExist: except Interface.DoesNotExist:
messages.error(request, "Interface inexistante") messages.error(request, "Interface inexistante")
return redirect("/machines/") return redirect(reverse('machines:index'))
if not request.user.has_perms(('cableur',)) and object_instance.machine.user != request.user: if not request.user.has_perms(('cableur',)) and object_instance.machine.user != request.user:
messages.error(request, "Vous ne pouvez pas afficher l'historique d'une interface d'un autre user que vous sans droit cableur") messages.error(request, "Vous ne pouvez pas afficher l'historique d'une interface d'un autre user que vous sans droit cableur")
return redirect("/users/profil/" + str(request.user.id)) return redirect(reverse(
'users:profil',
kwargs={'userid':str(request.user.id)}
))
elif object == 'alias': elif object == 'alias':
try: try:
object_instance = Domain.objects.get(pk=id) object_instance = Domain.objects.get(pk=id)
except Domain.DoesNotExist: except Domain.DoesNotExist:
messages.error(request, "Alias inexistant") messages.error(request, "Alias inexistant")
return redirect("/machines/") return redirect(reverse('machines:index'))
if not request.user.has_perms(('cableur',)) and object_instance.cname.interface_parent.machine.user != request.user: if not request.user.has_perms(('cableur',)) and object_instance.cname.interface_parent.machine.user != request.user:
messages.error(request, "Vous ne pouvez pas afficher l'historique d'un alias d'un autre user que vous sans droit cableur") messages.error(request, "Vous ne pouvez pas afficher l'historique d'un alias d'un autre user que vous sans droit cableur")
return redirect("/users/profil/" + str(request.user.id)) return redirect(reverse(
'users:profil',
kwargs={'userid':str(request.user.id)}
))
elif object == 'machinetype' and request.user.has_perms(('cableur',)): elif object == 'machinetype' and request.user.has_perms(('cableur',)):
try: try:
object_instance = MachineType.objects.get(pk=id) object_instance = MachineType.objects.get(pk=id)
except MachineType.DoesNotExist: except MachineType.DoesNotExist:
messages.error(request, "Type de machine inexistant") messages.error(request, "Type de machine inexistant")
return redirect("/machines/") return redirect(reverse('machines:index'))
elif object == 'iptype' and request.user.has_perms(('cableur',)): elif object == 'iptype' and request.user.has_perms(('cableur',)):
try: try:
object_instance = IpType.objects.get(pk=id) object_instance = IpType.objects.get(pk=id)
except IpType.DoesNotExist: except IpType.DoesNotExist:
messages.error(request, "Type d'ip inexistant") messages.error(request, "Type d'ip inexistant")
return redirect("/machines/") return redirect(reverse('machines:index'))
elif object == 'extension' and request.user.has_perms(('cableur',)): elif object == 'extension' and request.user.has_perms(('cableur',)):
try: try:
object_instance = Extension.objects.get(pk=id) object_instance = Extension.objects.get(pk=id)
except Extension.DoesNotExist: except Extension.DoesNotExist:
messages.error(request, "Extension inexistante") messages.error(request, "Extension inexistante")
return redirect("/machines/") return redirect(reverse('machines:index'))
elif object == 'soa' and request.user.has_perms(('cableur',)): elif object == 'soa' and request.user.has_perms(('cableur',)):
try: try:
object_instance = SOA.objects.get(pk=id) object_instance = SOA.objects.get(pk=id)
except SOA.DoesNotExist: except SOA.DoesNotExist:
messages.error(request, "SOA inexistant") messages.error(request, "SOA inexistant")
return redirect("/machines/") return redirect(reverse('machines:index'))
elif object == 'mx' and request.user.has_perms(('cableur',)): elif object == 'mx' and request.user.has_perms(('cableur',)):
try: try:
object_instance = Mx.objects.get(pk=id) object_instance = Mx.objects.get(pk=id)
except Mx.DoesNotExist: except Mx.DoesNotExist:
messages.error(request, "Mx inexistant") messages.error(request, "Mx inexistant")
return redirect("/machines/") return redirect(reverse('machines:index'))
elif object == 'txt' and request.user.has_perms(('cableur',)): elif object == 'txt' and request.user.has_perms(('cableur',)):
try: try:
object_instance = Text.objects.get(pk=id) object_instance = Text.objects.get(pk=id)
except Text.DoesNotExist: except Text.DoesNotExist:
messages.error(request, "Txt inexistant") messages.error(request, "Txt inexistant")
return redirect("/machines/") return redirect(reverse('machines:index'))
elif object == 'ns' and request.user.has_perms(('cableur',)): elif object == 'ns' and request.user.has_perms(('cableur',)):
try: try:
object_instance = Ns.objects.get(pk=id) object_instance = Ns.objects.get(pk=id)
except Ns.DoesNotExist: except Ns.DoesNotExist:
messages.error(request, "Ns inexistant") messages.error(request, "Ns inexistant")
return redirect("/machines/") return redirect(reverse('machines:index'))
elif object == 'service' and request.user.has_perms(('cableur',)): elif object == 'service' and request.user.has_perms(('cableur',)):
try: try:
object_instance = Service.objects.get(pk=id) object_instance = Service.objects.get(pk=id)
except Service.DoesNotExist: except Service.DoesNotExist:
messages.error(request, "Service inexistant") messages.error(request, "Service inexistant")
return redirect("/machines/") return redirect(reverse('machines:index'))
elif object == 'vlan' and request.user.has_perms(('cableur',)): elif object == 'vlan' and request.user.has_perms(('cableur',)):
try: try:
object_instance = Vlan.objects.get(pk=id) object_instance = Vlan.objects.get(pk=id)
except Vlan.DoesNotExist: except Vlan.DoesNotExist:
messages.error(request, "Vlan inexistant") messages.error(request, "Vlan inexistant")
return redirect("/machines/") return redirect(reverse('machines:index'))
elif object == 'nas' and request.user.has_perms(('cableur',)): elif object == 'nas' and request.user.has_perms(('cableur',)):
try: try:
object_instance = Nas.objects.get(pk=id) object_instance = Nas.objects.get(pk=id)
except Nas.DoesNotExist: except Nas.DoesNotExist:
messages.error(request, "Nas inexistant") messages.error(request, "Nas inexistant")
return redirect("/machines/") return redirect(reverse('machines:index'))
else: else:
messages.error(request, "Objet inconnu") messages.error(request, "Objet inconnu")
return redirect("/machines/") return redirect(reverse('machines:index'))
options, created = GeneralOption.objects.get_or_create() options, created = GeneralOption.objects.get_or_create()
pagination_number = options.pagination_number pagination_number = options.pagination_number
reversions = Version.objects.get_for_object(object_instance) reversions = Version.objects.get_for_object(object_instance)
@ -1133,7 +1203,7 @@ def edit_portlist(request, pk):
port_list_instance = OuverturePortList.objects.get(pk=pk) port_list_instance = OuverturePortList.objects.get(pk=pk)
except OuverturePortList.DoesNotExist: except OuverturePortList.DoesNotExist:
messages.error(request, "Liste de ports inexistante") messages.error(request, "Liste de ports inexistante")
return redirect("/machines/index_portlist/") return redirect(reverse('machines:index-portlist'))
port_list = EditOuverturePortListForm(request.POST or None, instance=port_list_instance) port_list = EditOuverturePortListForm(request.POST or None, instance=port_list_instance)
port_formset = modelformset_factory( port_formset = modelformset_factory(
OuverturePort, OuverturePort,
@ -1152,7 +1222,7 @@ def edit_portlist(request, pk):
port.port_list = pl port.port_list = pl
port.save() port.save()
messages.success(request, "Liste de ports modifiée") messages.success(request, "Liste de ports modifiée")
return redirect("/machines/index_portlist/") return redirect(reverse('machines:index-portlist'))
return form({'port_list' : port_list, 'ports' : port_formset}, 'machines/edit_portlist.html', request) return form({'port_list' : port_list, 'ports' : port_formset}, 'machines/edit_portlist.html', request)
@login_required @login_required
@ -1162,13 +1232,13 @@ def del_portlist(request, pk):
port_list_instance = OuverturePortList.objects.get(pk=pk) port_list_instance = OuverturePortList.objects.get(pk=pk)
except OuverturePortList.DoesNotExist: except OuverturePortList.DoesNotExist:
messages.error(request, "Liste de ports inexistante") messages.error(request, "Liste de ports inexistante")
return redirect("/machines/index_portlist/") return redirect(reverse('machines:index-portlist'))
if port_list_instance.interface_set.all(): if port_list_instance.interface_set.all():
messages.error(request, "Cette liste de ports est utilisée") messages.error(request, "Cette liste de ports est utilisée")
return redirect("/machines/index_portlist/") return redirect(reverse('machines:index-portlist'))
port_list_instance.delete() port_list_instance.delete()
messages.success(request, "La liste de ports a été supprimée") messages.success(request, "La liste de ports a été supprimée")
return redirect("/machines/index_portlist/") return redirect(reverse('machines:index-portlist'))
@login_required @login_required
@permission_required('bureau') @permission_required('bureau')
@ -1191,13 +1261,13 @@ def add_portlist(request):
port.port_list = pl port.port_list = pl
port.save() port.save()
messages.success(request, "Liste de ports créée") messages.success(request, "Liste de ports créée")
return redirect("/machines/index_portlist/") return redirect(reverse('machines:index-portlist'))
return form({'port_list' : port_list, 'ports' : port_formset}, 'machines/edit_portlist.html', request) return form({'port_list' : port_list, 'ports' : port_formset}, 'machines/edit_portlist.html', request)
port_list = EditOuverturePortListForm(request.POST or None) port_list = EditOuverturePortListForm(request.POST or None)
if port_list.is_valid(): if port_list.is_valid():
port_list.save() port_list.save()
messages.success(request, "Liste de ports créée") messages.success(request, "Liste de ports créée")
return redirect("/machines/index_portlist/") return redirect(reverse('machines:index-portlist'))
return form({'machineform' : port_list}, 'machines/machine.html', request) return form({'machineform' : port_list}, 'machines/machine.html', request)
@login_required @login_required
@ -1207,14 +1277,14 @@ def configure_ports(request, pk):
interface_instance = Interface.objects.get(pk=pk) interface_instance = Interface.objects.get(pk=pk)
except Interface.DoesNotExist: except Interface.DoesNotExist:
messages.error(request, u"Interface inexistante" ) messages.error(request, u"Interface inexistante" )
return redirect("/machines") return redirect(reverse('machines:index'))
if not interface_instance.may_have_port_open(): if not interface_instance.may_have_port_open():
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() interface.save()
messages.success(request, "Configuration des ports mise à jour.") messages.success(request, "Configuration des ports mise à jour.")
return redirect("/machines/") return redirect(reverse('machines:index'))
return form({'interfaceform' : interface}, 'machines/machine.html', request) return form({'interfaceform' : interface}, 'machines/machine.html', request)
""" Framework Rest """ """ Framework Rest """

View file

@ -30,6 +30,7 @@ topologie, users, service...)
from __future__ import unicode_literals from __future__ import unicode_literals
from django.urls import reverse
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.contrib import messages from django.contrib import messages
@ -93,7 +94,7 @@ def edit_options(request, section):
) )
) )
messages.success(request, "Préférences modifiées") messages.success(request, "Préférences modifiées")
return redirect("/preferences/") return redirect(reverse('preferences:display-options'))
return form( return form(
{'options': options}, {'options': options},
'preferences/edit_preferences.html', 'preferences/edit_preferences.html',
@ -101,7 +102,7 @@ def edit_options(request, section):
) )
else: else:
messages.error(request, "Objet inconnu") messages.error(request, "Objet inconnu")
return redirect("/preferences/") return redirect(reverse('preferences:display-options'))
@login_required @login_required
@ -115,7 +116,7 @@ def add_services(request):
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Création") reversion.set_comment("Création")
messages.success(request, "Cet enregistrement ns a été ajouté") messages.success(request, "Cet enregistrement ns a été ajouté")
return redirect("/preferences/") return redirect(reverse('preferences:display-options'))
return form( return form(
{'preferenceform': services}, {'preferenceform': services},
'preferences/preferences.html', 'preferences/preferences.html',
@ -131,7 +132,7 @@ def edit_services(request, servicesid):
services_instance = Service.objects.get(pk=servicesid) services_instance = Service.objects.get(pk=servicesid)
except Service.DoesNotExist: except Service.DoesNotExist:
messages.error(request, u"Entrée inexistante") messages.error(request, u"Entrée inexistante")
return redirect("/preferences/") return redirect(reverse('preferences:display-options'))
services = ServiceForm(request.POST or None, instance=services_instance) services = ServiceForm(request.POST or None, instance=services_instance)
if services.is_valid(): if services.is_valid():
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
@ -143,7 +144,7 @@ def edit_services(request, servicesid):
) )
) )
messages.success(request, "Service modifié") messages.success(request, "Service modifié")
return redirect("/preferences/") return redirect(reverse('preferences:display-options'))
return form( return form(
{'preferenceform': services}, {'preferenceform': services},
'preferences/preferences.html', 'preferences/preferences.html',
@ -167,7 +168,7 @@ def del_services(request):
except ProtectedError: except ProtectedError:
messages.error(request, "Erreur le service\ messages.error(request, "Erreur le service\
suivant %s ne peut être supprimé" % services_del) suivant %s ne peut être supprimé" % services_del)
return redirect("/preferences/") return redirect(reverse('preferences:display-options'))
return form( return form(
{'preferenceform': services}, {'preferenceform': services},
'preferences/preferences.html', 'preferences/preferences.html',
@ -185,7 +186,7 @@ def history(request, object_name, object_id):
object_instance = Service.objects.get(pk=object_id) object_instance = Service.objects.get(pk=object_id)
except Service.DoesNotExist: except Service.DoesNotExist:
messages.error(request, "Service inexistant") messages.error(request, "Service inexistant")
return redirect("/preferences/") return redirect(reverse('preferences:display-options'))
options, _created = GeneralOption.objects.get_or_create() options, _created = GeneralOption.objects.get_or_create()
pagination_number = options.pagination_number pagination_number = options.pagination_number
reversions = Version.objects.get_for_object(object_instance) reversions = Version.objects.get_for_object(object_instance)

View file

@ -35,6 +35,7 @@ coté models et forms de topologie
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
from django.urls import reverse
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.decorators import login_required, permission_required from django.contrib.auth.decorators import login_required, permission_required
@ -84,28 +85,28 @@ def history(request, object_name, object_id):
object_instance = Switch.objects.get(pk=object_id) object_instance = Switch.objects.get(pk=object_id)
except Switch.DoesNotExist: except Switch.DoesNotExist:
messages.error(request, "Switch inexistant") messages.error(request, "Switch inexistant")
return redirect("/topologie/") return redirect(reverse('topologie:index'))
elif object_name == 'port': elif object_name == 'port':
try: try:
object_instance = Port.objects.get(pk=object_id) object_instance = Port.objects.get(pk=object_id)
except Port.DoesNotExist: except Port.DoesNotExist:
messages.error(request, "Port inexistant") messages.error(request, "Port inexistant")
return redirect("/topologie/") return redirect(reverse('topologie:index'))
elif object_name == 'room': elif object_name == 'room':
try: try:
object_instance = Room.objects.get(pk=object_id) object_instance = Room.objects.get(pk=object_id)
except Room.DoesNotExist: except Room.DoesNotExist:
messages.error(request, "Chambre inexistante") messages.error(request, "Chambre inexistante")
return redirect("/topologie/") return redirect(reverse('topologie:index'))
elif object_name == 'stack': elif object_name == 'stack':
try: try:
object_instance = Stack.objects.get(pk=object_id) object_instance = Stack.objects.get(pk=object_id)
except Room.DoesNotExist: except Room.DoesNotExist:
messages.error(request, "Stack inexistante") messages.error(request, "Stack inexistante")
return redirect("/topologie/") return redirect(reverse('topologie:index'))
else: else:
messages.error(request, "Objet inconnu") messages.error(request, "Objet inconnu")
return redirect("/topologie/") return redirect(reverse('topologie:index'))
options, _created = GeneralOption.objects.get_or_create() options, _created = GeneralOption.objects.get_or_create()
pagination_number = options.pagination_number pagination_number = options.pagination_number
reversions = Version.objects.get_for_object(object_instance) reversions = Version.objects.get_for_object(object_instance)
@ -133,7 +134,7 @@ def index_port(request, switch_id):
switch = Switch.objects.get(pk=switch_id) switch = Switch.objects.get(pk=switch_id)
except Switch.DoesNotExist: except Switch.DoesNotExist:
messages.error(request, u"Switch inexistant") messages.error(request, u"Switch inexistant")
return redirect("/topologie/") return redirect(reverse('topologie:index'))
port_list = Port.objects.filter(switch=switch)\ port_list = Port.objects.filter(switch=switch)\
.select_related('room')\ .select_related('room')\
.select_related('machine_interface__domain__extension')\ .select_related('machine_interface__domain__extension')\
@ -206,7 +207,7 @@ def new_port(request, switch_id):
switch = Switch.objects.get(pk=switch_id) switch = Switch.objects.get(pk=switch_id)
except Switch.DoesNotExist: except Switch.DoesNotExist:
messages.error(request, u"Switch inexistant") messages.error(request, u"Switch inexistant")
return redirect("/topologie/") return redirect(reverse('topologie:index'))
port = AddPortForm(request.POST or None) port = AddPortForm(request.POST or None)
if port.is_valid(): if port.is_valid():
port = port.save(commit=False) port = port.save(commit=False)
@ -219,7 +220,10 @@ def new_port(request, switch_id):
messages.success(request, "Port ajouté") messages.success(request, "Port ajouté")
except IntegrityError: except IntegrityError:
messages.error(request, "Ce port existe déjà") messages.error(request, "Ce port existe déjà")
return redirect("/topologie/switch/" + switch_id) return redirect(reverse(
'topologie:index-port',
kwargs={'switch_id':switch_id}
))
return form({'topoform': port}, 'topologie/topo.html', request) return form({'topoform': port}, 'topologie/topo.html', request)
@ -238,7 +242,7 @@ def edit_port(request, port_id):
.get(pk=port_id) .get(pk=port_id)
except Port.DoesNotExist: except Port.DoesNotExist:
messages.error(request, u"Port inexistant") messages.error(request, u"Port inexistant")
return redirect("/topologie/") return redirect(reverse('topologie:index'))
port = EditPortForm(request.POST or None, instance=port_object) port = EditPortForm(request.POST or None, instance=port_object)
if port.is_valid(): if port.is_valid():
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
@ -248,7 +252,10 @@ def edit_port(request, port_id):
field for field in port.changed_data field for field in port.changed_data
)) ))
messages.success(request, "Le port a bien été modifié") messages.success(request, "Le port a bien été modifié")
return redirect("/topologie/switch/" + str(port_object.switch.id)) return redirect(reverse(
'topologie:index-port',
kwargs={'switch_id': str(port_object.switch.id)}
))
return form({'topoform': port}, 'topologie/topo.html', request) return form({'topoform': port}, 'topologie/topo.html', request)
@ -260,7 +267,7 @@ def del_port(request, port_id):
port = Port.objects.get(pk=port_id) port = Port.objects.get(pk=port_id)
except Port.DoesNotExist: except Port.DoesNotExist:
messages.error(request, u"Port inexistant") messages.error(request, u"Port inexistant")
return redirect('/topologie/') return redirect(reverse('topologie:index'))
if request.method == "POST": if request.method == "POST":
try: try:
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
@ -271,7 +278,10 @@ def del_port(request, port_id):
except ProtectedError: except ProtectedError:
messages.error(request, "Le port %s est affecté à un autre objet,\ messages.error(request, "Le port %s est affecté à un autre objet,\
impossible de le supprimer" % port) impossible de le supprimer" % port)
return redirect('/topologie/switch/' + str(port.switch.id)) return redirect(reverse(
'topologie:index-port',
kwargs={'switch_id':str(port.switch.id)
))
return form({'objet': port}, 'topologie/delete.html', request) return form({'objet': port}, 'topologie/delete.html', request)
@ -297,7 +307,7 @@ def edit_stack(request, stack_id):
stack = Stack.objects.get(pk=stack_id) stack = Stack.objects.get(pk=stack_id)
except Stack.DoesNotExist: except Stack.DoesNotExist:
messages.error(request, u"Stack inexistante") messages.error(request, u"Stack inexistante")
return redirect('/topologie/index_stack/') return redirect(reverse('topologie:index-stack'))
stack = StackForm(request.POST or None, instance=stack) stack = StackForm(request.POST or None, instance=stack)
if stack.is_valid(): if stack.is_valid():
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
@ -308,7 +318,7 @@ def edit_stack(request, stack_id):
field for field in stack.changed_data field for field in stack.changed_data
) )
) )
return redirect('/topologie/index_stack') return redirect(reverse('topologie:index-stack'))
return form({'topoform': stack}, 'topologie/topo.html', request) return form({'topoform': stack}, 'topologie/topo.html', request)
@ -320,7 +330,7 @@ def del_stack(request, stack_id):
stack = Stack.objects.get(pk=stack_id) stack = Stack.objects.get(pk=stack_id)
except Stack.DoesNotExist: except Stack.DoesNotExist:
messages.error(request, u"Stack inexistante") messages.error(request, u"Stack inexistante")
return redirect('/topologie/index_stack') return redirect(reverse('topologie:index-stack'))
if request.method == "POST": if request.method == "POST":
try: try:
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
@ -331,7 +341,7 @@ def del_stack(request, stack_id):
except ProtectedError: except ProtectedError:
messages.error(request, "La stack %s est affectée à un autre\ messages.error(request, "La stack %s est affectée à un autre\
objet, impossible de la supprimer" % stack) objet, impossible de la supprimer" % stack)
return redirect('/topologie/index_stack') return redirect(reverse('topologie:index-stack'))
return form({'objet': stack}, 'topologie/delete.html', request) return form({'objet': stack}, 'topologie/delete.html', request)
@ -343,7 +353,7 @@ def edit_switchs_stack(request, stack_id):
stack = Stack.objects.get(pk=stack_id) stack = Stack.objects.get(pk=stack_id)
except Stack.DoesNotExist: except Stack.DoesNotExist:
messages.error(request, u"Stack inexistante") messages.error(request, u"Stack inexistante")
return redirect('/topologie/index_stack') return redirect(reverse('topologie:index-stack'))
if request.method == "POST": if request.method == "POST":
pass pass
else: else:
@ -373,7 +383,7 @@ def new_switch(request):
if not user: if not user:
messages.error(request, "L'user association n'existe pas encore,\ messages.error(request, "L'user association n'existe pas encore,\
veuillez le créer ou le linker dans preferences") veuillez le créer ou le linker dans preferences")
return redirect("/topologie/") return redirect(reverse('topologie:index'))
new_machine = machine.save(commit=False) new_machine = machine.save(commit=False)
new_machine.user = user new_machine.user = user
new_interface = interface.save(commit=False) new_interface = interface.save(commit=False)
@ -399,7 +409,7 @@ def new_switch(request):
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Création") reversion.set_comment("Création")
messages.success(request, "Le switch a été créé") messages.success(request, "Le switch a été créé")
return redirect("/topologie/") return redirect(reverse('topologie:index'))
i_mbf_param = generate_ipv4_mbf_param( interface, False ) i_mbf_param = generate_ipv4_mbf_param( interface, False )
return form({ return form({
'topoform': switch, 'topoform': switch,
@ -419,7 +429,7 @@ def edit_switch(request, switch_id):
switch = Switch.objects.get(pk=switch_id) switch = Switch.objects.get(pk=switch_id)
except Switch.DoesNotExist: except Switch.DoesNotExist:
messages.error(request, u"Switch inexistant") messages.error(request, u"Switch inexistant")
return redirect("/topologie/") return redirect(reverse('topologie:index'))
switch_form = EditSwitchForm(request.POST or None, instance=switch) switch_form = EditSwitchForm(request.POST or None, instance=switch)
machine_form = EditMachineForm( machine_form = EditMachineForm(
request.POST or None, request.POST or None,
@ -466,7 +476,7 @@ def edit_switch(request, switch_id):
field for field in switch_form.changed_data) field for field in switch_form.changed_data)
) )
messages.success(request, "Le switch a bien été modifié") messages.success(request, "Le switch a bien été modifié")
return redirect("/topologie/") return redirect(reverse('topologie'))
i_mbf_param = generate_ipv4_mbf_param( interface_form, False ) i_mbf_param = generate_ipv4_mbf_param( interface_form, False )
return form({ return form({
'topoform': switch_form, 'topoform': switch_form,
@ -488,7 +498,7 @@ def new_room(request):
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Création") reversion.set_comment("Création")
messages.success(request, "La chambre a été créé") messages.success(request, "La chambre a été créé")
return redirect("/topologie/index_room/") return redirect(reverse('topologie:index-room'))
return form({'topoform': room}, 'topologie/topo.html', request) return form({'topoform': room}, 'topologie/topo.html', request)
@ -500,7 +510,7 @@ def edit_room(request, room_id):
room = Room.objects.get(pk=room_id) room = Room.objects.get(pk=room_id)
except Room.DoesNotExist: except Room.DoesNotExist:
messages.error(request, u"Chambre inexistante") messages.error(request, u"Chambre inexistante")
return redirect("/topologie/index_room/") return redirect(reverse('topologie:index-room'))
room = EditRoomForm(request.POST or None, instance=room) room = EditRoomForm(request.POST or None, instance=room)
if room.is_valid(): if room.is_valid():
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
@ -510,7 +520,7 @@ def edit_room(request, room_id):
field for field in room.changed_data) field for field in room.changed_data)
) )
messages.success(request, "La chambre a bien été modifiée") messages.success(request, "La chambre a bien été modifiée")
return redirect("/topologie/index_room/") return redirect(reverse('topologie:index-room'))
return form({'topoform': room}, 'topologie/topo.html', request) return form({'topoform': room}, 'topologie/topo.html', request)
@ -522,7 +532,7 @@ def del_room(request, room_id):
room = Room.objects.get(pk=room_id) room = Room.objects.get(pk=room_id)
except Room.DoesNotExist: except Room.DoesNotExist:
messages.error(request, u"Chambre inexistante") messages.error(request, u"Chambre inexistante")
return redirect("/topologie/index_room/") return redirect(reverse('topologie:index-room'))
if request.method == "POST": if request.method == "POST":
try: try:
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
@ -533,7 +543,7 @@ def del_room(request, room_id):
except ProtectedError: except ProtectedError:
messages.error(request, "La chambre %s est affectée à un autre objet,\ messages.error(request, "La chambre %s est affectée à un autre objet,\
impossible de la supprimer (switch ou user)" % room) impossible de la supprimer (switch ou user)" % room)
return redirect("/topologie/index_room/") return redirect(reverse('topologie:index-room'))
return form({ return form({
'objet': room, 'objet': room,
'objet_name': 'Chambre' 'objet_name': 'Chambre'

View file

@ -35,6 +35,7 @@ des whitelist, des services users et des écoles
from __future__ import unicode_literals from __future__ import unicode_literals
from django.urls import reverse
from django.shortcuts import get_object_or_404, render, redirect from django.shortcuts import get_object_or_404, render, redirect
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.contrib import messages from django.contrib import messages
@ -77,7 +78,10 @@ def password_change_action(u_form, user, request, req=False):
if req: if req:
req.delete() req.delete()
return redirect("/") return redirect("/")
return redirect("/users/profil/" + str(user.id)) return redirect(reverse(
'users:profil',
kwargs={'userid':str(user.id)}
))
@login_required @login_required
@ -95,7 +99,10 @@ def new_user(request):
user.reset_passwd_mail(request) user.reset_passwd_mail(request)
messages.success(request, "L'utilisateur %s a été crée, un mail\ messages.success(request, "L'utilisateur %s a été crée, un mail\
pour l'initialisation du mot de passe a été envoyé" % user.pseudo) pour l'initialisation du mot de passe a été envoyé" % user.pseudo)
return redirect("/users/profil/" + str(user.id)) return redirect(reverse(
'users:profil',
kwargs={'userid':str(user.id)}
))
return form({'userform': user}, 'users/user.html', request) return form({'userform': user}, 'users/user.html', request)
@ -114,7 +121,10 @@ def new_club(request):
club.reset_passwd_mail(request) club.reset_passwd_mail(request)
messages.success(request, "L'utilisateur %s a été crée, un mail\ messages.success(request, "L'utilisateur %s a été crée, un mail\
pour l'initialisation du mot de passe a été envoyé" % club.pseudo) pour l'initialisation du mot de passe a été envoyé" % club.pseudo)
return redirect("/users/profil/" + str(club.id)) return redirect(reverse(
'users:profil',
kwargs={'userid':str(club.id)}
))
return form({'userform': club}, 'users/user.html', request) return form({'userform': club}, 'users/user.html', request)
@ -145,11 +155,14 @@ def edit_info(request, userid):
user = User.objects.get(pk=userid) user = User.objects.get(pk=userid)
except User.DoesNotExist: except User.DoesNotExist:
messages.error(request, "Utilisateur inexistant") messages.error(request, "Utilisateur inexistant")
return redirect("/users/") return redirect(reverse('users:index'))
if not request.user.has_perms(('cableur',)) and user != request.user: if not request.user.has_perms(('cableur',)) and user != request.user:
messages.error(request, "Vous ne pouvez pas modifier un autre\ messages.error(request, "Vous ne pouvez pas modifier un autre\
user que vous sans droit cableur") user que vous sans droit cableur")
return redirect("/users/profil/" + str(request.user.id)) return redirect(reverse(
'users:profil',
kwargs={'userid':str(request.user.id)}
))
user = select_user_edit_form(request, user) user = select_user_edit_form(request, user)
if user.is_valid(): if user.is_valid():
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
@ -159,7 +172,10 @@ def edit_info(request, userid):
field for field in user.changed_data field for field in user.changed_data
)) ))
messages.success(request, "L'user a bien été modifié") messages.success(request, "L'user a bien été modifié")
return redirect("/users/profil/" + userid) return redirect(reverse(
'users:profil',
kwargs={'userid':str(userid)}
))
return form({'userform': user}, 'users/user.html', request) return form({'userform': user}, 'users/user.html', request)
@ -172,7 +188,7 @@ def state(request, userid):
user = User.objects.get(pk=userid) user = User.objects.get(pk=userid)
except User.DoesNotExist: except User.DoesNotExist:
messages.error(request, "Utilisateur inexistant") messages.error(request, "Utilisateur inexistant")
return redirect("/users/") return redirect(reverse('users:index'))
state = StateForm(request.POST or None, instance=user) state = StateForm(request.POST or None, instance=user)
if state.is_valid(): if state.is_valid():
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
@ -188,7 +204,10 @@ def state(request, userid):
)) ))
user.save() user.save()
messages.success(request, "Etat changé avec succès") messages.success(request, "Etat changé avec succès")
return redirect("/users/profil/" + userid) return redirect(reverse(
'users:profil',
kwargs={'userid':str(userid)}
))
return form({'userform': state}, 'users/user.html', request) return form({'userform': state}, 'users/user.html', request)
@ -201,16 +220,22 @@ def password(request, userid):
user = User.objects.get(pk=userid) user = User.objects.get(pk=userid)
except User.DoesNotExist: except User.DoesNotExist:
messages.error(request, "Utilisateur inexistant") messages.error(request, "Utilisateur inexistant")
return redirect("/users/") return redirect(reverse('users'))
if not request.user.has_perms(('cableur',)) and user != request.user: if not request.user.has_perms(('cableur',)) and user != request.user:
messages.error(request, "Vous ne pouvez pas modifier un\ messages.error(request, "Vous ne pouvez pas modifier un\
autre user que vous sans droit cableur") autre user que vous sans droit cableur")
return redirect("/users/profil/" + str(request.user.id)) return redirect(reverse(
'users:profil',
kwargs={'userid':str(request.user.id)}
))
if not request.user.has_perms(('bureau',)) and user != request.user\ if not request.user.has_perms(('bureau',)) and user != request.user\
and Right.objects.filter(user=user): and Right.objects.filter(user=user):
messages.error(request, "Il faut les droits bureau pour modifier le\ messages.error(request, "Il faut les droits bureau pour modifier le\
mot de passe d'un membre actif") mot de passe d'un membre actif")
return redirect("/users/profil/" + str(request.user.id)) return redirect(reverse(
'users:profil',
kwargs={'userid':str(request.user.id)}
))
u_form = PassForm(request.POST or None) u_form = PassForm(request.POST or None)
if u_form.is_valid(): if u_form.is_valid():
return password_change_action(u_form, user, request) return password_change_action(u_form, user, request)
@ -233,7 +258,7 @@ def new_serviceuser(request):
request, request,
"L'utilisateur %s a été crée" % user_object.pseudo "L'utilisateur %s a été crée" % user_object.pseudo
) )
return redirect("/users/index_serviceusers/") return redirect(reverse('users:index-serviceusers'))
return form({'userform': user}, 'users/user.html', request) return form({'userform': user}, 'users/user.html', request)
@ -247,7 +272,7 @@ def edit_serviceuser(request, userid):
user = ServiceUser.objects.get(pk=userid) user = ServiceUser.objects.get(pk=userid)
except ServiceUser.DoesNotExist: except ServiceUser.DoesNotExist:
messages.error(request, "Utilisateur inexistant") messages.error(request, "Utilisateur inexistant")
return redirect("/users/") return redirect(reverse('users:index'))
user = EditServiceUserForm(request.POST or None, instance=user) user = EditServiceUserForm(request.POST or None, instance=user)
if user.is_valid(): if user.is_valid():
user_object = user.save(commit=False) user_object = user.save(commit=False)
@ -260,7 +285,7 @@ def edit_serviceuser(request, userid):
field for field in user.changed_data field for field in user.changed_data
)) ))
messages.success(request, "L'user a bien été modifié") messages.success(request, "L'user a bien été modifié")
return redirect("/users/index_serviceusers") return redirect(reverse('users:index-serviceusers'))
return form({'userform': user}, 'users/user.html', request) return form({'userform': user}, 'users/user.html', request)
@ -272,13 +297,13 @@ def del_serviceuser(request, userid):
user = ServiceUser.objects.get(pk=userid) user = ServiceUser.objects.get(pk=userid)
except ServiceUser.DoesNotExist: except ServiceUser.DoesNotExist:
messages.error(request, u"Utilisateur inexistant") messages.error(request, u"Utilisateur inexistant")
return redirect("/users/") return redirect(reverse('users:index'))
if request.method == "POST": if request.method == "POST":
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
user.delete() user.delete()
reversion.set_user(request.user) reversion.set_user(request.user)
messages.success(request, "L'user a été détruite") messages.success(request, "L'user a été détruite")
return redirect("/users/index_serviceusers/") return redirect(reverse('users:index-serviceusers'))
return form( return form(
{'objet': user, 'objet_name': 'serviceuser'}, {'objet': user, 'objet_name': 'serviceuser'},
'users/delete.html', 'users/delete.html',
@ -294,7 +319,7 @@ def add_right(request, userid):
user = User.objects.get(pk=userid) user = User.objects.get(pk=userid)
except User.DoesNotExist: except User.DoesNotExist:
messages.error(request, "Utilisateur inexistant") messages.error(request, "Utilisateur inexistant")
return redirect("/users/") return redirect(reverse('users:index'))
right = RightForm(request.POST or None) right = RightForm(request.POST or None)
if right.is_valid(): if right.is_valid():
right = right.save(commit=False) right = right.save(commit=False)
@ -307,7 +332,10 @@ def add_right(request, userid):
messages.success(request, "Droit ajouté") messages.success(request, "Droit ajouté")
except IntegrityError: except IntegrityError:
pass pass
return redirect("/users/profil/" + userid) return redirect(reverse(
'users:profil',
kwargs={'userid':str(userid)}
))
return form({'userform': right}, 'users/user.html', request) return form({'userform': right}, 'users/user.html', request)
@ -328,7 +356,7 @@ def del_right(request):
)) ))
right_del.delete() right_del.delete()
messages.success(request, "Droit retiré avec succès") messages.success(request, "Droit retiré avec succès")
return redirect("/users/") return redirect(reverse('users:index'))
return form({'userform': user_right_list}, 'users/del_right.html', request) return form({'userform': user_right_list}, 'users/del_right.html', request)
@ -342,7 +370,7 @@ def add_ban(request, userid):
user = User.objects.get(pk=userid) user = User.objects.get(pk=userid)
except User.DoesNotExist: except User.DoesNotExist:
messages.error(request, "Utilisateur inexistant") messages.error(request, "Utilisateur inexistant")
return redirect("/users/") return redirect(reverse('users:index'))
ban_instance = Ban(user=user) ban_instance = Ban(user=user)
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():
@ -351,7 +379,10 @@ def add_ban(request, userid):
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Création") reversion.set_comment("Création")
messages.success(request, "Bannissement ajouté") messages.success(request, "Bannissement ajouté")
return redirect("/users/profil/" + userid) return redirect(reverse(
'users:profil',
kwargs={'userid':str(userid)}
))
if user.is_ban: if user.is_ban:
messages.error( messages.error(
request, request,
@ -370,7 +401,7 @@ def edit_ban(request, banid):
ban_instance = Ban.objects.get(pk=banid) ban_instance = Ban.objects.get(pk=banid)
except Ban.DoesNotExist: except Ban.DoesNotExist:
messages.error(request, "Entrée inexistante") messages.error(request, "Entrée inexistante")
return redirect("/users/") return redirect(reverse('users:index'))
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():
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
@ -380,7 +411,7 @@ def edit_ban(request, banid):
field for field in ban.changed_data field for field in ban.changed_data
)) ))
messages.success(request, "Bannissement modifié") messages.success(request, "Bannissement modifié")
return redirect("/users/") return redirect(reverse('users:index'))
return form({'userform': ban}, 'users/user.html', request) return form({'userform': ban}, 'users/user.html', request)
@ -395,7 +426,7 @@ def add_whitelist(request, userid):
user = User.objects.get(pk=userid) user = User.objects.get(pk=userid)
except User.DoesNotExist: except User.DoesNotExist:
messages.error(request, "Utilisateur inexistant") messages.error(request, "Utilisateur inexistant")
return redirect("/users/") return redirect(reverse('users:index'))
whitelist_instance = Whitelist(user=user) whitelist_instance = Whitelist(user=user)
whitelist = WhitelistForm( whitelist = WhitelistForm(
request.POST or None, request.POST or None,
@ -407,7 +438,10 @@ def add_whitelist(request, userid):
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Création") reversion.set_comment("Création")
messages.success(request, "Accès à titre gracieux accordé") messages.success(request, "Accès à titre gracieux accordé")
return redirect("/users/profil/" + userid) return redirect(reverse(
'users:profil',
kwargs={'userid':str(userid)}
))
if user.is_whitelisted: if user.is_whitelisted:
messages.error( messages.error(
request, request,
@ -427,7 +461,7 @@ def edit_whitelist(request, whitelistid):
whitelist_instance = Whitelist.objects.get(pk=whitelistid) whitelist_instance = Whitelist.objects.get(pk=whitelistid)
except Whitelist.DoesNotExist: except Whitelist.DoesNotExist:
messages.error(request, "Entrée inexistante") messages.error(request, "Entrée inexistante")
return redirect("/users/") return redirect(reverse('users:index'))
whitelist = WhitelistForm( whitelist = WhitelistForm(
request.POST or None, request.POST or None,
instance=whitelist_instance instance=whitelist_instance
@ -440,7 +474,7 @@ def edit_whitelist(request, whitelistid):
field for field in whitelist.changed_data field for field in whitelist.changed_data
)) ))
messages.success(request, "Whitelist modifiée") messages.success(request, "Whitelist modifiée")
return redirect("/users/") return redirect(reverse('users:index'))
return form({'userform': whitelist}, 'users/user.html', request) return form({'userform': whitelist}, 'users/user.html', request)
@ -456,7 +490,7 @@ def add_school(request):
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Création") reversion.set_comment("Création")
messages.success(request, "L'établissement a été ajouté") messages.success(request, "L'établissement a été ajouté")
return redirect("/users/index_school/") return redirect(reverse('users:index-school'))
return form({'userform': school}, 'users/user.html', request) return form({'userform': school}, 'users/user.html', request)
@ -469,7 +503,7 @@ def edit_school(request, schoolid):
school_instance = School.objects.get(pk=schoolid) school_instance = School.objects.get(pk=schoolid)
except School.DoesNotExist: except School.DoesNotExist:
messages.error(request, u"Entrée inexistante") messages.error(request, u"Entrée inexistante")
return redirect("/users/") return redirect(reverse('users:index'))
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():
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
@ -479,7 +513,7 @@ def edit_school(request, schoolid):
field for field in school.changed_data field for field in school.changed_data
)) ))
messages.success(request, "Établissement modifié") messages.success(request, "Établissement modifié")
return redirect("/users/index_school/") return redirect(reverse('users:index-school'))
return form({'userform': school}, 'users/user.html', request) return form({'userform': school}, 'users/user.html', request)
@ -504,7 +538,7 @@ def del_school(request):
request, request,
"L'établissement %s est affecté à au moins un user, \ "L'établissement %s est affecté à au moins un user, \
vous ne pouvez pas le supprimer" % school_del) vous ne pouvez pas le supprimer" % school_del)
return redirect("/users/index_school/") return redirect(reverse('users:index-school'))
return form({'userform': school}, 'users/user.html', request) return form({'userform': school}, 'users/user.html', request)
@ -520,7 +554,7 @@ def add_listright(request):
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Création") reversion.set_comment("Création")
messages.success(request, "Le droit/groupe a été ajouté") messages.success(request, "Le droit/groupe a été ajouté")
return redirect("/users/index_listright/") return redirect(reverse('users:index-listright'))
return form({'userform': listright}, 'users/user.html', request) return form({'userform': listright}, 'users/user.html', request)
@ -533,7 +567,7 @@ def edit_listright(request, listrightid):
listright_instance = ListRight.objects.get(pk=listrightid) listright_instance = ListRight.objects.get(pk=listrightid)
except ListRight.DoesNotExist: except ListRight.DoesNotExist:
messages.error(request, u"Entrée inexistante") messages.error(request, u"Entrée inexistante")
return redirect("/users/") return redirect(reverse('users:index'))
listright = ListRightForm( listright = ListRightForm(
request.POST or None, request.POST or None,
instance=listright_instance instance=listright_instance
@ -546,7 +580,7 @@ def edit_listright(request, listrightid):
field for field in listright.changed_data field for field in listright.changed_data
)) ))
messages.success(request, "Droit modifié") messages.success(request, "Droit modifié")
return redirect("/users/index_listright/") return redirect(reverse('users:index-listright'))
return form({'userform': listright}, 'users/user.html', request) return form({'userform': listright}, 'users/user.html', request)
@ -569,7 +603,7 @@ def del_listright(request):
request, request,
"L'établissement %s est affecté à au moins un user, \ "L'établissement %s est affecté à au moins un user, \
vous ne pouvez pas le supprimer" % listright_del) vous ne pouvez pas le supprimer" % listright_del)
return redirect("/users/index_listright/") return redirect(reverse('users:index-listright'))
return form({'userform': listright}, 'users/user.html', request) return form({'userform': listright}, 'users/user.html', request)
@ -595,7 +629,7 @@ def mass_archive(request):
messages.success(request, "%s users ont été archivés" % len( messages.success(request, "%s users ont été archivés" % len(
to_archive_list to_archive_list
)) ))
return redirect("/users/") return redirect(reverse('users:index'))
return form( return form(
{'userform': to_archive_date, 'to_archive_list': to_archive_list}, {'userform': to_archive_date, 'to_archive_list': to_archive_list},
'users/mass_archive.html', 'users/mass_archive.html',
@ -760,55 +794,64 @@ def history(request, object_name, object_id):
object_instance = User.objects.get(pk=object_id) object_instance = User.objects.get(pk=object_id)
except User.DoesNotExist: except User.DoesNotExist:
messages.error(request, "Utilisateur inexistant") messages.error(request, "Utilisateur inexistant")
return redirect("/users/") return redirect(reverse('users:index'))
if not request.user.has_perms(('cableur',)) and\ if not request.user.has_perms(('cableur',)) and\
object_instance != request.user: object_instance != request.user:
messages.error(request, "Vous ne pouvez pas afficher\ messages.error(request, "Vous ne pouvez pas afficher\
l'historique d'un autre user que vous sans droit cableur") l'historique d'un autre user que vous sans droit cableur")
return redirect("/users/profil/" + str(request.user.id)) return redirect(reverse(
'users:profil',
kwargs={'userid':str(request.user.id)}
))
elif object_name == 'serviceuser' and request.user.has_perms(('cableur',)): elif object_name == 'serviceuser' and request.user.has_perms(('cableur',)):
try: try:
object_instance = ServiceUser.objects.get(pk=object_id) object_instance = ServiceUser.objects.get(pk=object_id)
except ServiceUser.DoesNotExist: except ServiceUser.DoesNotExist:
messages.error(request, "User service inexistant") messages.error(request, "User service inexistant")
return redirect("/users/") return redirect(reverse('users:index'))
elif object_name == 'ban': elif object_name == 'ban':
try: try:
object_instance = Ban.objects.get(pk=object_id) object_instance = Ban.objects.get(pk=object_id)
except Ban.DoesNotExist: except Ban.DoesNotExist:
messages.error(request, "Bannissement inexistant") messages.error(request, "Bannissement inexistant")
return redirect("/users/") return redirect(reverse('users:index'))
if not request.user.has_perms(('cableur',)) and\ if not request.user.has_perms(('cableur',)) and\
object_instance.user != request.user: object_instance.user != request.user:
messages.error(request, "Vous ne pouvez pas afficher les bans\ messages.error(request, "Vous ne pouvez pas afficher les bans\
d'un autre user que vous sans droit cableur") d'un autre user que vous sans droit cableur")
return redirect("/users/profil/" + str(request.user.id)) return redirect(reverse(
'users:profil',
kwargs={'userid':str(request.user.id)}
))
elif object_name == 'whitelist': elif object_name == 'whitelist':
try: try:
object_instance = Whitelist.objects.get(pk=object_id) object_instance = Whitelist.objects.get(pk=object_id)
except Whitelist.DoesNotExist: except Whitelist.DoesNotExist:
messages.error(request, "Whitelist inexistant") messages.error(request, "Whitelist inexistant")
return redirect("/users/") return redirect(reverse('users:index'))
if not request.user.has_perms(('cableur',)) and\ if not request.user.has_perms(('cableur',)) and\
object_instance.user != request.user: object_instance.user != request.user:
messages.error(request, "Vous ne pouvez pas afficher les\ messages.error(request, "Vous ne pouvez pas afficher les\
whitelist d'un autre user que vous sans droit cableur") whitelist d'un autre user que vous sans droit cableur")
return redirect("/users/profil/" + str(request.user.id)) return redirect(reverse(
'users:profil',
kwargs={'userid':str(request.user.id)}
))
elif object_name == 'school' and request.user.has_perms(('cableur',)): elif object_name == 'school' and request.user.has_perms(('cableur',)):
try: try:
object_instance = School.objects.get(pk=object_id) object_instance = School.objects.get(pk=object_id)
except School.DoesNotExist: except School.DoesNotExist:
messages.error(request, "Ecole inexistante") messages.error(request, "Ecole inexistante")
return redirect("/users/") return redirect(reverse('users:index'))
elif object_name == 'listright' and request.user.has_perms(('cableur',)): elif object_name == 'listright' and request.user.has_perms(('cableur',)):
try: try:
object_instance = ListRight.objects.get(pk=object_id) object_instance = ListRight.objects.get(pk=object_id)
except ListRight.DoesNotExist: except ListRight.DoesNotExist:
messages.error(request, "Droit inexistant") messages.error(request, "Droit inexistant")
return redirect("/users/") return redirect(reverse('users:index'))
else: else:
messages.error(request, "Objet inconnu") messages.error(request, "Objet inconnu")
return redirect("/users/") return redirect(reverse('users:index'))
options, _created = GeneralOption.objects.get_or_create() options, _created = GeneralOption.objects.get_or_create()
pagination_number = options.pagination_number pagination_number = options.pagination_number
reversions = Version.objects.get_for_object(object_instance) reversions = Version.objects.get_for_object(object_instance)
@ -832,7 +875,10 @@ def history(request, object_name, object_id):
@login_required @login_required
def mon_profil(request): def mon_profil(request):
""" Lien vers profil, renvoie request.id à la fonction """ """ Lien vers profil, renvoie request.id à la fonction """
return redirect("/users/profil/" + str(request.user.id)) return redirect(reverse(
'users:profil',
kwargs={'userid':str(request.user.id)}
))
@login_required @login_required
@ -842,11 +888,14 @@ def profil(request, userid):
users = User.objects.get(pk=userid) users = User.objects.get(pk=userid)
except User.DoesNotExist: except User.DoesNotExist:
messages.error(request, "Utilisateur inexistant") messages.error(request, "Utilisateur inexistant")
return redirect("/users/") return redirect(reverse('users:index'))
if not request.user.has_perms(('cableur',)) and users != request.user: if not request.user.has_perms(('cableur',)) and users != request.user:
messages.error(request, "Vous ne pouvez pas afficher un autre user\ messages.error(request, "Vous ne pouvez pas afficher un autre user\
que vous sans droit cableur") que vous sans droit cableur")
return redirect("/users/profil/" + str(request.user.id)) return redirect(reverse(
'users:profil',
kwargs={'userid':str(request.user.id)}
))
machines = Machine.objects.filter(user=users).select_related('user')\ machines = Machine.objects.filter(user=users).select_related('user')\
.prefetch_related('interface_set__domain__extension')\ .prefetch_related('interface_set__domain__extension')\
.prefetch_related('interface_set__ipv4__ip_type__extension')\ .prefetch_related('interface_set__ipv4__ip_type__extension')\