Browse Source

Generovani stvrzenek ze soustredeni.

remotes/origin/fix-prekryvani-korektur
parent
commit
e07b228dac
  1. 24
      seminar/static/seminar/stvrzenka.sty
  2. 13
      seminar/static/seminar/stvrzenky.tex
  3. 1
      seminar/urls.py
  4. 28
      seminar/views.py

24
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}
}

13
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}

1
seminar/urls.py

@ -29,6 +29,7 @@ urlpatterns = [
name = 'seminar_seznam_soustredeni'), name = 'seminar_seznam_soustredeni'),
url(r'^soustredeni/probehlo/(?P<soustredeni>\d+)/$', views.SoustredeniView.as_view(), name='seminar_soustredeni'), url(r'^soustredeni/probehlo/(?P<soustredeni>\d+)/$', views.SoustredeniView.as_view(), name='seminar_soustredeni'),
url(r'^soustredeni/(?P<soustredeni>\d+)/seznam_ucastniku$', staff_member_required(views.SoustredeniUcastniciView.as_view()), name='soustredeni_ucastnici'), url(r'^soustredeni/(?P<soustredeni>\d+)/seznam_ucastniku$', staff_member_required(views.SoustredeniUcastniciView.as_view()), name='soustredeni_ucastnici'),
url(r'^soustredeni/(?P<soustredeni>\d+)/stvrzenky/(?P<first_num>\d+)$', staff_member_required(views.soustredeniStvrzenkyExportView), name='soustredeni_stvrzenky'),
url(r'^soustredeni/(?P<soustredeni>\d+)/export_ucastniku$', staff_member_required(views.soustredeniUcastniciExportView), name='soustredeni_ucastnici_export'), url(r'^soustredeni/(?P<soustredeni>\d+)/export_ucastniku$', staff_member_required(views.soustredeniUcastniciExportView), name='soustredeni_ucastnici_export'),
url(r'^soustredeni/(?P<soustredeni>\d+)/fotogalerie/', include('galerie.urls')), url(r'^soustredeni/(?P<soustredeni>\d+)/fotogalerie/', include('galerie.urls')),

28
seminar/views.py

@ -6,7 +6,7 @@ from django.core.urlresolvers import reverse
from django.core.exceptions import PermissionDenied, ObjectDoesNotExist from django.core.exceptions import PermissionDenied, ObjectDoesNotExist
from django.views import generic from django.views import generic
from django.utils.translation import ugettext as _ 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.db.models import Q
from django.views.decorators.csrf import ensure_csrf_cookie from django.views.decorators.csrf import ensure_csrf_cookie
from django.contrib.auth import authenticate, login from django.contrib.auth import authenticate, login
@ -530,7 +530,7 @@ class SoustredeniView(generic.DetailView):
template_name = 'seminar/archiv/soustredeni.html' template_name = 'seminar/archiv/soustredeni.html'
def soustredeniObalkyView(request,soustredeni): 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()) return obalkyView(request,soustredeni.ucastnici.all())
class SoustredeniUcastniciView(generic.ListView): class SoustredeniUcastniciView(generic.ListView):
@ -541,8 +541,30 @@ class SoustredeniUcastniciView(generic.ListView):
self.soustredeni = get_object_or_404(Soustredeni, id=self.kwargs["soustredeni"]) self.soustredeni = get_object_or_404(Soustredeni, id=self.kwargs["soustredeni"])
return Soustredeni_Ucastnici.objects.filter(soustredeni=self.soustredeni).select_related('resitel') 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): 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) ucastnici = Resitel.objects.filter(soustredeni=soustredeni)
response = HttpResponse(content_type='text/csv') response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="ucastnici.csv"' response['Content-Disposition'] = 'attachment; filename="ucastnici.csv"'

Loading…
Cancel
Save