Commit 8b57ab4a authored by Antoine Bernard's avatar Antoine Bernard Committed by Antoine Bernard

[factures] Commentaires et lisibilité.

parent 61420181
# -*- coding: utf-8 -*
from django.template.loader import get_template
from django.template import TemplateDoesNotExist, Context
from django.http import HttpResponse, Http404, HttpResponseNotModified
......@@ -33,6 +35,7 @@ def render_tex(request, template, ctx={}):
cache_key = "%s:%s:%s" % (CACHE_PREFIX, template, etag)
pdf = cache.get(cache_key)
# Si le pdf N'est PAS déjà présent sur le serveur.
if pdf is None:
if '\\nonstopmode' not in body:
raise ValueError("\\nonstopmode not present in document, cowardly refusing to process.")
......@@ -52,14 +55,14 @@ def render_tex(request, template, ctx={}):
).wait()
if error:
if request.user.is_superuser:
if request.user.is_superuser: # Si l'utilisateur est nounou
log = open("%s/%s.log" % (tmp, doc)).read()
return HttpResponse(log, content_type="text/plain")
else:
else: # Sinon, on renvoie une page d'erreur
raise RuntimeError("pdflatex error (code %s) in %s/%s" % (error, tmp, doc))
pdf = open("%s/%s.pdf" % (tmp, doc)).read()
finally:
finally: # Quoi qu'il arrive, on supprime le dossier temporaire
shutil.rmtree(tmp)
pass
......
# -*- coding: utf-8 -*
import os
from subprocess import call
from tempfile import mkdtemp, mkstemp
......@@ -33,7 +34,11 @@ class IndexView(CableurOrSelfMixin, View):
luser = conn_pool.get_conn(request.user).search(u'aid=%s' % aid)[0]
elif ptype=="club":
luser = conn_pool.get_conn(request.user).search(u'cid=%s' % cid)[0]
return render(request, self.template_name, {'luser': luser})
return render(
request,
self.template_name,
{'luser': luser,},
)
@method_decorator(login_required)
def dispatch(self, request, aid=None, cid=None, ptype=None, *args, **kwargs):
......@@ -59,24 +64,31 @@ class FactureView(View):
def get(self, request, fid):
luser = conn_pool.get_user(request.user)
f = conn_pool.get_conn(request.user).search(u"fid=%s" % int(fid))
if not f:
if not f: # Si la facture n'existe pas
return redirect('factures:index')
else:
else: # Sinon, le premier élément de f est la facture.
f = f[0]
if not f.dn in [fac.dn for fac in luser.factures()] and not request.user.has_perm('auth.crans_cableur'):
# On vérifie que l'utilisateur demande une facture dont il est le
# propriétaire, ou que l'utilisateur est un câbleur.
if not f.dn in [fac.dn for fac in luser.factures()] \
and not request.user.has_perm('auth.crans_cableur'):
return redirect('factures:index')
# On commence le traitement des données à générer.
total = 0
for i in range(0,len(f['article'])):
f['article'][i].value['ptotal']=int(f['article'][i]['nombre']) * float(f['article'][i]['pu'])
f['article'][i].value['ptotal'] = int(f['article'][i]['nombre']) * float(f['article'][i]['pu'])
total += f['article'][i].value['ptotal']
if f.get('recuPaiement', []):
paid = total
else:
paid = 0
# On récupère la date et l'heure de la facture
(jour, heure) = f['historique'][0].value.split(',')[0].split(" ")
date = u"Le %s à %s" % (jour, heure.replace(":", "h"))
# On récupère le montant restant à payer
topay = total - paid
return render_tex(request, 'factures/facture.tex', {'total':total, 'paid':paid, 'topay':topay, 'DATE':date, 'f':f, 'fid':fid})
......
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