Commit a67ad011 authored by Gabriel Detraz's avatar Gabriel Detraz

Ajout d'une vue de modification de solde pour les cableurs, reste à ajouter la...

Ajout d'une vue de modification de solde pour les cableurs, reste à ajouter la vente sur la meme vue
parent 95d1cba7
......@@ -5,6 +5,7 @@ from django import forms
from django.forms import widgets
from django.core.validators import validate_email
from gestion import config
from gestion.config import factures
from gestion.chgpass import check_password
import subprocess
......@@ -94,3 +95,8 @@ class BasePassForm(forms.Form):
class PassForm(BasePassForm):
passwdexists = forms.CharField(label=u'Ancien mot de passe', max_length=255, widget=widgets.PasswordInput, required=True)
class FactureForm(forms.Form):
montant = forms.DecimalField(label=u'Montant à ajouter ou supprimer', required=True)
mode = forms.ChoiceField(choices=tuple(factures.SOLDE.items()), widget=forms.RadioSelect(), required=True)
commentaire = forms.CharField(label=u'Commentaire', max_length=255, required=False)
......@@ -83,7 +83,14 @@
</div>
<div class="row">
<a class="button" href="{% url 'compte:chgpass' 'adh' luser.aid.0 %}">Changer mon mot de passe</a>
<div class="six columns">
<a class="button" href="{% url 'compte:chgpass' 'adh' luser.aid.0 %}">Changer mon mot de passe</a>
</div>
{% if cablage %}
<div class="six columns">
<a class="button" href="{% url 'compte:facture' 'adh' luser.aid.0 %}">Vendre un article ou modifier le solde</a>
</div>
{% endif %}
</div>
<h2>Mail</h2>
......
{% extends "template.html" %}
{% block title %} Factures et solde {% endblock %}
{% block h1 %} Créer une facture ou modifier le solde {% endblock %}
{% block content %}
<form class="form-full-width" method="post">{% csrf_token %}
<div class="error-container">
{{ form.non_field_errors }}
</div>
<h2>Modifier le solde</h2>
<div class="row">
<div class="six columns{% if form.montant.errors %} error{% endif %}">
{{ form.montant.label_tag}}
{{ form.montant }}
{{ form.montant.errors }}
</div>
<div class="six columns{% if form.commentaire.errors %} error{% endif %}">
{{ form.commentaire.label_tag}}
{{ form.commentaire }}
{{ form.commentaire.errors }}
</div>
</div>
<div class="row">
<div class="six columns{% if form.mode.errors %} error{% endif %}">
{{ form.mode.label_tag}}
{{ form.mode }}
{{ form.mode.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>
</form>
{% endblock %}
......@@ -21,4 +21,6 @@ urlpatterns = patterns('',
views.delete_alias, name='delete_alias'),
url('^delete_alias/(?P<uid>[0-9]+)/(?P<ptype>club)/(?P<alias_id>[0-9]+)/$',
views.delete_alias, name='delete_alias'),
url('^facture/(?P<ptype>club)/(?P<uid>[0-9]+)/$', views.facture, name='facture'),
url('^facture/(?P<ptype>adh)/(?P<uid>[0-9]+)/$', views.facture, name='facture'),
)
......@@ -23,7 +23,7 @@ import lc_ldap.crans_utils
from intranet import settings
from forms import BaseCompteForm, CompteForm, BasePassForm, PassForm, MailForm, AliasForm
from forms import BaseCompteForm, CompteForm, BasePassForm, PassForm, MailForm, AliasForm, FactureForm
from django.forms.util import ErrorList
def is_cableur(user):
......@@ -51,7 +51,7 @@ class ClubView(CableurOrSelfMixin, View):
"""
template_name = 'compte/affichage_club.html'
def get(self, request, cid, *args, **kwargs):
def get(self, request, cid, cablage, *args, **kwargs):
# On a juste a peupler le form avec les informations de l'utilisateur
luser = conn_pool.get_conn(request.user).search(u'cid=%s' % cid)[0]
form = BaseCompteForm(luser)
......@@ -59,10 +59,11 @@ class ClubView(CableurOrSelfMixin, View):
'form': form,
'now': timezone.now(),
'luser': luser,
'cablage': cablage,
}
return render(request, self.template_name, context)
def post(self, request, cid, *args, **kwargs):
def post(self, request, cid, cablage, *args, **kwargs):
luser = conn_pool.get_conn(request.user).search(u'cid=%s' % cid)[0]
form = BaseCompteForm(luser, request.POST)
if form.is_valid():
......@@ -85,6 +86,7 @@ class ClubView(CableurOrSelfMixin, View):
'form': form,
'now': timezone.now(),
'luser': luser,
'cablage': cablage,
}
return render(request, self.template_name, context)
......@@ -94,7 +96,10 @@ class ClubView(CableurOrSelfMixin, View):
if not cid:
luser = conn_pool.get_user(request.user)
cid = luser['cid'][0]
return super(ClubView, self).dispatch(request, cid, *args, **kwargs)
cablage = False
if is_cableur(request.user):
cablage = True
return super(ClubView, self).dispatch(request, cid, cablage, *args, **kwargs)
afficher_club = ClubView.as_view()
......@@ -105,7 +110,7 @@ class CompteView(CableurOrSelfMixin, View):
"""
template_name = 'compte/affichage.html'
def get(self, request, aid, *args, **kwargs):
def get(self, request, aid, cablage, *args, **kwargs):
luser = conn_pool.get_conn(request.user).search(u'aid=%s' % aid)[0]
redirection_mail = subprocess.Popen(["sudo", "-n", "/usr/scripts/utils/forward.py", "--read", "--name=%s" % luser['uid'][0]], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
mailredirect = redirection_mail.stdout.readlines()
......@@ -120,10 +125,11 @@ class CompteView(CableurOrSelfMixin, View):
'now': timezone.now(),
'luser': luser,
'mailredirect': mailredirect,
'cablage': cablage,
}
return render(request, self.template_name, context)
def post(self, request, aid, *args, **kwargs):
def post(self, request, aid, cablage, *args, **kwargs):
luser = conn_pool.get_conn(request.user).search(u'aid=%s' % aid)[0]
form = CompteForm(luser, request.POST)
if form.is_valid():
......@@ -163,6 +169,7 @@ class CompteView(CableurOrSelfMixin, View):
'form': form,
'now': timezone.now(),
'luser': luser,
'cablage': cablage,
}
return render(request, self.template_name, context)
......@@ -172,7 +179,10 @@ class CompteView(CableurOrSelfMixin, View):
if not aid:
luser = conn_pool.get_user(request.user)
aid = luser['aid'][0]
return super(CompteView, self).dispatch(request, aid, *args, **kwargs)
cablage = False
if is_cableur(request.user):
cablage = True
return super(CompteView, self).dispatch(request, aid, cablage, *args, **kwargs)
afficher = CompteView.as_view()
......@@ -333,11 +343,40 @@ alias = AliasView.as_view()
# Vues réservées aux cableurs
class FactureView(CableurOrSelfMixin, View):
"""
Classe de base pour les modifications de solde
"""
template_name = "compte/facture.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 = FactureForm()
return render(request, self.template_name, {'form': form, 'ptype': ptype, 'ide': uid})
def post(self, request, uid, ptype, *args, **kwargs):
form = FactureForm(request.POST)
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]
if form.is_valid():
with luser as user:
user.solde(float(form.cleaned_data['montant']), comment="mode: " + form.cleaned_data['mode'] + " ,"+form.cleaned_data['commentaire'], login=unicode(request.user))
user.save()
messages.success(request, u"""Modification de solde effectuée""")
return redirect_home(uid, ptype)
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(FactureView, self).dispatch(request, uid, ptype, *args, **kwargs)
#@login_required
#def solde(request, aid=None, cid=None, ptype=None):
# # Modification de solde par le cableur
# if not is_cableur(request):
# messages.error(request, "Vous n'etes pas cableur !")
# return redirect("/compte/")
facture = FactureView.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