8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-23 23:43:47 +00:00

Vue pour gérer la liste des écoles

This commit is contained in:
Gabriel Detraz 2016-07-06 19:45:36 +02:00
parent 881340ae1f
commit cf5b55b31a
8 changed files with 129 additions and 2 deletions

View file

@ -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'),
),
]

View file

@ -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',
),
]

View file

@ -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),
),
]

View file

@ -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),
),
]

View file

@ -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)

View file

@ -5,5 +5,7 @@
<p><a href="{% url "users:index" %}">Liste des adhérents</a></p>
<p><a href="{% url "users:index-ban" %}">Liste des bannissements</a></p>
<p><a href="{% url "users:index-white" %}">Liste des accès à titre gracieux</a></p>
<p><a href="{% url "users:add-school" %}">Ajouter un établissement</a></p>
<p><a href="{% url "users:del-school" %}">Supprimer un établissement</a></p>
<p><a href="{% url "users:del-right" %}">Retirer un droit rezo</a></p>
{% endblock %}

View file

@ -13,6 +13,8 @@ urlpatterns = [
url(r'^edit_whitelist/(?P<whitelistid>[0-9]+)$', views.edit_whitelist, name='edit-whitelist'),
url(r'^add_right/(?P<userid>[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<userid>[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'),

View file

@ -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 = []