1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-12-22 23:42:25 +00:00
This commit is contained in:
Yohann D'ANELLO 2020-03-21 17:29:39 +01:00
parent b3bc30b72b
commit 2d0ba4750c
6 changed files with 45 additions and 37 deletions

View File

@ -3,7 +3,7 @@
from django.contrib import admin
from treasury.models import Billing, Product
from .models import Billing, Product
@admin.register(Billing)

View File

@ -2,7 +2,6 @@
# SPDX-License-Identifier: GPL-3.0-or-later
from django.apps import AppConfig
from django.db.models.signals import pre_save, post_save, post_delete
from django.utils.translation import gettext_lazy as _

View File

@ -20,10 +20,11 @@ ProductFormSet = forms.inlineformset_factory(
extra=1,
)
class ProductFormSetHelper(FormHelper):
def __init__(self, form=None):
super().__init__(form)
self.form_tag = False
self.form_method = 'POST'
self.form_class = 'form-inline'
self.template = 'bootstrap4/table_inline_formset.html'
self.template = 'bootstrap4/table_inline_formset.html'

View File

@ -1,8 +1,8 @@
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from django.utils.translation import gettext_lazy as _
import django_tables2 as tables
from django.utils.translation import gettext_lazy as _
from django_tables2 import A
from .models import Billing
@ -11,17 +11,17 @@ from .models import Billing
class BillingTable(tables.Table):
id = tables.LinkColumn("treasury:billing_update",
args=[A("pk")],
text=lambda record: _("Billing #{:d}").format(record.id),)
text=lambda record: _("Billing #{:d}").format(record.id), )
billing = tables.LinkColumn("treasury:billing_render",
verbose_name=_("Billing"),
args=[A("pk")],
accessor="pk",
text="",
attrs={
'a': {'class': 'fa fa-file-pdf-o'},
'td': {'data-turbolinks': 'false'}
})
verbose_name=_("Billing"),
args=[A("pk")],
accessor="pk",
text="",
attrs={
'a': {'class': 'fa fa-file-pdf-o'},
'td': {'data-turbolinks': 'false'}
})
class Meta:
attrs = {
@ -29,4 +29,4 @@ class BillingTable(tables.Table):
}
model = Billing
template_name = 'django_tables2/bootstrap4.html'
fields = ('id', 'name', 'subject', 'acquitted', 'billing', )
fields = ('id', 'name', 'subject', 'acquitted', 'billing',)

View File

@ -15,7 +15,6 @@ from django.urls import reverse_lazy
from django.views.generic import CreateView, UpdateView
from django.views.generic.base import View
from django_tables2 import SingleTableView
from note_kfet.settings.base import BASE_DIR
from .forms import BillingForm, ProductFormSet, ProductFormSetHelper
@ -130,30 +129,39 @@ class BillingRenderView(LoginRequiredMixin, View):
pass
tmp_dir = mkdtemp(prefix=BASE_DIR + "/tmp/")
with open("{}/billing-{:d}.tex".format(tmp_dir, pk), "wb") as f:
f.write(tex.encode("UTF-8"))
del tex
try:
with open("{}/billing-{:d}.tex".format(tmp_dir, pk), "wb") as f:
f.write(tex.encode("UTF-8"))
del tex
error = subprocess.Popen(
["pdflatex", "billing-{}.tex".format(pk)],
cwd=tmp_dir,
stdin=open(os.devnull, "r"),
stderr=open(os.devnull, "wb"),
stdout=open(os.devnull, "wb")
).wait()
error = subprocess.Popen(
["pdflatex", "billing-{}.tex".format(pk)],
cwd=tmp_dir,
stdin=open(os.devnull, "r"),
stderr=open(os.devnull, "wb"),
stdout=open(os.devnull, "wb")
).wait()
error = subprocess.Popen(
["pdflatex", "billing-{}.tex".format(pk)],
cwd=tmp_dir,
stdin=open(os.devnull, "r"),
stderr=open(os.devnull, "wb"),
stdout=open(os.devnull, "wb")
).wait()
if error:
raise IOError("An error attempted while generating a billing:", error)
pdf = open("{}/billing-{}.pdf".format(tmp_dir, pk), 'rb').read()
shutil.rmtree(tmp_dir)
error = subprocess.Popen(
["pdflatex", "billing-{}.tex".format(pk)],
cwd=tmp_dir,
stdin=open(os.devnull, "r"),
stderr=open(os.devnull, "wb"),
stdout=open(os.devnull, "wb")
).wait()
response = HttpResponse(pdf, content_type="application/pdf")
response['Content-Disposition'] = "inline;filename=billing-{:d}.pdf".format(pk)
if error:
raise IOError("An error attempted while generating a billing:", error)
pdf = open("{}/billing-{}.pdf".format(tmp_dir, pk), 'rb').read()
response = HttpResponse(pdf, content_type="application/pdf")
response['Content-Disposition'] = "inline;filename=billing-{:d}.pdf".format(pk)
except IOError as e:
raise e
finally:
shutil.rmtree(tmp_dir)
return response

View File

@ -32,7 +32,7 @@ deps =
pep8-naming
pyflakes
commands =
flake8 apps/activity apps/api apps/logs apps/member apps/note
flake8 apps/activity apps/api apps/logs apps/member apps/note apps/treasury
[flake8]
# Ignore too many errors, should be reduced in the future