8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-27 15:12:25 +00:00

Modification et affichage de la liste des écoles

This commit is contained in:
chirac 2016-07-08 02:25:12 +02:00
parent 560db140d1
commit 23246b848e
6 changed files with 54 additions and 6 deletions

View file

@ -133,7 +133,7 @@ class SchoolForm(ModelForm):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(SchoolForm, self).__init__(*args, **kwargs) super(SchoolForm, self).__init__(*args, **kwargs)
self.fields['name'].label = 'Établissement à ajouter' self.fields['name'].label = 'Établissement'
class DelSchoolForm(ModelForm): class DelSchoolForm(ModelForm):
schools = forms.ModelMultipleChoiceField(queryset=School.objects.all(), label="Etablissements actuels", widget=forms.CheckboxSelectMultiple) schools = forms.ModelMultipleChoiceField(queryset=School.objects.all(), label="Etablissements actuels", widget=forms.CheckboxSelectMultiple)

View file

@ -0,0 +1,15 @@
<table class="table table-striped">
<thead>
<tr>
<th>Etablissement</th>
<th></th>
</tr>
</thead>
{% for school in school_list %}
<tr>
<td>{{ school.name }}</td>
<td><a class="btn btn-primary btn-sm" role="button" href="{% url 'users:edit-school' school.id %}"><i class="glyphicon glyphicon-pushpin"></i> Editer</a></td>
</tr>
{% endfor %}
</table>

View file

@ -0,0 +1,15 @@
{% extends "users/sidebar.html" %}
{% load bootstrap3 %}
{% block title %}Utilisateurs{% endblock %}
{% block content %}
<h2>Liste des Établissements</h2>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'users:add-school' %}"><i class="glyphicon glyphicon-plus"></i> Ajouter un établissement</a>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'users:del-school' %}"><i class="glyphicon glyphicon-trash"></i> Supprimer un ou plusieurs établissements</a>
{% include "users/aff_schools.html" with school_list=school_list %}
<br />
<br />
<br />
{% endblock %}

View file

@ -5,7 +5,6 @@
<p><a href="{% url "users:index" %}">Liste des adhérents</a></p> <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-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: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:index-school" %}">Liste des établissements</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> <p><a href="{% url "users:del-right" %}">Retirer un droit rezo</a></p>
{% endblock %} {% endblock %}

View file

@ -14,10 +14,12 @@ urlpatterns = [
url(r'^add_right/(?P<userid>[0-9]+)$', views.add_right, name='add-right'), 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'^del_right/$', views.del_right, name='del-right'),
url(r'^add_school/$', views.add_school, name='add-school'), url(r'^add_school/$', views.add_school, name='add-school'),
url(r'^edit_school/(?P<schoolid>[0-9]+)$', views.edit_school, name='edit-school'),
url(r'^del_school/$', views.del_school, name='del-school'), url(r'^del_school/$', views.del_school, name='del-school'),
url(r'^profil/(?P<userid>[0-9]+)$', views.profil, name='profil'), url(r'^profil/(?P<userid>[0-9]+)$', views.profil, name='profil'),
url(r'^index_ban/$', views.index_ban, name='index-ban'), url(r'^index_ban/$', views.index_ban, name='index-ban'),
url(r'^index_white/$', views.index_white, name='index-white'), 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'), url(r'^$', views.index, name='index'),
] ]

View file

@ -10,7 +10,7 @@ from django.db.models import Max, ProtectedError
from django.db import IntegrityError from django.db import IntegrityError
from django.utils import timezone 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 cotisations.models import Facture
from machines.models import Machine, Interface from machines.models import Machine, Interface
from users.forms import PassForm from users.forms import PassForm
@ -222,7 +222,20 @@ def add_school(request):
if school.is_valid(): if school.is_valid():
school.save() school.save()
messages.success(request, "L'établissement a été ajouté") messages.success(request, "L'établissement a été ajouté")
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/") 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) return form({'userform': school}, 'users/user.html', request)
def del_school(request): def del_school(request):
@ -235,7 +248,7 @@ def del_school(request):
messages.success(request, "L'établissement a été supprimé") messages.success(request, "L'établissement a été supprimé")
except ProtectedError: except ProtectedError:
messages.error(request, "L'établissement %s est affecté à au moins un user, vous ne pouvez pas le supprimer" % school_del) 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) return form({'userform': school}, 'users/user.html', request)
def index(request): def index(request):
@ -258,6 +271,10 @@ def index_white(request):
white_list = Whitelist.objects.order_by('date_start') white_list = Whitelist.objects.order_by('date_start')
return render(request, 'users/index_whitelist.html', {'white_list':white_list}) 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): def profil(request, userid):
try: try:
users = User.objects.get(pk=userid) users = User.objects.get(pk=userid)