mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-27 07:02:26 +00:00
Redirection constante vers la page utilisateur en cas d'erreur et nommage consistant des paramètres
This commit is contained in:
parent
ec62e4568b
commit
cf642bad08
2 changed files with 6 additions and 16 deletions
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue