Commit 9c7b2d97 authored by Charlie Jacomme's avatar Charlie Jacomme

[compte] Création de club

parent b168942c
......@@ -29,9 +29,11 @@
<h2>Créer un nouvel objet</h2>
<div class="row">
<a class="button" href="{% url 'compte:create' %}">Créer un nouvel adhérent</a>
<a class="button" href="{% url 'compte:create' 'adh'%}">Créer un nouvel adhérent</a>
</div>
<div class="row">
<a class="button" href="{% url 'compte:create' 'club'%}">Créer un nouveau club</a>
</div>
<div class="row">
<a class="button" href="{% url 'cablage:rechercher' %}addmachineadherent">Ajouter une machine à un adhérent</a>
</div>
......
......@@ -22,6 +22,18 @@ class BaseCompteForm(forms.Form):
if ldap_user:
self.fields['nom'].initial = ldap_user['nom'][0]
#self.fields['tel'].initial = ldap_user.get('tel',[''])[0]
def apply(self, luser):
"""
Fonction d'application des modifications à l'objet ldap. Doit être appellé après un form.valid
"""
for field in self.changed_data:
try:
luser[field] = unicode(self.cleaned_data[field])
except ValueError as e:
elist = self._errors.setdefault(field, ErrorList())
elist.append(e)
return False
return True
......@@ -207,7 +219,8 @@ class EmenagementForm(forms.Form):
chbre = self.cleaned_data['chbre']
try:
luser['chbre'] = chbre
luser['postalAddress'] = []
if 'adherent' in luser.get("objectClass", []):
luser['postalAddress'] = []
return True
except ValueError as e:
self._errors.setdefault('chbre', ErrorList()).append(e )
......@@ -219,11 +232,15 @@ class EmenagementForm(forms.Form):
self._errors.setdefault('chbre', ErrorList()).append("Cette chambre est déjà occupée, corrigez la saisie ou revalidez pour confirmer.")
return 'confirm' # Ce confirm doit être rattrapé par la view
else:
squatteur = conn.search(u'chbre=%s' % chbre, mode='w')[0]
squatteur['chbre'] = '????' # on vire le squatteur si on a eu une confirmation
squatteur.save()
luser['chbre'] = chbre
return True
if 'adherent' in luser.get("objectClass", []):
squatteur = conn.search(u'chbre=%s' % chbre, mode='w')[0]
squatteur['chbre'] = '????' # on vire le squatteur si on a eu une confirmation
squatteur.save()
luser['chbre'] = chbre
return True
else: # on ne peut pas virer un club
self._errors.setdefault('chbre', ErrorList()).append("Un club ne peux pas être viré")
return 'confirm' # Ce confirm doit être rattrapé par la view
class DemenagementForm(EmenagementForm):
postalAddress = forms.CharField(label=u'Adresse :', max_length=255, required=False)
......@@ -268,3 +285,10 @@ class NewCompteForm(CompteForm):
if age < 18:
return False
return True
class NewClubForm(BaseCompteForm):
responsable = forms.IntegerField(label=u'Aid du responsable', required=True)
def check_date(self):
return True
......@@ -3,7 +3,7 @@
{% block h1 %} Création d'un adhérent{% endblock %}
{% block content %}
<form class="form1-full-width" method="post" {% if confirm %} action="{% url 'compte:create' confirm %}" {% endif %}>{% csrf_token %}
<form class="form1-full-width" method="post" {% if confirm %} action="{% url 'compte:create' ptype confirm %}" {% endif %}>{% csrf_token %}
<div class="error-container">
{{ form1.non_field_errors }}
</div>
......@@ -50,6 +50,11 @@
{{ form1.naissance }}
{{ form1.naissance.errors }}
</div>
<div class="four columns{% if form1.responsable.errors %} error{% endif %}">
{{ form1.responsable.label_tag}}
{{ form1.responsable }}
{{ form1.responsable.errors }}
</div>
</div>
<div class="error-container">
......
......@@ -11,6 +11,7 @@ urlpatterns = patterns('',
url('^club/$', views.afficher_club, name='afficher_club'),
url('^chgpass/$', views.chgpass, name='chgpass'),
url('^chgpass/(?P<ptype>club)/(?P<uid>[0-9]+)/$', views.chgpass, name='chgpass'),
url('^chgpass/(?P<ptype>club)/(?P<uid>[0-9]+)/(?P<next>.*)/$', views.chgpass, name='chgpass'),
url('^chgpass/(?P<ptype>adh)/(?P<uid>[0-9]+)/$', views.chgpass, name='chgpass'),
url('^chgpass/(?P<ptype>adh)/(?P<uid>[0-9]+)/(?P<next>.*)/$', views.chgpass, name='chgpass'),
url('^redirection/$', views.redirection, name='redirection'),
......@@ -37,7 +38,9 @@ views.delete_alias, name='delete_alias'),
url('^demenagement/(?P<ptype>adh)/(?P<uid>[0-9]+)/(?P<confirm>confirm)/$', views.demenagement, name='demenagement'),
url('^delete/(?P<ptype>club)/(?P<uid>[0-9]+)/$', views.delete, name='delete'),
url('^delete/(?P<ptype>adh)/(?P<uid>[0-9]+)/$', views.delete, name='delete'),
url('^create/$', views.create, name='create'),
url('^create/(?P<confirm>confirm)/$$', views.create, name='create'),
url('^(?P<ptype>adh)/create/$', views.create, name='create'),
url('^(?P<ptype>adh)/create/(?P<confirm>confirm)/$$', views.create, name='create'),
url('^(?P<ptype>club)/create/$', views.create, name='create'),
url('^(?P<ptype>club)/create/(?P<confirm>confirm)/$$', views.create, name='create'),
url('^resetpass/(?P<uid>[0-9]+)/$', views.resetpass, name='resetpass'),
)
......@@ -27,7 +27,7 @@ from intranet import settings
from gestion.config import factures, cotisation
from forms import BaseCompteForm, CompteForm, BasePassForm, PassForm, MailForm, AliasForm, SoldeForm, VenteForm, AdhesionForm, ComptecransForm, DemenagementForm, NewCompteForm, EmenagementForm
from forms import BaseCompteForm, CompteForm, BasePassForm, PassForm, MailForm, AliasForm, SoldeForm, VenteForm, AdhesionForm, ComptecransForm, DemenagementForm, NewCompteForm, EmenagementForm, NewClubForm
from django.forms.util import ErrorList
from intranet.mixins import CableurOrSelfMixin, CableurMixin
......@@ -590,26 +590,30 @@ class CreateCompteView(CableurMixin, View):
on affiche le formulaire de comptecrans avec un login prégénéré grace
au informations du premier forms.
"""
form1 = NewCompteForm
form2 = EmenagementForm
template_name = "compte/create.html"
def get(self, request, *args, **kwargs):
form1 = NewCompteForm()
form2 = EmenagementForm()
return render(request, self.template_name, {'form1' : form1, 'form2' : form2})
def post(self, request, confirm = "", *args, **kwargs):
form1 = NewCompteForm(data=request.POST)
form2 = EmenagementForm(data=request.POST)
def get(self, request, ptype, *args, **kwargs):
return render(request, self.template_name, {'form1' : self.form1(), 'form2' : self.form2()})
def post(self, request, ptype, confirm = "", *args, **kwargs):
form1 = self.form1(data=request.POST)
form2 = self.form2(data=request.POST)
form3 = None
comptecrans = False
if form1.is_valid() and form2.is_valid():
if 'comptecrans' in request.POST.keys():
comptecrans = True
with conn_pool.get_conn(request.user).newAdherent({}) as adherent:
if ptype == u"club":
new_adherent = conn_pool.get_conn(request.user).newClub
else:
new_adherent = conn_pool.get_conn(request.user).newAdherent
with new_adherent({}) as adherent:
lconn = conn_pool.get_conn(request.user)
if 'step2' in request.POST.keys() and form1.apply(adherent):
if not form1.check_date():
messages.error(request, "L'adhérent est mineur, merci de faire signer une décharge par le responsable légal")
form3 = ComptecransForm(ldap_user = adherent, ldap_conn=lconn, ptype = u"adh")
form3 = ComptecransForm(ldap_user = adherent, ldap_conn=lconn, ptype = ptype)
else:
form3 = ComptecransForm(data=request.POST)
if form3.is_valid():
......@@ -622,13 +626,25 @@ class CreateCompteView(CableurMixin, View):
elif res:
adherent.create()
messages.success(request, u"""Compte crée""")
adh_url = reverse('compte:adhesion', args=(u'adh', adherent['aid'][0]))
redir_url = reverse('compte:redirection', args=(adherent['aid'][0], True, adh_url))
if ptype == u"club":
uid = adherent['cid'][0]
redir_url = reverse('compte:adhesion', args=(ptype, uid))
else:
uid = adherent['aid'][0]
adh_url = reverse('compte:adhesion', args=(ptype, uid))
redir_url = reverse('compte:redirection', args=(uid, True, adh_url))
if comptecrans:
return redirect(reverse('compte:chgpass', args=(u'adh', adherent['aid'][0], redir_url)))
return redirect(reverse('compte:chgpass', args=(ptype, uid, redir_url)))
else:
return redirect(adh_url)
return render(request, self.template_name, {'form1' : form1, 'form2' : form2, 'form3' : form3, 'confirm' : confirm, 'comptecrans': comptecrans})
return redirect(redir_url)
return render(request, self.template_name, {'form1' : form1, 'form2' : form2, 'form3' : form3, 'confirm' : confirm, 'ptype' : ptype, 'comptecrans': comptecrans})
@method_decorator(login_required)
def dispatch(self, request, ptype=u"adh", *args, **kwargs):
if ptype == u"club":
self.form1 = NewClubForm
return super(CreateCompteView, self).dispatch(request, ptype=ptype, *args, **kwargs)
create = CreateCompteView.as_view()
......
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