From 387515d410bc404cdcdcc85a69075a293f47f3d4 Mon Sep 17 00:00:00 2001 From: chirac Date: Wed, 6 Jul 2016 19:45:36 +0200 Subject: [PATCH] =?UTF-8?q?Vue=20pour=20g=C3=A9rer=20la=20liste=20des=20?= =?UTF-8?q?=C3=A9coles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- topologie/migrations/0013_port_related.py | 19 ++++++++++++++ .../migrations/0014_auto_20160706_1238.py | 26 +++++++++++++++++++ .../migrations/0015_auto_20160706_1452.py | 23 ++++++++++++++++ .../migrations/0016_auto_20160706_1531.py | 23 ++++++++++++++++ users/models.py | 11 ++++++++ users/templates/users/sidebar.html | 2 ++ users/urls.py | 2 ++ users/views.py | 25 ++++++++++++++++-- 8 files changed, 129 insertions(+), 2 deletions(-) create mode 100644 topologie/migrations/0013_port_related.py create mode 100644 topologie/migrations/0014_auto_20160706_1238.py create mode 100644 topologie/migrations/0015_auto_20160706_1452.py create mode 100644 topologie/migrations/0016_auto_20160706_1531.py diff --git a/topologie/migrations/0013_port_related.py b/topologie/migrations/0013_port_related.py new file mode 100644 index 00000000..afce7dce --- /dev/null +++ b/topologie/migrations/0013_port_related.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('topologie', '0012_port_machine_interface'), + ] + + operations = [ + migrations.AddField( + model_name='port', + name='related', + field=models.OneToOneField(null=True, to='topologie.Port', blank=True, related_name='related_port'), + ), + ] diff --git a/topologie/migrations/0014_auto_20160706_1238.py b/topologie/migrations/0014_auto_20160706_1238.py new file mode 100644 index 00000000..3be29e79 --- /dev/null +++ b/topologie/migrations/0014_auto_20160706_1238.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('topologie', '0013_port_related'), + ] + + operations = [ + migrations.AlterUniqueTogether( + name='port', + unique_together=set([('switch', 'port')]), + ), + migrations.RemoveField( + model_name='port', + name='_content_type', + ), + migrations.RemoveField( + model_name='port', + name='_object_id', + ), + ] diff --git a/topologie/migrations/0015_auto_20160706_1452.py b/topologie/migrations/0015_auto_20160706_1452.py new file mode 100644 index 00000000..29f9ca99 --- /dev/null +++ b/topologie/migrations/0015_auto_20160706_1452.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('topologie', '0014_auto_20160706_1238'), + ] + + operations = [ + migrations.RemoveField( + model_name='port', + name='related', + ), + migrations.AddField( + model_name='port', + name='related', + field=models.ManyToManyField(related_name='_port_related_+', to='topologie.Port', blank=True), + ), + ] diff --git a/topologie/migrations/0016_auto_20160706_1531.py b/topologie/migrations/0016_auto_20160706_1531.py new file mode 100644 index 00000000..649eab2d --- /dev/null +++ b/topologie/migrations/0016_auto_20160706_1531.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('topologie', '0015_auto_20160706_1452'), + ] + + operations = [ + migrations.RemoveField( + model_name='port', + name='related', + ), + migrations.AddField( + model_name='port', + name='related', + field=models.OneToOneField(blank=True, to='topologie.Port', related_name='related_port', null=True), + ), + ] diff --git a/users/models.py b/users/models.py index 8e5af681..c12def82 100644 --- a/users/models.py +++ b/users/models.py @@ -131,6 +131,17 @@ class SchoolForm(ModelForm): model = School fields = ['name'] + def __init__(self, *args, **kwargs): + super(SchoolForm, self).__init__(*args, **kwargs) + self.fields['name'].label = 'Établissement à ajouter' + +class DelSchoolForm(ModelForm): + schools = forms.ModelMultipleChoiceField(queryset=School.objects.all(), label="Etablissements actuels", widget=forms.CheckboxSelectMultiple) + + class Meta: + exclude = ['name'] + model = School + class RightForm(ModelForm): def __init__(self, *args, **kwargs): super(RightForm, self).__init__(*args, **kwargs) diff --git a/users/templates/users/sidebar.html b/users/templates/users/sidebar.html index 1cc97e47..d4d34a19 100644 --- a/users/templates/users/sidebar.html +++ b/users/templates/users/sidebar.html @@ -5,5 +5,7 @@

Liste des adhérents

Liste des bannissements

Liste des accès à titre gracieux

+

Ajouter un établissement

+

Supprimer un établissement

Retirer un droit rezo

{% endblock %} diff --git a/users/urls.py b/users/urls.py index a7d8b89a..616f3a88 100644 --- a/users/urls.py +++ b/users/urls.py @@ -13,6 +13,8 @@ urlpatterns = [ url(r'^edit_whitelist/(?P[0-9]+)$', views.edit_whitelist, name='edit-whitelist'), 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'^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'), diff --git a/users/views.py b/users/views.py index a2cc32a9..c3e60a9b 100644 --- a/users/views.py +++ b/users/views.py @@ -6,11 +6,11 @@ from django.shortcuts import render_to_response, get_object_or_404 from django.core.context_processors import csrf from django.template import Context, RequestContext, loader from django.contrib import messages -from django.db.models import Max +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 +from users.models import User, Right, Ban, DelRightForm, UserForm, InfoForm, PasswordForm, StateForm, RightForm, BanForm, ProfilForm, Whitelist, WhitelistForm, DelSchoolForm, SchoolForm from cotisations.models import Facture from machines.models import Machine, Interface from users.forms import PassForm @@ -217,6 +217,27 @@ def edit_whitelist(request, whitelistid): return redirect("/users/") return form({'userform': whitelist}, 'users/user.html', request) +def add_school(request): + school = SchoolForm(request.POST or None) + if school.is_valid(): + school.save() + messages.success(request, "L'établissement a été ajouté") + return redirect("/users/") + return form({'userform': school}, 'users/user.html', request) + +def del_school(request): + school = DelSchoolForm(request.POST or None) + if school.is_valid(): + school_dels = school.cleaned_data['schools'] + for school_del in school_dels: + try: + school_del.delete() + 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 form({'userform': school}, 'users/user.html', request) + def index(request): users_list = User.objects.order_by('pk') connexion = []