diff --git a/users/urls.py b/users/urls.py index 31f97abd..9e435547 100644 --- a/users/urls.py +++ b/users/urls.py @@ -7,6 +7,8 @@ urlpatterns = [ url(r'^edit_info/(?P[0-9]+)$', views.edit_info, name='edit-info'), url(r'^state/(?P[0-9]+)$', views.state, name='state'), url(r'^password/(?P[0-9]+)$', views.password, name='password'), + url(r'^add_ban/(?P[0-9]+)$', views.add_ban, name='add-ban'), + url(r'^edit_ban/(?P[0-9]+)$', views.edit_ban, name='edit-ban'), url(r'^add_right/$', views.add_right, name='add-right'), url(r'^del_right/$', views.del_right, name='del-right'), url(r'^$', views.index, name='index'), diff --git a/users/views.py b/users/views.py index b20c9a97..db53acda 100644 --- a/users/views.py +++ b/users/views.py @@ -7,7 +7,7 @@ from django.core.context_processors import csrf from django.template import Context, RequestContext, loader from django.contrib import messages -from users.models import User, Right, DelRightForm, UserForm, InfoForm, PasswordForm, StateForm, RightForm +from users.models import User, Right, Ban, DelRightForm, UserForm, InfoForm, PasswordForm, StateForm, RightForm, BanForm from users.forms import PassForm from re2o.login import makeSecret, hashNT @@ -86,6 +86,33 @@ def del_right(request): return redirect("/users/") return form({'userform': right}, 'users/user.html', request) +def add_ban(request, userid): + try: + user = User.objects.get(pk=userid) + except User.DoesNotExist: + messages.error(request, u"Utilisateur inexistant" ) + return redirect("/users/") + ban_instance = Ban(user=user) + ban = BanForm(request.POST or None, instance=ban_instance) + if ban.is_valid(): + ban.save() + messages.success(request, "Bannissement ajouté") + return redirect("/users/") + return form({'userform': ban}, 'users/user.html', request) + +def edit_ban(request, banid): + try: + ban_instance = Ban.objects.get(pk=banid) + except User.DoesNotExist: + messages.error(request, u"Entrée inexistante" ) + return redirect("/users/") + ban = BanForm(request.POST or None, instance=ban_instance) + if ban.is_valid(): + ban.save() + messages.success(request, "Bannissement modifié") + return redirect("/users/") + return form({'userform': ban}, 'users/user.html', request) + def index(request): users_list = User.objects.order_by('pk') return render(request, 'users/index.html', {'users_list': users_list})