From d3f07cf63aa644bb829c42ca5ca5f8dd6d25dcfe Mon Sep 17 00:00:00 2001 From: FERNET Laouen Date: Sun, 7 Jan 2018 20:29:43 +0100 Subject: [PATCH] removes hard-coded urls, calls reverse. Fix issue #63 --- preferences/views.py | 2 +- re2o/urls.py | 2 +- topologie/views.py | 19 +++++++++++-------- users/views.py | 6 +++--- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/preferences/views.py b/preferences/views.py index 45324f53..7660a7ef 100644 --- a/preferences/views.py +++ b/preferences/views.py @@ -90,7 +90,7 @@ def edit_options(request, section): if not can: messages.error(request, msg or "Vous ne pouvez pas éditer cette\ option.") - return redirect('/') + return redirect(reverse('index')) options = form_instance( request.POST or None, instance=options_instance diff --git a/re2o/urls.py b/re2o/urls.py index 775b87ec..00e658a3 100644 --- a/re2o/urls.py +++ b/re2o/urls.py @@ -43,7 +43,7 @@ from django.contrib.auth import views as auth_views from .views import index urlpatterns = [ - url(r'^$', index), + url(r'^$', index, name='index'), url('^logout/', auth_views.logout, {'next_page': '/'}), url('^', include('django.contrib.auth.urls')), url(r'^admin/', include(admin.site.urls)), diff --git a/topologie/views.py b/topologie/views.py index 25cc8aa2..c9f3c49f 100644 --- a/topologie/views.py +++ b/topologie/views.py @@ -416,7 +416,7 @@ def create_ports(request, switch_id): switch = Switch.objects.get(pk=switch_id) except Switch.DoesNotExist: messages.error(request, u"Switch inexistant") - return redirect("/topologie/") + return redirect(reverse('topologie:index')) s_begin = s_end = 0 nb_ports = switch.ports.count() @@ -439,7 +439,10 @@ def create_ports(request, switch_id): except ValidationError as e: messages.error(request, ''.join(e)) - return redirect("/topologie/switch/" + str(switch.id)) + return redirect(reverse( + 'topologie:index-port', + kwargs={'switch_id':switch_id} + )) return form({'id_switch': switch_id, 'topoform': port_form}, 'topologie/switch.html', request) @@ -573,7 +576,7 @@ def new_model_switch(request): reversion.set_user(request.user) reversion.set_comment("Création") messages.success(request, "Le modèle a été créé") - return redirect("/topologie/index_model_switch/") + return redirect(reverse('topologie:index-model-switch')) return form({'topoform': model_switch}, 'topologie/topo.html', request) @@ -591,7 +594,7 @@ def edit_model_switch(request, model_switch, model_switch_id): field for field in model_switch.changed_data) ) messages.success(request, "Le modèle a bien été modifié") - return redirect("/topologie/index_model_switch/") + return redirect(reverse('topologie:index-model-switch')) return form({'topoform': model_switch}, 'topologie/topo.html', request) @@ -609,7 +612,7 @@ def del_model_switch(request, model_switch_id): except ProtectedError: messages.error(request, "Le modèle %s est affectée à un autre objet,\ impossible de la supprimer (switch ou user)" % model_switch) - return redirect("/topologie/index_model_switch/") + return redirect(reverse('topologie:index-model-switch')) return form({ 'objet': model_switch, 'objet_name': 'Modèle de switch' @@ -627,7 +630,7 @@ def new_constructor_switch(request): reversion.set_user(request.user) reversion.set_comment("Création") messages.success(request, "Le constructeur a été créé") - return redirect("/topologie/index_model_switch/") + return redirect(reverse('topologie:index-model-switch')) return form({'topoform': constructor_switch}, 'topologie/topo.html', request) @@ -645,7 +648,7 @@ def edit_constructor_switch(request, constructor_switch, constructor_switch_id): field for field in constructor_switch.changed_data) ) messages.success(request, "Le modèle a bien été modifié") - return redirect("/topologie/index_model_switch/") + return redirect(reverse('topologie:index-model-switch')) return form({'topoform': constructor_switch}, 'topologie/topo.html', request) @@ -663,7 +666,7 @@ def del_constructor_switch(request, constructor_switch_id): except ProtectedError: messages.error(request, "Le constructeur %s est affecté à un autre objet,\ impossible de la supprimer (switch ou user)" % constructor_switch) - return redirect("/topologie/index_model_switch/") + return redirect(reverse('topologie:index-model-switch')) return form({ 'objet': constructor_switch, 'objet_name': 'Constructeur de switch' diff --git a/users/views.py b/users/views.py index 600c472e..fbdbc73b 100644 --- a/users/views.py +++ b/users/views.py @@ -111,7 +111,7 @@ def password_change_action(u_form, user, request, req=False): messages.success(request, "Le mot de passe a changé") if req: req.delete() - return redirect("/") + return redirect(reverse('index')) return redirect(reverse( 'users:profil', kwargs={'userid':str(user.id)} @@ -809,7 +809,7 @@ def reset_password(request): user.reset_passwd_mail(request) messages.success(request, "Un mail pour l'initialisation du mot\ de passe a été envoyé") - redirect("/") + redirect(reverse('index')) return form({'userform': userform}, 'users/user.html', request) @@ -822,7 +822,7 @@ def process(request, token): return process_passwd(request, req) else: messages.error(request, "Entrée incorrecte, contactez un admin") - redirect("/") + redirect(reverse('index')) def process_passwd(request, req):