From 2c9c1dc8e17c8b93f5bb10fe9da0c5524054da12 Mon Sep 17 00:00:00 2001 From: Kristyna Petrlikova Date: Mon, 14 Nov 2022 23:08:02 +0100 Subject: [PATCH 1/2] =?UTF-8?q?P=C5=99id=C3=A1n=C3=AD=20=C3=BA=C4=8Dastnic?= =?UTF-8?q?k=C3=A9ho=20poplatku=20v=20nastaven=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/migrations/0108_nastaveni_cena_sous.py | 18 ++++++++++++++++++ seminar/models/tvorba.py | 4 ++++ 2 files changed, 22 insertions(+) create mode 100644 seminar/migrations/0108_nastaveni_cena_sous.py diff --git a/seminar/migrations/0108_nastaveni_cena_sous.py b/seminar/migrations/0108_nastaveni_cena_sous.py new file mode 100644 index 00000000..112b2a6c --- /dev/null +++ b/seminar/migrations/0108_nastaveni_cena_sous.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.16 on 2022-11-14 20:51 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('seminar', '0107_zmrazenavysledkovka'), + ] + + operations = [ + migrations.AddField( + model_name='nastaveni', + name='cena_sous', + field=models.IntegerField(default=1000, verbose_name='Účastnický poplatek za soustředění'), + ), + ] diff --git a/seminar/models/tvorba.py b/seminar/models/tvorba.py index 57813f39..7e04b213 100644 --- a/seminar/models/tvorba.py +++ b/seminar/models/tvorba.py @@ -718,6 +718,10 @@ class Nastaveni(SingletonModel): aktualni_cislo = models.ForeignKey(Cislo, verbose_name='Aktuální číslo', null=False, on_delete=models.PROTECT) + cena_sous = models.IntegerField(null=False, + verbose_name="Účastnický poplatek za soustředění", + default=1000) + @property def aktualni_rocnik(self): return self.aktualni_cislo.rocnik -- 2.39.5 From c08e6c87f5c0b5a5f9b2467ee661cfabef2be6a5 Mon Sep 17 00:00:00 2001 From: Kristyna Petrlikova Date: Mon, 14 Nov 2022 23:16:24 +0100 Subject: [PATCH 2/2] =?UTF-8?q?P=C5=99eps=C3=A1n=C3=AD=20stvrzenek=20do=20?= =?UTF-8?q?templates?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/static/seminar/stvrzenky.tex | 25 ------------- .../templates/soustredeni/stvrzenky.tex | 37 +++++++++++++++++++ .../templates/soustredeni/ucastnici.tex | 5 --- soustredeni/views.py | 26 ++++++------- 4 files changed, 49 insertions(+), 44 deletions(-) delete mode 100644 seminar/static/seminar/stvrzenky.tex create mode 100644 soustredeni/templates/soustredeni/stvrzenky.tex delete mode 100644 soustredeni/templates/soustredeni/ucastnici.tex diff --git a/seminar/static/seminar/stvrzenky.tex b/seminar/static/seminar/stvrzenky.tex deleted file mode 100644 index 28eab580..00000000 --- a/seminar/static/seminar/stvrzenky.tex +++ /dev/null @@ -1,25 +0,0 @@ -\input opmac -\chyph -\nopagenumbers -\parindent=0pt - -\def\castka{1000} - -\newread\data -\openin\data=/dev/stdin -\read\data to\termin -\read\data to\misto - -\loop - \read\data to\ucastnik - \unless\ifeof\data - \vbox{\picw=2cm\inspic logomm.pdf \smallskip\hrule\medskip - Potvrzujeme, že \ucastnik se zúčastnil(a) soustředění Korespondenčního semináře M\&M konaného % \ucastnik má na konci mezeru - v~termínu \termin a že zaplatil(a) účastnický poplatek ve výši $\sim$\castka Kč$\sim$. % \termin též - \bigskip - \the\day.~\the\month.~\the\year, \misto\hfill Přijal(a): \hbox to 4cm{\hrulefill} - \bigskip - } -\repeat - -\bye diff --git a/soustredeni/templates/soustredeni/stvrzenky.tex b/soustredeni/templates/soustredeni/stvrzenky.tex new file mode 100644 index 00000000..78752866 --- /dev/null +++ b/soustredeni/templates/soustredeni/stvrzenky.tex @@ -0,0 +1,37 @@ +{% autoescape off %} +{% load static %} +{% load tex %} +\documentclass[11pt,a4paper]{article} +\usepackage[left=0.75in, right=0.75in,top=0.5in,bottom=0.5in]{geometry} +\usepackage[T1]{fontenc} +\usepackage[utf8]{inputenc} +\usepackage[czech]{babel} +\usepackage{graphicx} +\begin{document} +\pagenumbering{gobble} +\parindent=0pt + +\def\stvrzenka#1#2{ + \vbox{% + \includegraphics[width=2cm]{logomm.pdf} + \smallskip\hrule\medskip + {% with soustredeni as s %} + Potvrzujeme, že #1 #2 se zúčastnil(a) soustředění Korespondenčního semináře M\&M konaného + v~termínu {{s.datum_zacatku|date:"j.~n.~Y"|sloz}} -- + {{s.datum_konce|date:"j.~n.~Y"|sloz}} a~že zaplatil(a) účastnický poplatek ve + výši $\sim${{castka|sloz}}Kč$\sim$. + + \bigskip + {{s.datum_zacatku|date:"j.~n.~Y"|sloz}}, {{s.misto|sloz}} \hfill Přijal(a): \hbox to 4cm{\hrulefill} + \bigskip + } + {% endwith %} +} + +{% for u in ucastnici %} + {% with o=u.osoba %} + \stvrzenka{{o.jmeno|sloz}}{{o.prijmeni|sloz}} + {% endwith %} +{% endfor %} +\end{document} +{% endautoescape %} diff --git a/soustredeni/templates/soustredeni/ucastnici.tex b/soustredeni/templates/soustredeni/ucastnici.tex deleted file mode 100644 index a39885a6..00000000 --- a/soustredeni/templates/soustredeni/ucastnici.tex +++ /dev/null @@ -1,5 +0,0 @@ -{% load tex %} -\newcommand{\datum}{{datum|date:"j. n. Y"|sloz}} -{% for u in ucastnici %} -\stvrzenka{{u.cislo_stvrzenky|sloz}}{{u.jmeno|sloz}}{{u.prijmeni|sloz}}{{u.ulice|sloz}}{{u.psc|sloz}}{{u.mesto|sloz}} -{% endfor %} diff --git a/soustredeni/views.py b/soustredeni/views.py index 54c34fbe..e5ae2992 100644 --- a/soustredeni/views.py +++ b/soustredeni/views.py @@ -1,8 +1,9 @@ -from django.shortcuts import get_object_or_404 +from django.shortcuts import get_object_or_404, render from django.http import HttpResponse from django.views import generic from django.conf import settings -from seminar.models import Soustredeni, Resitel, Soustredeni_Ucastnici # Tohle je stare a chceme se toho zbavit. Pouzivejte s.ToCoChci +from django.contrib.staticfiles.finders import find +from seminar.models import Soustredeni, Resitel, Soustredeni_Ucastnici, Nastaveni # Tohle je stare a chceme se toho zbavit. Pouzivejte s.ToCoChci import csv import tempfile import shutil @@ -62,20 +63,17 @@ def soustredeniUcastniciExportView(request, soustredeni): def soustredeniStvrzenkyView(request, soustredeni): soustredeni = get_object_or_404(Soustredeni, id=soustredeni) ucastnici = Resitel.objects.filter(soustredeni=soustredeni) + castka = Nastaveni.get_solo().cena_sous + tex = render(request, 'soustredeni/stvrzenky.tex', {'ucastnici': ucastnici, 'soustredeni': soustredeni, 'castka': castka}).content - static = Path(settings.STATIC_ROOT) tempdir = Path(tempfile.mkdtemp()) - shutil.copy(static / 'images/logomm.pdf', tempdir) - shutil.copy(static / 'seminar/stvrzenky.tex', tempdir) - subprocess.run( - ['pdfcsplain', 'stvrzenky.tex'], - cwd=tempdir, - encoding='utf-8', - input=f'{soustredeni.datum_zacatku.strftime("%-d.~%-m.~%Y")} -- {soustredeni.datum_konce.strftime("%-d.~%-m.~%Y")}\n{soustredeni.misto}\n' - + '\n'.join([f'{u.osoba.jmeno} {u.osoba.prijmeni}' for u in ucastnici]) - ) - - with open(tempdir / 'stvrzenky.pdf', 'rb') as pdffile: + with open(tempdir / "stvrzenky.tex", "w") as texfile: + texfile.write(tex.decode()) + + shutil.copy(find('images/logomm.pdf'), tempdir) + subprocess.call(["pdflatex", "stvrzenky.tex"], cwd = tempdir, stdout=subprocess.DEVNULL) + + with open(tempdir / "stvrzenky.pdf", "rb") as pdffile: response = HttpResponse(pdffile.read(), content_type='application/pdf') shutil.rmtree(tempdir) return response -- 2.39.5