mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-26 22:52: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
db6c11075f
commit
74d93c5219
2 changed files with 6 additions and 16 deletions
|
@ -81,14 +81,15 @@ def can_edit(model):
|
||||||
instance = model.get_instance(*args, **kwargs)
|
instance = model.get_instance(*args, **kwargs)
|
||||||
except model.DoesNotExist:
|
except model.DoesNotExist:
|
||||||
messages.error(request, u"Entrée inexistante")
|
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):
|
if not model.can_edit(instance, request.user):
|
||||||
messages.error(request, "Vous ne pouvez pas accéder à ce menu")
|
messages.error(request, "Vous ne pouvez pas accéder à ce menu")
|
||||||
return redirect(reverse('users:profil',
|
return redirect(reverse('users:profil',
|
||||||
kwargs={'userid':str(request.user.id)}
|
kwargs={'userid':str(request.user.id)}
|
||||||
))
|
))
|
||||||
kwargs['instance'] = instance
|
return view(request, instance, *args, **kwargs)
|
||||||
return view(request, *args, **kwargs)
|
|
||||||
return wrapper
|
return wrapper
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
|
|
@ -204,22 +204,11 @@ def select_user_edit_form(request, user):
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@can_edit(User)
|
@can_edit(User)
|
||||||
def edit_info(request, userid, instance):
|
def edit_info(request, user, userid):
|
||||||
""" Edite un utilisateur à partir de son id,
|
""" Edite un utilisateur à partir de son id,
|
||||||
si l'id est différent de request.user, vérifie la
|
si l'id est différent de request.user, vérifie la
|
||||||
possession du droit cableur """
|
possession du droit cableur """
|
||||||
# try:
|
user = select_user_edit_form(request, user)
|
||||||
# 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)
|
|
||||||
if user.is_valid():
|
if user.is_valid():
|
||||||
with transaction.atomic(), reversion.create_revision():
|
with transaction.atomic(), reversion.create_revision():
|
||||||
user.save()
|
user.save()
|
||||||
|
|
Loading…
Reference in a new issue