From cf642bad082de528ea32decb1b1abde3feefab76 Mon Sep 17 00:00:00 2001 From: LEVY-FALK Hugo Date: Thu, 30 Nov 2017 13:52:33 +0100 Subject: [PATCH] =?UTF-8?q?Redirection=20constante=20vers=20la=20page=20ut?= =?UTF-8?q?ilisateur=20en=20cas=20d'erreur=20et=20nommage=20consistant=20d?= =?UTF-8?q?es=20param=C3=A8tres?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- re2o/utils.py | 7 ++++--- users/views.py | 15 ++------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/re2o/utils.py b/re2o/utils.py index f350b4d1..91145d2a 100644 --- a/re2o/utils.py +++ b/re2o/utils.py @@ -81,14 +81,15 @@ def can_edit(model): instance = model.get_instance(*args, **kwargs) except model.DoesNotExist: messages.error(request, u"Entrée inexistante") - return redirect(reverse('users:index')) + return redirect(reverse('users:profil', + kwargs={'userid':str(request.user.id)} + )) if not model.can_edit(instance, request.user): messages.error(request, "Vous ne pouvez pas accéder à ce menu") return redirect(reverse('users:profil', kwargs={'userid':str(request.user.id)} )) - kwargs['instance'] = instance - return view(request, *args, **kwargs) + return view(request, instance, *args, **kwargs) return wrapper return decorator diff --git a/users/views.py b/users/views.py index 3eeefcc1..9036ab0a 100644 --- a/users/views.py +++ b/users/views.py @@ -204,22 +204,11 @@ def select_user_edit_form(request, user): @login_required @can_edit(User) -def edit_info(request, userid, instance): +def edit_info(request, user, userid): """ Edite un utilisateur à partir de son id, si l'id est différent de request.user, vérifie la possession du droit cableur """ - # try: - # user = User.objects.get(pk=userid) - # except User.DoesNotExist: - # messages.error(request, "Utilisateur inexistant") - # return redirect(reverse('users:index')) - # if not user.can_edit(request.user): - # messages.error(request, "Vous ne pouvez pas accéder à ce menu") - # return redirect(reverse( - # 'users:profil', - # kwargs={'userid':str(request.user.id)} - # )) - user = select_user_edit_form(request, instance) + user = select_user_edit_form(request, user) if user.is_valid(): with transaction.atomic(), reversion.create_revision(): user.save()