mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-25 08:23:46 +00:00
Fix #48 : Rename invoice PDF file
This commit is contained in:
parent
66dec02f59
commit
d3b0e14ba9
2 changed files with 21 additions and 12 deletions
|
@ -21,17 +21,14 @@
|
||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
from django.template.loader import get_template
|
from django.template.loader import get_template
|
||||||
from django.template import TemplateDoesNotExist, Context
|
from django.template import Context
|
||||||
from django.http import HttpResponse, Http404, HttpResponseNotModified
|
from django.http import HttpResponse
|
||||||
from django.core.cache import cache
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.shortcuts import redirect
|
from django.utils.text import slugify
|
||||||
|
|
||||||
import tempfile
|
import tempfile
|
||||||
from subprocess import Popen, PIPE
|
from subprocess import Popen, PIPE
|
||||||
import os
|
import os
|
||||||
import shutil
|
|
||||||
from hashlib import md5
|
|
||||||
|
|
||||||
|
|
||||||
TEMP_PREFIX = getattr(settings, 'TEX_TEMP_PREFIX', 'render_tex-')
|
TEMP_PREFIX = getattr(settings, 'TEX_TEMP_PREFIX', 'render_tex-')
|
||||||
|
@ -39,9 +36,22 @@ CACHE_PREFIX = getattr(settings, 'TEX_CACHE_PREFIX', 'render-tex')
|
||||||
CACHE_TIMEOUT = getattr(settings, 'TEX_CACHE_TIMEOUT', 86400) # 1 day
|
CACHE_TIMEOUT = getattr(settings, 'TEX_CACHE_TIMEOUT', 86400) # 1 day
|
||||||
|
|
||||||
|
|
||||||
def render_tex(request,tmp, ctx={}):
|
def render_invoice(request, ctx={}):
|
||||||
|
filename = '_'.join([
|
||||||
|
'invoice',
|
||||||
|
slugify(ctx['asso_name']),
|
||||||
|
slugify(ctx['dest'].pseudo),
|
||||||
|
str(ctx['DATE'].year),
|
||||||
|
str(ctx['DATE'].month),
|
||||||
|
str(ctx['DATE'].day),
|
||||||
|
])
|
||||||
|
r = render_tex(request, 'cotisations/factures.tex', ctx)
|
||||||
|
r['Content-Disposition'] = ''.join(['attachment; filename="',filename,'.pdf"'])
|
||||||
|
return r
|
||||||
|
|
||||||
|
def render_tex(request, template, ctx={}):
|
||||||
context = Context(ctx)
|
context = Context(ctx)
|
||||||
template = get_template('cotisations/factures.tex')
|
template = get_template(template)
|
||||||
rendered_tpl = template.render(context).encode('utf-8')
|
rendered_tpl = template.render(context).encode('utf-8')
|
||||||
|
|
||||||
with tempfile.TemporaryDirectory() as tempdir:
|
with tempfile.TemporaryDirectory() as tempdir:
|
||||||
|
@ -55,6 +65,5 @@ def render_tex(request,tmp, ctx={}):
|
||||||
with open(os.path.join(tempdir, 'texput.pdf'), 'rb') as f:
|
with open(os.path.join(tempdir, 'texput.pdf'), 'rb') as f:
|
||||||
pdf = f.read()
|
pdf = f.read()
|
||||||
r = HttpResponse(content_type='application/pdf')
|
r = HttpResponse(content_type='application/pdf')
|
||||||
#r['Content-Disposition'] = 'attachement; filename=texput.pdf'
|
|
||||||
r.write(pdf)
|
r.write(pdf)
|
||||||
return r
|
return r
|
||||||
|
|
|
@ -61,7 +61,7 @@ from .forms import (
|
||||||
SelectClubArticleForm,
|
SelectClubArticleForm,
|
||||||
CreditSoldeForm
|
CreditSoldeForm
|
||||||
)
|
)
|
||||||
from .tex import render_tex
|
from .tex import render_invoice
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
@ -182,7 +182,7 @@ def new_facture_pdf(request):
|
||||||
tbl.append([art, quantite, art.prix * quantite])
|
tbl.append([art, quantite, art.prix * quantite])
|
||||||
prix_total = sum(a[2] for a in tbl)
|
prix_total = sum(a[2] for a in tbl)
|
||||||
user = {'name': destinataire, 'room': chambre}
|
user = {'name': destinataire, 'room': chambre}
|
||||||
return render_tex(request, 'cotisations/factures.tex', {
|
return render_invoice(request, {
|
||||||
'DATE': timezone.now(),
|
'DATE': timezone.now(),
|
||||||
'dest': user,
|
'dest': user,
|
||||||
'fid': fid,
|
'fid': fid,
|
||||||
|
@ -233,7 +233,7 @@ def facture_pdf(request, factureid):
|
||||||
options, _created = AssoOption.objects.get_or_create()
|
options, _created = AssoOption.objects.get_or_create()
|
||||||
for vente in ventes_objects:
|
for vente in ventes_objects:
|
||||||
ventes.append([vente, vente.number, vente.prix_total])
|
ventes.append([vente, vente.number, vente.prix_total])
|
||||||
return render_tex(request, 'cotisations/factures.tex', {
|
return render_invoice(request, {
|
||||||
'paid': True,
|
'paid': True,
|
||||||
'fid': facture.id,
|
'fid': facture.id,
|
||||||
'DATE': facture.date,
|
'DATE': facture.date,
|
||||||
|
|
Loading…
Reference in a new issue