Browse Source

Obalky v Djangu.

remotes/origin/imagekit
parent
commit
b5a9d677e5
  1. 1603
      seminar/static/seminar/lisak.eps
  2. 103
      seminar/templates/seminar/archiv/obalky.tex
  3. 6
      seminar/templatetags/tex.py
  4. 1
      seminar/urls.py
  5. 45
      seminar/views.py

1603
seminar/static/seminar/lisak.eps

File diff suppressed because it is too large

103
seminar/templates/seminar/archiv/obalky.tex

@ -0,0 +1,103 @@
{% autoescape off %}
{% load staticfiles %}
{% load tex %}
\input czech.sty
\input epsf
\special{landscape}
\nopagenumbers
\hoffset=-1in
\voffset=-1in
\advance\voffset by 0.9cm
%nove pridano, aby to fungovalo...
\advance\hoffset by 6.5cm
\hsize=22cm
\vsize=16cm
\font\adrfonta=csssbx10 at 14pt
\font\adrfontb=csssbx10 at 12pt
\font\adrfontc=csss12
\font\tofont=csr12 at 16pt
\newdimen\fromskip
\newdimen\toskip
\fromskip=4.35cm
\toskip=13.2cm
\def\first{\relax}
\catcode`_=13
%\catcode`_=12
\def_{$\_$}
\advance\voffset by 2.5cm
\def\obalka#1#2#3#4#5#6#7{
\def\jmeno{#1}
\def\prijm{#2}
\def\skola{#3}
\def\popis{}
\def\first{}
\def\ulice{#4}
\def\PSC{#5}
\def\mesto{#6}
\def\stat{#7}
\vskip-4mm\vbox to 0pt{\hbox to 0pt{\hskip1.4cm\epsfysize=2.55cm\epsfbox{lisak.eps}\hss}\vss}
\baselineskip=13pt
\parindent=\fromskip
\line{\indent\adrfonta Časopis M\&M,\hfil}
\vskip3pt
\line{\indent\adrfontb OVVP UK MFF\hfil}
\vskip3pt
\line{\indent\adrfontc Ke Karlovu 3, 121 16 Praha 2\hfil}
\line{\indent\adrfontc Tel.: +420 221 911 235\hss}
\line{\indent\adrfontc mam@atrey.karlin.mff.cuni.cz\hfil}
\vskip6.15cm
\vbox to 0pt{\parindent=1.4cm\hsize=\toskip\advance\hsize by -1cm
\vbox to 60pt{\vfil} \popis\vss}
\parindent=\toskip
\baselineskip=18pt
\line{\indent\tofont\first\hfil}
\line{\indent\tofont\jmeno\ \prijm\hfil}
\ifx \skola \empty
{}
\else
\line{\indent\tofont\skola\hfil}
\fi
\line{\indent\tofont\ulice\hfil}
\line{\tofont\item{\PSC} \mesto\hfil}
\vskip5pt
\line{\indent\tofont\stat\hfil}
\vfil\eject
}
{% for r in resitele %}
{% spaceless %}
{% if r.zasilat == "do_skoly" %}
{% if r.stat == "CZ" %}
\obalka{{r.jmeno|sloz}}{{r.prijmeni|sloz}}{{r.skola.nazev|sloz}}{{r.skola.ulice|sloz}}{{r.skola.psc|sloz}}{{r.skola.mesto|sloz}}{{''|sloz}}
{% else %}
\obalka{{r.jmeno|sloz}}{{r.prijmeni|sloz}}{{r.skola.nazev|sloz}}{{r.skola.ulice|sloz}}{{r.skola.psc|sloz}}{{r.skola.mesto|sloz}}{{r.stat.name|sloz}}
{% endif %}
{% elif r.zasilat == "domu" %}
{% if r.stat == "CZ" %}
\obalka{{r.jmeno|sloz}}{{r.prijmeni|sloz}}{{''|sloz}}{{r.ulice|sloz}}{{r.psc|sloz}}{{r.mesto|sloz}}{{''|sloz}}
{% else %}
\obalka{{r.jmeno|sloz}}{{r.prijmeni|sloz}}{{''|sloz}}{{r.ulice|sloz}}{{r.psc|sloz}}{{r.mesto|sloz}}{{r.stat.name|sloz}}
{% endif %}
{% else %}
% zasilat: {{r.zasilat}}
%\obalka{{r.jmeno|sloz}}{{r.prijmeni|sloz}}{{''|sloz}}{{r.ulice|sloz}}{{r.psc|sloz}}{{r.mesto|sloz}}{{r.stat.name|sloz}}
{% endif %}
{% endspaceless %}
{% endfor %}
\bye
{% endautoescape %}

6
seminar/templatetags/tex.py

@ -0,0 +1,6 @@
from django import template
register = template.Library()
@register.filter(name='sloz')
def sloz(value):
return u"{{{}}}".format(value)

1
seminar/urls.py

@ -35,4 +35,5 @@ urlpatterns = patterns('',
url(r'^aesop-export/mam-sous-(?P<datum_zacatku>[\d-]+)\.csv$', export.ExportSousView.as_view(), name='seminar_export_sous'),
url(r'^aesop-export/index.csv$', export.ExportIndexView.as_view(), name='seminar_export_index'),
url(r'^cislo/(?P<rocnik>\d+).(?P<cislo>\d+)/vysledkovka.tex$', views.CisloVysledkovkaView.as_view(), name='seminar_cislo_vysledkovka'),
url(r'^cislo/(?P<rocnik>\d+).(?P<cislo>\d+)/obalky.pdf$',views.cisloObalkyView, name='seminar_cislo_obalky')
)

45
seminar/views.py

@ -2,6 +2,7 @@
from django.shortcuts import get_object_or_404, render
from django.http import HttpResponseRedirect
from django.http import HttpResponse
from django.core.urlresolvers import reverse
from django.views import generic
from django.utils.translation import ugettext as _
@ -13,6 +14,11 @@ from . import utils
from datetime import timedelta, date, datetime
from itertools import groupby
import tempfile
import subprocess
import shutil
import os
from django.conf import settings
def verejna_temata(rocnik):
@ -334,6 +340,45 @@ class RocnikVysledkovkaView(RocnikView):
content_type = 'text/plain; charset=UTF8'
#vypise na stranku textovy obsah vyTeXane vysledkovky k okopirovani
### Generovani obalek
class CisloObalkyStruct:
resitele = None
rocnik = None
problemy = None
def cisloObalkyView(request,rocnik,cislo):
letos = CisloObalkyStruct()
loni = CisloObalkyStruct()
letos.rocnik = Rocnik.objects.filter(rocnik = rocnik)
loni.rocnik = Rocnik.objects.filter(rocnik = int(rocnik)-1)
letos.problemy = Problem.objects.filter(cislo_zadani = Cislo.objects.filter(rocnik=letos.rocnik,cislo__lte = cislo))
loni.problemy = Problem.objects.filter(cislo_zadani = Cislo.objects.filter(rocnik=loni.rocnik))
letos.resitele = Resitel.objects.filter(reseni = Reseni.objects.filter(problem=letos.problemy)).distinct()
loni.resitele = Resitel.objects.filter(reseni = Reseni.objects.filter(problem=loni.problemy)).distinct()
if int(cislo) > 3:
resitele = letos.resitele
else:
resitele = list(letos.resitele) + list(loni.resitele)
return obalkyView(request,resitele)
def obalkyView(request,resitele):
tex = render(request,'seminar/archiv/obalky.tex', {'resitele': resitele}).content
tempdir = tempfile.mkdtemp()
with open(tempdir+"/obalky.tex","w") as texfile:
texfile.write(tex.decode("utf-8").encode("utf-8"))
shutil.copy(os.path.join(settings.STATIC_ROOT, 'seminar/lisak.eps'),tempdir)
subprocess.call(["csplain","obalky.tex"],cwd = tempdir)
subprocess.call(["dvipdf","obalky.dvi"],cwd = tempdir)
with open(tempdir+"/obalky.pdf","rb") as pdffile:
response = HttpResponse(pdffile.read(),content_type='application/pdf')
return response
### Soustredeni

Loading…
Cancel
Save