From ba2ea74a049f0167770a5d385261bb6e257c287c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=C3=A1=C5=A1=20Havelka?= Date: Sun, 4 Aug 2024 18:21:50 +0200 Subject: [PATCH] =?UTF-8?q?Ob=C3=A1lky=20do=20person=C3=A1ln=C3=ADho?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templates/personalni}/obalky.tex | 0 personalni/views.py | 31 +++++++++++++++++++ seminar/views/views_all.py | 30 ++---------------- soustredeni/views.py | 4 +-- 4 files changed, 35 insertions(+), 30 deletions(-) rename {seminar/templates/seminar/archiv => personalni/templates/personalni}/obalky.tex (100%) diff --git a/seminar/templates/seminar/archiv/obalky.tex b/personalni/templates/personalni/obalky.tex similarity index 100% rename from seminar/templates/seminar/archiv/obalky.tex rename to personalni/templates/personalni/obalky.tex diff --git a/personalni/views.py b/personalni/views.py index da3ed07e..a4c410be 100644 --- a/personalni/views.py +++ b/personalni/views.py @@ -1,3 +1,8 @@ +import tempfile +import subprocess +import shutil +import http + from django.shortcuts import render from django.urls import reverse from django.views import generic @@ -6,6 +11,7 @@ from django.views.decorators.debug import sensitive_post_parameters from django.views.generic.base import TemplateView from django.contrib.auth.models import User, Permission, Group, AnonymousUser from django.contrib.auth.mixins import LoginRequiredMixin +from django.contrib.staticfiles.finders import find from django.db import transaction from django.http import HttpResponse from django.utils import timezone @@ -53,6 +59,31 @@ class CojemamOrganizatoriStariView(generic.ListView): ).order_by('-organizuje_do') +def obalkyView(request, resitele): + if len(resitele) == 0: + return HttpResponse( + render(request, 'universal.html', { + 'title': 'Není pro koho vyrobit obálky.', + 'text': 'Právě ses pokusil/a vygenerovat obálky pro prázdnou množinu lidí. Můžeš to zkusit změnit, případně se zeptej webařů :-)', + }), + status=http.HTTPStatus.NOT_FOUND, + ) + + tex = render(request, 'personalni/obalky.tex', { + 'resitele': resitele + }).content + + with tempfile.TemporaryDirectory() as tempdir: + with open(tempdir+"/obalky.tex", "w") as texfile: + texfile.write(tex.decode()) + shutil.copy(find('seminar/lisak.pdf'), tempdir) + subprocess.call(["pdflatex", "obalky.tex"], cwd=tempdir) + + with open(tempdir+"/obalky.pdf", "rb") as pdffile: + response = HttpResponse(pdffile.read(), content_type='application/pdf') + return response + + class OrgoRozcestnikView(TemplateView): """ Zobrazí organizátorský rozcestník.""" diff --git a/seminar/views/views_all.py b/seminar/views/views_all.py index f838481c..9f115687 100644 --- a/seminar/views/views_all.py +++ b/seminar/views/views_all.py @@ -8,7 +8,6 @@ from django.http import Http404 from django.db.models import Q, Sum, Count from django.views.generic.base import RedirectView from django.core.exceptions import PermissionDenied -from django.contrib.staticfiles.finders import find import seminar.models as s import seminar.models as m @@ -26,18 +25,15 @@ from vysledkovky.utils import body_resitelu, VysledkovkaCisla, \ from datetime import date, datetime from itertools import groupby from collections import OrderedDict -import tempfile -import subprocess -import shutil import os import os.path as op from django.conf import settings import unicodedata import logging import time -import http from seminar.utils import aktivniResitele +import personalni.views # ze starého modelu #def verejna_temata(rocnik): @@ -485,31 +481,9 @@ class RocnikVysledkovkaView(RocnikView): def cisloObalkyView(request, rocnik, cislo): realne_cislo = get_object_or_404(Cislo, poradi=cislo, rocnik__rocnik=rocnik) - return obalkyView(request, aktivniResitele(realne_cislo)) + return personalni.views.obalkyView(request, aktivniResitele(realne_cislo)) -def obalkyView(request, resitele): - if len(resitele) == 0: - return HttpResponse( - render(request, 'universal.html', { - 'title': 'Není pro koho vyrobit obálky.', - 'text': 'Právě ses pokusil/a vygenerovat obálky pro prázdnou množinu lidí. Můžeš to zkusit změnit, případně se zeptej webařů :-)', - }), - status=http.HTTPStatus.NOT_FOUND, - ) - - tex = render(request,'seminar/archiv/obalky.tex', {'resitele': resitele}).content - - with tempfile.TemporaryDirectory() as tempdir: - with open(tempdir+"/obalky.tex","w") as texfile: - texfile.write(tex.decode()) - shutil.copy(find('seminar/lisak.pdf'), tempdir) - subprocess.call(["pdflatex","obalky.tex"], cwd = tempdir) - - with open(tempdir+"/obalky.pdf","rb") as pdffile: - response = HttpResponse(pdffile.read(), content_type='application/pdf') - return response - ### Tituly def TitulyViewRocnik(request, rocnik): diff --git a/soustredeni/views.py b/soustredeni/views.py index f150b6b8..4b8fb91f 100644 --- a/soustredeni/views.py +++ b/soustredeni/views.py @@ -11,7 +11,7 @@ import subprocess from pathlib import Path import http -from seminar.views import obalkyView +import personalni.views class SoustredeniListView(generic.ListView): @@ -34,7 +34,7 @@ class SoustredeniListView(generic.ListView): def soustredeniObalkyView(request, soustredeni): soustredeni = get_object_or_404(Soustredeni, id=soustredeni) - return obalkyView(request, soustredeni.ucastnici.all()) + return personalni.views.obalkyView(request, soustredeni.ucastnici.all()) class SoustredeniUcastniciBaseView(generic.ListView):