Commit cf642bad authored by LEVY-FALK Hugo's avatar LEVY-FALK Hugo Committed by root

Redirection constante vers la page utilisateur en cas d'erreur et nommage consistant des paramètres

parent ec62e456
......@@ -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
......
......@@ -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()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment