Commit 68a47666 authored by Charlie Jacomme's avatar Charlie Jacomme

[club] Gestion du responsable

parent 8b8e7a85
......@@ -32,3 +32,19 @@ class ImprimeurAddForm(forms.Form):
login = new_imprimeur.lower().strip(' ')
return login
class ResponsableEditForm(forms.Form):
new_responsable = forms.CharField(
required=True,
label='Modifier le responsable',
help_text=('Entrer le login crans de la personne.\n'
'Usuellement le nom (sans accents) '
'ou la première lettre du prénom suivi du nom'
)
)
def clean_new_responsable(self):
"""Passe le login du responsable en minuscule et retire les espaces"""
# Apparement cette méthode est appelé par Django au moment du clean
new_responsable = self.cleaned_data['new_responsable']
login = new_responsable.lower().strip(' ')
return login
......@@ -12,7 +12,7 @@
<div class="row">
<div class="six columns">
<a href="{% if not cablage %}{% url 'club:index' %}
{% else %} {% url 'club:index' cid %}{% endif %}" class="button-cancel">Retour à la liste des clubs</a>
{% else %} {% url 'club:index' cid %}{% endif %}" class="button-cancel">Retour</a>
<input class="button-add" type="submit" value="Ajouter cet imprimeur">
</div>
</div>
......
......@@ -12,7 +12,7 @@
<div class="row">
<div class="six columns">
<a href="{% if not cablage %}{% url 'club:index' %}
{% else %} {% url 'club:index' cid %}{% endif %}" class="button-cancel">Retour à la liste des clubs</a>
{% else %} {% url 'club:index' cid %}{% endif %}" class="button-cancel">Retour</a>
<input class="button-del" type="submit" value="Retirer ces imprimeurs">
</div>
</div>
......
......@@ -34,6 +34,15 @@ Responsable : {{club.responsable}}
{% endif %}
"><button class="button-del">Retirer un imprimeur</button></a>
{% endif %}
{% if perms.aut.crans_cableur %}
<a href="
{% if not cablage %}
{% url 'club:responsable_edit' cid=club.cid %}
{% else %}
{% url 'club:responsable_edit' cid=club.cid cablage='cablage'%}
{% endif %}
"><button class="button-add">Modifier le responsable</button></a>
{% endif %}
</footer>
</div>
{% empty %}
......
{% extends "template.html" %}
{% block title %} Club - Modification du responsable {% endblock %}
{% block h1 %} Modification du responsable {% endblock %}
{% block content %}
<div class="error-container">
{{ form.non_field_errors }}
</div>
<form class="form-full-width" method="post">{% csrf_token %}
{{ form.as_p }}
<footer>
<div class="row">
<div class="six columns">
<a href="{% if not cablage %}{% url 'club:index' %}
{% else %} {% url 'club:index' cid %}{% endif %}" class="button-cancel">Retour</a>
<input class="button-add" type="submit" value="Modifier le responsable">
</div>
</div>
</footer>
</form>
{% endblock %}
......@@ -7,6 +7,8 @@ urlpatterns = [
url('^liste/(?P<cid>[0-9]+)/$', views.IndexView.as_view(), name='index'),
url('^(?P<cid>[0-9]+)/imprimeur/ajouter$', views.ImprimeurAddView.as_view(), name='imprimeur_add'),
url('^(?P<cid>[0-9]+)/imprimeur/retirer$', views.ImprimeurDelView.as_view(), name='imprimeur_del'),
url('^(?P<cid>[0-9]+)/responsable/edit$', views.ResponsableEditView.as_view(), name='responsable_edit'),
url('^(?P<cid>[0-9]+)/imprimeur/ajouter/(?P<cablage>cablage)$', views.ImprimeurAddView.as_view(), name='imprimeur_add'),
url('^(?P<cid>[0-9]+)/imprimeur/retirer/(?P<cablage>cablage)$', views.ImprimeurDelView.as_view(), name='imprimeur_del'),
url('^(?P<cid>[0-9]+)/responsable/edit/(?P<cablage>cablage)$', views.ResponsableEditView.as_view(), name='responsable_edit'),
]
......@@ -8,7 +8,7 @@ from django.shortcuts import redirect
from django.forms.models import formset_factory
from django.contrib import messages
from forms import ImprimeurAddForm, ImprimeurDelForm
from forms import ImprimeurAddForm, ImprimeurDelForm, ResponsableEditForm
from tools import get_clubs_for_user, get_imprimeurs_for_club
from intranet import conn_pool
......@@ -128,3 +128,26 @@ class ImprimeurDelView(EditClubView):
club.save()
return super(ImprimeurDelView, self).form_valid(form)
class ResponsableEditView(EditClubView):
template_name = 'club/responsable_edit.html'
form_class = ResponsableEditForm
def form_valid(self, form):
ldap_user = conn_pool.get_conn(self.request.user)
club = ldap_user.search(u'cid=%s' % self.cid, mode='w')[0]
with club as club:
new_responsable = form.cleaned_data['new_responsable']
try:
new_responsable_ldap = ldap_user.search(u'uid=%s' % new_responsable)[0]
except IndexError:
messages.error(self.request, "Ce login n'est pas valide")
return redirect(self.request.path)
try:
club['responsable'] = unicode(new_responsable_ldap['aid'][0])
club.history_gen()
club.save()
except ValueError as e:
messages.error(self.request, e)
return redirect(self.request.path)
return super(ResponsableEditView, self).form_valid(form)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment