Commit e58a6758 authored by Gabriel Detraz's avatar Gabriel Detraz

Vue pour la création d'un compte crans

parent 380d54c2
......@@ -8,7 +8,7 @@ from gestion import config
from gestion.config import factures
from gestion.chgpass import check_password
import subprocess
import unicodedata
class BaseCompteForm(forms.Form):
nom = forms.CharField(label=u'Nom', max_length=40, required=True)
......@@ -109,3 +109,21 @@ class VenteForm(forms.Form):
class AdhesionForm(forms.Form):
nbrmois = forms.IntegerField(label=u'Nombre de mois de connexion, entre 0 et 12, 0 pour une adhésion seule', min_value=0, max_value=12, required=True)
mode = forms.ChoiceField(label=u'Mode de réglement', choices=tuple(factures.VENTE.items()), widget=forms.RadioSelect(), required=True)
class ComptecransForm(forms.Form):
login = forms.CharField(label=u'Login Crans', required=True)
def __init__(self, ldap_user, ldap_conn, ptype, *args, **kwargs):
super(ComptecransForm, self).__init__(*args, **kwargs)
nom = unicode(unicodedata.normalize('NFKD', unicode(ldap_user['nom'][0])).encode('ascii', 'ignore')).lower().replace(' ', '-')
if ptype != 'club':
prenom = unicode(unicodedata.normalize('NFKD', unicode(ldap_user['prenom'][0])).encode('ascii', 'ignore')).lower().replace(' ', '-')
login_crans = nom
baselogin = nom
for rang,let in enumerate(prenom):
if ldap_conn.search(u'uid=%s' % login_crans) == []:
break
else:
login_crans = prenom[:rang] + baselogin
else:
login_crans = u'club-' + nom
self.fields['login'].initial = login_crans
......@@ -121,6 +121,12 @@
<div class="four columns">
<a class="button" href="{% url 'compte:redirection' luser.aid.0 %}">Changer la redirection mail</a>
</div>
{% else %}
{% if cablage %}
<div class="four columns">
<a class="button" href="{% url 'compte:comptecrans' 'adh' luser.aid.0 %}">Créer un compte Crans</a>
</div>
{% endif %}
{% endif %}
</div>
......
......@@ -78,13 +78,19 @@
<h2>Mail</h2>
{% if comptecrans %}
<div class="row">
{% if comptecrans %}
<div class="four columns">
<a class="button" href="{% url 'compte:alias' 'club' luser.cid.0 %}">Gérer mes alias mail</a>
</div>
</div>
{% else %}
{% if cablage %}
<div class="four columns">
<a class="button" href="{% url 'compte:comptecrans' 'club' luser.cid.0 %}">Créer un compte Crans</a>
</div>
{% endif %}
{% endif %}
</div>
<footer>
<div class="row">
......@@ -95,3 +101,6 @@
</footer>
</form>
{% endblock %}
{% extends "template.html" %}
{% block title %} Creation du compte crans {% endblock %}
{% block h1 %} Créer un compte Crans {% endblock %}
{% block content %}
<form class="form-full-width" method="post">{% csrf_token %}
<div class="error-container">
{{ form.non_field_errors }}
</div>
<div class="row">
<div class="six columns{% if form.login.errors %} error{% endif %}">
{{ form.login.label_tag}}
{{ form.login }}
{{ form.login.errors }}
</div>
</div>
<footer>
<a href="{% if ptype == "club" %} {% url 'compte:afficher_club' ide %} {% else %} {% url 'compte:afficher' ide %} {% endif %}" class="button-cancel">Retour à mon compte</a>
<input type="submit" value="Suivant">
</footer>
</form>
{% endblock %}
......@@ -27,4 +27,6 @@ views.delete_alias, name='delete_alias'),
url('^vente/(?P<ptype>adh)/(?P<uid>[0-9]+)/$', views.vente, name='vente'),
url('^adhesion/(?P<ptype>club)/(?P<uid>[0-9]+)/$', views.adhesion, name='adhesion'),
url('^adhesion/(?P<ptype>adh)/(?P<uid>[0-9]+)/$', views.adhesion, name='adhesion'),
url('^comptecrans/(?P<ptype>club)/(?P<uid>[0-9]+)/$', views.comptecrans, name='comptecrans'),
url('^comptecrans/(?P<ptype>adh)/(?P<uid>[0-9]+)/$', views.comptecrans, name='comptecrans'),
)
......@@ -28,7 +28,7 @@ from intranet import settings
from gestion.config import factures, cotisation
from forms import BaseCompteForm, CompteForm, BasePassForm, PassForm, MailForm, AliasForm, SoldeForm, VenteForm, AdhesionForm
from forms import BaseCompteForm, CompteForm, BasePassForm, PassForm, MailForm, AliasForm, SoldeForm, VenteForm, AdhesionForm, ComptecransForm
from django.forms.util import ErrorList
def is_cableur(user):
......@@ -531,3 +531,48 @@ class AdhesionView(CableurOrSelfMixin, View):
adhesion = AdhesionView.as_view()
class ComptecransView(CableurOrSelfMixin, View):
"""
Classe de base pour la création de compte crans
"""
template_name = "compte/comptecrans.html"
def get(self, request, uid, ptype, *args, **kwargs):
if ptype == 'club':
luser = conn_pool.get_conn(request.user).search(u'cid=%s' % uid)[0]
else:
luser = conn_pool.get_conn(request.user).search(u'aid=%s' % uid)[0]
form = ComptecransForm(luser, conn_pool.get_conn(request.user), ptype)
return render(request, self.template_name, {'form': form, 'ptype': ptype, 'ide': uid})
def post(self, request, uid, ptype, *args, **kwargs):
if ptype == 'club':
luser = conn_pool.get_conn(request.user).search(u'cid=%s' % uid, mode='w')[0]
else:
luser = conn_pool.get_conn(request.user).search(u'aid=%s' % uid, mode='w')[0]
form = ComptecransForm(luser, conn_pool.get_conn(request.user), ptype, request.POST)
if form.is_valid():
with luser as user:
try:
user.compte(login=unicode(form.cleaned_data['login']))
user.history_gen()
user.save()
messages.success(request, u"""Compte Crans crée, choisir un mot de passe""")
return redirect(reverse('compte:chgpass', args=(ptype,uid)))
except ValueError as e:
# Le message d'une ValueError est directement dans e
elist = form._errors.setdefault('login', ErrorList())
elist.append(e)
return render(request, self.template_name, {'form': form, 'ptype': ptype, 'ide': uid})
@method_decorator(login_required)
def dispatch(self, request, uid, ptype, *args, **kwargs):
if not is_cableur(request.user):
messages.error(request, "Accès interdits, droits insuffisants")
return redirect(settings.LOGIN_URL)
return super(ComptecransView, self).dispatch(request, uid, ptype, *args, **kwargs)
comptecrans = ComptecransView.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