From e4f916cf19edf71dd88867983a5cbbd8d1cfcc70 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Fri, 8 Jul 2016 02:25:12 +0200 Subject: [PATCH] =?UTF-8?q?Modification=20et=20affichage=20de=20la=20liste?= =?UTF-8?q?=20des=20=C3=A9coles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- users/models.py | 2 +- users/templates/users/aff_schools.html | 15 +++++++++++++++ users/templates/users/index_schools.html | 15 +++++++++++++++ users/templates/users/sidebar.html | 3 +-- users/urls.py | 2 ++ users/views.py | 23 ++++++++++++++++++++--- 6 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 users/templates/users/aff_schools.html create mode 100644 users/templates/users/index_schools.html diff --git a/users/models.py b/users/models.py index c12def82..f5f05faa 100644 --- a/users/models.py +++ b/users/models.py @@ -133,7 +133,7 @@ class SchoolForm(ModelForm): def __init__(self, *args, **kwargs): super(SchoolForm, self).__init__(*args, **kwargs) - self.fields['name'].label = 'Établissement à ajouter' + self.fields['name'].label = 'Établissement' class DelSchoolForm(ModelForm): schools = forms.ModelMultipleChoiceField(queryset=School.objects.all(), label="Etablissements actuels", widget=forms.CheckboxSelectMultiple) diff --git a/users/templates/users/aff_schools.html b/users/templates/users/aff_schools.html new file mode 100644 index 00000000..0f9f73b5 --- /dev/null +++ b/users/templates/users/aff_schools.html @@ -0,0 +1,15 @@ + + + + + + + + {% for school in school_list %} + + + + + {% endfor %} +
Etablissement
{{ school.name }} Editer
+ diff --git a/users/templates/users/index_schools.html b/users/templates/users/index_schools.html new file mode 100644 index 00000000..eaf63414 --- /dev/null +++ b/users/templates/users/index_schools.html @@ -0,0 +1,15 @@ +{% extends "users/sidebar.html" %} +{% load bootstrap3 %} + +{% block title %}Utilisateurs{% endblock %} + +{% block content %} +

Liste des Établissements

+ Ajouter un établissement + Supprimer un ou plusieurs établissements + {% include "users/aff_schools.html" with school_list=school_list %} +
+
+
+{% endblock %} + diff --git a/users/templates/users/sidebar.html b/users/templates/users/sidebar.html index d4d34a19..ba691ab6 100644 --- a/users/templates/users/sidebar.html +++ b/users/templates/users/sidebar.html @@ -5,7 +5,6 @@

Liste des adhérents

Liste des bannissements

Liste des accès à titre gracieux

-

Ajouter un établissement

-

Supprimer un établissement

+

Liste des établissements

Retirer un droit rezo

{% endblock %} diff --git a/users/urls.py b/users/urls.py index 616f3a88..af744278 100644 --- a/users/urls.py +++ b/users/urls.py @@ -14,10 +14,12 @@ urlpatterns = [ url(r'^add_right/(?P[0-9]+)$', views.add_right, name='add-right'), url(r'^del_right/$', views.del_right, name='del-right'), url(r'^add_school/$', views.add_school, name='add-school'), + url(r'^edit_school/(?P[0-9]+)$', views.edit_school, name='edit-school'), url(r'^del_school/$', views.del_school, name='del-school'), url(r'^profil/(?P[0-9]+)$', views.profil, name='profil'), url(r'^index_ban/$', views.index_ban, name='index-ban'), url(r'^index_white/$', views.index_white, name='index-white'), + url(r'^index_school/$', views.index_school, name='index-school'), url(r'^$', views.index, name='index'), ] diff --git a/users/views.py b/users/views.py index bbd431fe..97e89361 100644 --- a/users/views.py +++ b/users/views.py @@ -10,7 +10,7 @@ from django.db.models import Max, ProtectedError from django.db import IntegrityError from django.utils import timezone -from users.models import User, Right, Ban, DelRightForm, UserForm, InfoForm, PasswordForm, StateForm, RightForm, BanForm, ProfilForm, Whitelist, WhitelistForm, DelSchoolForm, SchoolForm +from users.models import User, Right, Ban, DelRightForm, UserForm, InfoForm, PasswordForm, StateForm, RightForm, BanForm, ProfilForm, Whitelist, WhitelistForm, DelSchoolForm, SchoolForm, School from cotisations.models import Facture from machines.models import Machine, Interface from users.forms import PassForm @@ -222,9 +222,22 @@ def add_school(request): if school.is_valid(): school.save() messages.success(request, "L'établissement a été ajouté") - return redirect("/users/") + return redirect("/users/index_school/") return form({'userform': school}, 'users/user.html', request) +def edit_school(request, schoolid): + try: + school_instance = School.objects.get(pk=schoolid) + except School.DoesNotExist: + messages.error(request, u"Entrée inexistante" ) + return redirect("/users/") + school = SchoolForm(request.POST or None, instance=school_instance) + if school.is_valid(): + school.save() + messages.success(request, "Établissement modifié") + return redirect("/users/index_school/") + return form({'userform': school}, 'users/user.html', request) + def del_school(request): school = DelSchoolForm(request.POST or None) if school.is_valid(): @@ -235,7 +248,7 @@ def del_school(request): messages.success(request, "L'établissement a été supprimé") except ProtectedError: messages.error(request, "L'établissement %s est affecté à au moins un user, vous ne pouvez pas le supprimer" % school_del) - return redirect("/users/") + return redirect("/users/index_school/") return form({'userform': school}, 'users/user.html', request) def index(request): @@ -258,6 +271,10 @@ def index_white(request): white_list = Whitelist.objects.order_by('date_start') return render(request, 'users/index_whitelist.html', {'white_list':white_list}) +def index_school(request): + school_list = School.objects.order_by('name') + return render(request, 'users/index_schools.html', {'school_list':school_list}) + def profil(request, userid): try: users = User.objects.get(pk=userid)