From e07b228dac9ef3389e7b0f3d91895e512826e9f3 Mon Sep 17 00:00:00 2001 From: "Tomas \"Jethro\" Pokorny" Date: Tue, 11 Oct 2016 18:18:39 +0200 Subject: [PATCH] Generovani stvrzenek ze soustredeni. --- seminar/static/seminar/stvrzenka.sty | 24 ++++++++++++++++++++++++ seminar/static/seminar/stvrzenky.tex | 13 +++++++++++++ seminar/urls.py | 1 + seminar/views.py | 28 +++++++++++++++++++++++++--- 4 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 seminar/static/seminar/stvrzenka.sty create mode 100644 seminar/static/seminar/stvrzenky.tex diff --git a/seminar/static/seminar/stvrzenka.sty b/seminar/static/seminar/stvrzenka.sty new file mode 100644 index 00000000..aa3122a1 --- /dev/null +++ b/seminar/static/seminar/stvrzenka.sty @@ -0,0 +1,24 @@ +\newcommand{\stvrzenka}[6]{ + \removelastskip\bigskip + \newpage + + \noindent\textbf{Dodavatel:}\hfill\textbf{Stvrzenka č. {\Large #1}} + + {Univerzita Karlova \\ + \indent Matematicko-fyzikální fakulta \\ + \indent OVVP, M\&M \\ + \indent Ke Karlovu 3, 120 00 Praha 2 \\ + \indent IČ: 00216208 DIČ: CZ00216208} + + \parindent=0pt + \parskip=0.2in + + \textbf{Celkem Kč:} 700,- \\ + \textbf{Slovy:} sedmset korun českých + + \textbf{Přijato od (firma, jméno, adresa):} #2 #3, #4, #5 #6 + + \textbf{Účel platby:} příspěvek na stravování + + ze dne \datum \hfill Přijal:\hspace{3cm} +} diff --git a/seminar/static/seminar/stvrzenky.tex b/seminar/static/seminar/stvrzenky.tex new file mode 100644 index 00000000..b3c21cfc --- /dev/null +++ b/seminar/static/seminar/stvrzenky.tex @@ -0,0 +1,13 @@ +\documentclass[12pt,a4paper]{article} +\usepackage[czech]{babel} +\usepackage[utf8]{inputenc} +\usepackage[margin=1in]{geometry} + +\usepackage{stvrzenka} + +\pagestyle{empty} +\begin{document} + +\input{ucastnici} + +\end{document} diff --git a/seminar/urls.py b/seminar/urls.py index 2c06e0fb..f7228b47 100644 --- a/seminar/urls.py +++ b/seminar/urls.py @@ -29,6 +29,7 @@ urlpatterns = [ name = 'seminar_seznam_soustredeni'), url(r'^soustredeni/probehlo/(?P\d+)/$', views.SoustredeniView.as_view(), name='seminar_soustredeni'), url(r'^soustredeni/(?P\d+)/seznam_ucastniku$', staff_member_required(views.SoustredeniUcastniciView.as_view()), name='soustredeni_ucastnici'), + url(r'^soustredeni/(?P\d+)/stvrzenky/(?P\d+)$', staff_member_required(views.soustredeniStvrzenkyExportView), name='soustredeni_stvrzenky'), url(r'^soustredeni/(?P\d+)/export_ucastniku$', staff_member_required(views.soustredeniUcastniciExportView), name='soustredeni_ucastnici_export'), url(r'^soustredeni/(?P\d+)/fotogalerie/', include('galerie.urls')), diff --git a/seminar/views.py b/seminar/views.py index 95df1a2e..fbf1a266 100644 --- a/seminar/views.py +++ b/seminar/views.py @@ -6,7 +6,7 @@ from django.core.urlresolvers import reverse from django.core.exceptions import PermissionDenied, ObjectDoesNotExist from django.views import generic from django.utils.translation import ugettext as _ -from django.http import Http404 +from django.http import Http404,HttpResponseBadRequest from django.db.models import Q from django.views.decorators.csrf import ensure_csrf_cookie from django.contrib.auth import authenticate, login @@ -530,7 +530,7 @@ class SoustredeniView(generic.DetailView): template_name = 'seminar/archiv/soustredeni.html' def soustredeniObalkyView(request,soustredeni): - soustredeni = Soustredeni.objects.filter(id = soustredeni)[0] + soustredeni = get_object_or_404(Soustredeni,id = soustredeni) return obalkyView(request,soustredeni.ucastnici.all()) class SoustredeniUcastniciView(generic.ListView): @@ -541,8 +541,30 @@ class SoustredeniUcastniciView(generic.ListView): self.soustredeni = get_object_or_404(Soustredeni, id=self.kwargs["soustredeni"]) return Soustredeni_Ucastnici.objects.filter(soustredeni=self.soustredeni).select_related('resitel') +def soustredeniStvrzenkyExportView(request,soustredeni,first_num): + first_num = int(first_num) + soustredeni = get_object_or_404(Soustredeni,id = soustredeni) + ucastnici = Resitel.objects.filter(soustredeni=soustredeni) + for (idx,u) in enumerate(ucastnici): + u.cislo_stvrzenky = first_num+idx; + tex = render(request,'seminar/soustredeni/ucastnici.tex', {'ucastnici': ucastnici, 'datum':soustredeni.datum_zacatku }).content + + tempdir = tempfile.mkdtemp() + with open(tempdir+"/ucastnici.tex","w") as texfile: + # Pokud TeX chce ISO Latin, tak se da encode nastavit + texfile.write(tex.decode("utf-8").encode("utf-8")) + shutil.copy(os.path.join(settings.STATIC_ROOT, 'seminar/stvrzenka.sty'),tempdir) + shutil.copy(os.path.join(settings.STATIC_ROOT, 'seminar/stvrzenky.tex'),tempdir) + subprocess.call(["pdfcslatex","stvrzenky.tex"],cwd = tempdir) + + with open(tempdir+"/stvrzenky.pdf","rb") as pdffile: + response = HttpResponse(pdffile.read(),content_type='application/pdf') + shutil.rmtree(tempdir) + return response + + def soustredeniUcastniciExportView(request,soustredeni): - soustredeni = Soustredeni.objects.filter(id = soustredeni)[0] + soustredeni = get_object_or_404(Soustredeni,id = soustredeni) ucastnici = Resitel.objects.filter(soustredeni=soustredeni) response = HttpResponse(content_type='text/csv') response['Content-Disposition'] = 'attachment; filename="ucastnici.csv"'