Commit 1358c48e authored by Charlie Jacomme's avatar Charlie Jacomme

[compte] Demenagement et suppression

parent d040bb0f
......@@ -127,3 +127,16 @@ class ComptecransForm(forms.Form):
else:
login_crans = u'club-' + nom
self.fields['login'].initial = login_crans
class DemenagementForm(forms.Form):
postalAddress = forms.CharField(label=u'Adresse :', max_length=255, required=False)
postalAddress2 = forms.CharField(label=u'Adresse :', max_length=255, required=False)
postalAddress3 = forms.CharField(label=u'Code Postal :', max_length=255, required=False)
postalAddress4 = forms.CharField(label=u'Ville :', max_length=255, required=False)
chbre = forms.CharField(label=u'Chambre de l\'adhérent', max_length=255, required=False)
del_machines = forms.BooleanField(label=u'Supprimer les machines enregistrées', required=False)
def clean(self):
datas = [field for field in self.cleaned_data if self.cleaned_data[field]]
if "chbre" in datas and len(datas)>1 :
print self.cleaned_data
raise forms.ValidationError("Impossible d'avoir une chambre et une adresse extérieur")
......@@ -89,6 +89,18 @@
{% endif %}
</div>
<div class="row">
{% if cablage %}
<div class="four columns">
<a class="button" href="{% url 'compte:demenagement' 'adh' luser.aid.0 %}">Déménager</a>
</div>
{% if 'Nounou' in luser.droits or 'Bureau' in luser.droits %}
<div class="four columns">
<a class="button" href="{% url 'compte:delete' 'adh' luser.aid.0 %}">Supprimer le compte</a>
</div>
{% endif %}
{% endif %}
</div>
<div class="row">
{% if comptecrans %}
<div class="four columns">
......
......@@ -57,7 +57,19 @@
</div>
{% endif %}
</div>
<div class="row">
{% if cablage %}
<div class="four columns">
<a class="button" href="{% url 'compte:demenagement' 'adh' luser.aid.0 %}">Déménager</a>
</div>
{% if 'Nounou' in luser.droits or 'Bureau' in luser.droits %}
<div class="four columns">
<a class="button" href="{% url 'compte:delete' 'adh' luser.aid.0 %}">Supprimer le compte</a>
</div>
{% endif %}
{% endif %}
</div>
<div class="row">
{% if comptecrans %}
<div class="four columns">
......
{% extends "template.html" %}
{% block title %} Suppression {% endblock %}
{% block h1 %} Suppression d'un compte {% endblock %}
{% block content %}
<form class="form-full-width" method="post" {% if confirm %} action="{% url 'compte:demenagement' ptype ide confirm %}" {% endif %}>{% csrf_token %}
<div class="error-container">
{{ form.non_field_errors }}
</div>
<h2>Attention, la suppression est définitive, voulez vous vraiment détruire le compte ?</h2>
<footer>
<a href="{% if ptype == "club" %} {% url 'compte:afficher_club' ide %} {% else %} {% url 'compte:afficher' ide %} {% endif %}" class="button-add">Non</a>
<input type="submit" value="Oui" class="button-cancel">
</footer>
</form>
{% endblock %}
{% extends "template.html" %}
{% block title %} Demenagement {% endblock %}
{% block h1 %} Déménagement {% endblock %}
{% block content %}
<form class="form-full-width" method="post" {% if confirm %} action="{% url 'compte:demenagement' ptype ide confirm %}" {% endif %}>{% csrf_token %}
<div class="error-container">
{{ form.non_field_errors }}
</div>
<h2>Déménagement à l'intérieur du campus</h2>
<div class="row">
<div class="six columns{% if form.mode.errors %} error{% endif %}">
{{ form.chbre.label_tag}}
{{ form.chbre }}
{{ form.chbre.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="Enregistrer">
</footer>
{% if ptype != "club" %}
<h2>Déménagement à l'extérieur</h2>
<div class="row">
<div class="six columns{% if form.articles.errors %} error{% endif %}">
{{ form.del_machines.label_tag}}
{{ form.del_machines }}
{{ form.del_machines.errors }}
</div>
</div>
<div class="row">
<div class="twelve columns{% if form.mode.errors %} error{% endif %}">
{{ form.postalAddress.label_tag}}
{{ form.postalAddress }}
{{ form.postalAddress.errors }}
</div>
</div>
<div class="row">
<div class="twelve columns{% if form.mode.errors %} error{% endif %}">
{{ form.postalAddress2.label_tag}}
{{ form.postalAddress2 }}
{{ form.postalAddress2.errors }}
</div>
</div>
<div class="row">
<div class="six columns{% if form.mode.errors %} error{% endif %}">
{{ form.postalAddress3.label_tag}}
{{ form.postalAddress3 }}
{{ form.postalAddress3.errors }}
</div>
<div class="six columns{% if form.mode.errors %} error{% endif %}">
{{ form.postalAddress4.label_tag}}
{{ form.postalAddress4 }}
{{ form.postalAddress4.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="Enregistrer">
</footer>
{% endif %}
</form>
{% endblock %}
......@@ -29,4 +29,10 @@ views.delete_alias, name='delete_alias'),
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'),
url('^demenagement/(?P<ptype>club)/(?P<uid>[0-9]+)/$', views.demenagement, name='demenagement'),
url('^demenagement/(?P<ptype>adh)/(?P<uid>[0-9]+)/$', views.demenagement, name='demenagement'),
url('^demenagement/(?P<ptype>club)/(?P<uid>[0-9]+)/(?P<confirm>confirm)/$', views.demenagement, name='demenagement'),
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'),
)
......@@ -23,12 +23,12 @@ import datetime
from passlib.apps import ldap_context
import lc_ldap.crans_utils
from lc_ldap.attributs import UniquenessError
from intranet import settings
from gestion.config import factures, cotisation
from forms import BaseCompteForm, CompteForm, BasePassForm, PassForm, MailForm, AliasForm, SoldeForm, VenteForm, AdhesionForm, ComptecransForm
from forms import BaseCompteForm, CompteForm, BasePassForm, PassForm, MailForm, AliasForm, SoldeForm, VenteForm, AdhesionForm, ComptecransForm, DemenagementForm
from django.forms.util import ErrorList
def is_cableur(user):
......@@ -545,8 +545,87 @@ class ComptecransView(CableurMixin, View):
elist.append(e)
return render(request, self.template_name, {'form': form, 'ptype': ptype, 'ide': uid})
comptecrans = ComptecransView.as_view()
class DemenagementView(CableurMixin, View):
"""
Classe de base pour le déménagement
"""
template_name = "compte/demenagement.html"
def get(self, request, uid, ptype, *args, **kwargs):
form = DemenagementForm()
return render(request, self.template_name, {'form': form, 'ptype': ptype, 'ide': uid})
def post(self, request, uid, ptype, confirm = "", *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 = DemenagementForm(request.POST)
if form.is_valid():
chbre = form.cleaned_data['chbre']
if chbre:
try:
luser['chbre'] = chbre
luser.save()
messages.success(request, u"""Déménagement effectué""")
return redirect_home(uid, ptype)
except ValueError as e:
form._errors.setdefault('chbre', ErrorList()).append("Cette chambre n'est pas valide pour un club." )
except UniquenessError:
# La chambre est occupée
if not confirm:
# on demande confirmation
confirm = 'confirm'
form._errors.setdefault('chbre', ErrorList()).append("Cette chambre est déjà occupée, corrigez la saisie ou revalidez pour confirmer.")
else:
squatteur = conn_pool.get_conn(request.user).search(u'chbre=%s' % chbre, mode='w')[0]
squatteur['chbre'] = '????'
squatteur.save()
luser['chbre'] = chbre
luser.save()
messages.success(request, u"""Déménagement effectué""")
return redirect_home(uid, ptype)
comptecrans = ComptecransView.as_view()
else:
luser['chbre'] = 'EXT'
luser['postalAddress'][0] = form.cleaned_data['postalAddress']
luser['postalAddress'][1] = form.cleaned_data['postalAddress2']
luser['postalAddress'][2] = form.cleaned_data['postalAddress3']
luser['postalAddress'][3] = form.cleaned_data['postalAddress4']
luser.save()
if form.cleaned_data['del_machines']:
for m in luser.machines():
m.delete(login = request.user.username)
messages.success(request, u"""Déménagement effectué""")
return redirect_home(uid, ptype)
return render(request, self.template_name, {'form': form, 'ptype': ptype, 'ide': uid, 'confirm' : confirm})
demenagement = DemenagementView.as_view()
class DeleteCompteView(CableurMixin, View):
"""
Classe pour la suppression d'un compte
"""
template_name = "compte/delete.html"
def get(self, request, uid, ptype, *args, **kwargs):
return render(request, self.template_name, {'ptype': ptype, 'ide': uid})
def post(self, request, uid, ptype, confirm = "", *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]
for m in luser.machines():
m.delete(login = request.user.username)
luser.delete(login = request.user.username)
messages.success(request, u"""Compte supprimé""")
return redirect(reverse('home'))
delete = DeleteCompteView.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