From e07b228dac9ef3389e7b0f3d91895e512826e9f3 Mon Sep 17 00:00:00 2001 From: "Tomas \"Jethro\" Pokorny" Date: Tue, 11 Oct 2016 18:18:39 +0200 Subject: [PATCH 1/7] 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"' From c6b68505572eb96001d689262b93f3e58554aeab Mon Sep 17 00:00:00 2001 From: "Tomas \"Jethro\" Pokorny" Date: Tue, 11 Oct 2016 18:36:55 +0200 Subject: [PATCH 2/7] Odkaz na stvrzenky ze seznamu. --- seminar/templates/seminar/soustredeni/seznam_soustredeni.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/seminar/templates/seminar/soustredeni/seznam_soustredeni.html b/seminar/templates/seminar/soustredeni/seznam_soustredeni.html index 6176b3e9..18447a67 100644 --- a/seminar/templates/seminar/soustredeni/seznam_soustredeni.html +++ b/seminar/templates/seminar/soustredeni/seznam_soustredeni.html @@ -49,7 +49,8 @@ Vygenerovat obálky pro účastníky
Seznam účastníků - HTML tabulka pro tisk, - CSV + CSV
+ Stvrzenky (42 v URL nahraďte prvním číslem z rozsahu) {% endif %} From 6a34a398f07cf3496b66e47a314f0cd255255043 Mon Sep 17 00:00:00 2001 From: "Tomas \"Jethro\" Pokorny" Date: Sat, 15 Oct 2016 19:02:36 +0200 Subject: [PATCH 3/7] Zapomenuty template. --- seminar/templates/seminar/soustredeni/ucastnici.tex | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 seminar/templates/seminar/soustredeni/ucastnici.tex diff --git a/seminar/templates/seminar/soustredeni/ucastnici.tex b/seminar/templates/seminar/soustredeni/ucastnici.tex new file mode 100644 index 00000000..a39885a6 --- /dev/null +++ b/seminar/templates/seminar/soustredeni/ucastnici.tex @@ -0,0 +1,5 @@ +{% 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 %} From 1c43c3b9f47e5814a99d3067c1c3f01df14da118 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Koci=C3=A1n?= Date: Fri, 28 Oct 2016 12:19:42 +0200 Subject: [PATCH 4/7] =?UTF-8?q?Korektury:=20oprava=20p=C5=99ekryv=C5=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- korektury/templates/korektury/opraf.html | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/korektury/templates/korektury/opraf.html b/korektury/templates/korektury/opraf.html index 04cfc2de..6a92f28c 100644 --- a/korektury/templates/korektury/opraf.html +++ b/korektury/templates/korektury/opraf.html @@ -7,7 +7,7 @@ Korektury {{pdf.nazev}} - +

Korektury {{pdf.nazev}}

{% if pdf.status = 'zanaseni' %}

Probíhá zanášení korektur, zvažte, zda chcete přidávat nové

{% endif %} {% if pdf.status = 'zastarale' %}

Toto PDF je již zastaralé, nepřidávejte nové korektury

{% endif %} @@ -192,9 +192,11 @@ ["img-{{s.strana}}", [{% for o in s.op_id %}["op{{o.id}}",{{o.x}},{{o.y}}],{% endfor %}[]]], {% endfor %} []] - for (var i=0;i Date: Sun, 6 Nov 2016 16:39:45 +0100 Subject: [PATCH 5/7] =?UTF-8?q?Korektury:=20po=C5=A1li=20mail=20i=20autoro?= =?UTF-8?q?vi=20okom.=20korektury?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- korektury/views.py | 19 +++++++++++++++---- mamweb/settings_common.py | 10 +++++++--- mamweb/settings_prod.py | 2 ++ mamweb/settings_test.py | 5 +---- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/korektury/views.py b/korektury/views.py index 5eb42bd1..70cfaf6e 100644 --- a/korektury/views.py +++ b/korektury/views.py @@ -135,21 +135,32 @@ class KorekturyView(generic.TemplateView): # Prijemci e-mailu emails = set() + # e-mail autora korektury email = oprava.autor.user.email - # nalezeni e-mailu na organizatory komentaru + if email: + emails.add(email) + + # nalezeni e-mailu na autory komentaru for komentar in oprava.komentar_set.all(): - email = komentar.autor.user.email - if email: - emails.add(email) + email_komentujiciho = komentar.autor.user.email + if email_komentujiciho: + emails.add(email_komentujiciho) + # zodpovedny org if oprava.pdf.org: email_zobpovedny = oprava.pdf.org.user.email if email_zobpovedny: emails.add(email_zobpovedny) + # odstran e-mail autora opravy + email = autor.user.email if email: emails.discard(email) + if not settings.SEND_EMAIL_NOTIFICATIONS: + print "Poslal bych upozornění na tyto adresy: ", " ".join(emails) + return + send_mail(subject, text, from_email, list(emails)) def get_context_data(self, **kwargs): diff --git a/mamweb/settings_common.py b/mamweb/settings_common.py index a1025b07..ad2b7fd7 100644 --- a/mamweb/settings_common.py +++ b/mamweb/settings_common.py @@ -242,6 +242,10 @@ LOGGING = { SEMINAR_RESENI_DIR = os.path.join('reseni') SEMINAR_KONFERY_DIR = os.path.join('konfery') -KOREKTURY_PDF_DIR = os.path.join('korektury','pdf') -KOREKTURY_IMG_DIR = os.path.join('korektury','img') -CISLO_IMG_DIR = os.path.join('cislo','img') +KOREKTURY_PDF_DIR = os.path.join('korektury', 'pdf') +KOREKTURY_IMG_DIR = os.path.join('korektury', 'img') +CISLO_IMG_DIR = os.path.join('cislo', 'img') + + +# E-MAIL NOTIFICATIONS +SEND_EMAIL_NOTIFICATIONS = False diff --git a/mamweb/settings_prod.py b/mamweb/settings_prod.py index b56a9380..8b75ce74 100644 --- a/mamweb/settings_prod.py +++ b/mamweb/settings_prod.py @@ -67,3 +67,5 @@ LOGGING['loggers']['']['handlers'] = ['console', 'mail_admins'] LOGGING['loggers']['django']['handlers'] = ['console', 'mail_admins'] +# E-MAIL NOTIFICATIONS +SEND_EMAIL_NOTIFICATIONS = True diff --git a/mamweb/settings_test.py b/mamweb/settings_test.py index 3d1b0010..6ffd42b8 100644 --- a/mamweb/settings_test.py +++ b/mamweb/settings_test.py @@ -10,7 +10,7 @@ import os.path # # Import common settings -from .settings_common import * +from .settings_common import LOGGING # Quick-start development settings - unsuitable for production @@ -63,6 +63,3 @@ CSRF_COOKIE_SECURE = True LOGGING['loggers']['']['handlers'] = ['console', 'mail_admins'] LOGGING['loggers']['django']['handlers'] = ['console', 'mail_admins'] - - - From d34f75e455b09c1fe00bde7aea2251fd5181e28c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Koci=C3=A1n?= Date: Sun, 6 Nov 2016 16:39:45 +0100 Subject: [PATCH 6/7] =?UTF-8?q?Korektury:=20po=C5=A1li=20mail=20i=20autoro?= =?UTF-8?q?vi=20okom.=20korektury?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- korektury/views.py | 19 +++++++++++++++---- mamweb/settings_common.py | 10 +++++++--- mamweb/settings_prod.py | 2 ++ mamweb/settings_test.py | 5 +---- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/korektury/views.py b/korektury/views.py index 5eb42bd1..70cfaf6e 100644 --- a/korektury/views.py +++ b/korektury/views.py @@ -135,21 +135,32 @@ class KorekturyView(generic.TemplateView): # Prijemci e-mailu emails = set() + # e-mail autora korektury email = oprava.autor.user.email - # nalezeni e-mailu na organizatory komentaru + if email: + emails.add(email) + + # nalezeni e-mailu na autory komentaru for komentar in oprava.komentar_set.all(): - email = komentar.autor.user.email - if email: - emails.add(email) + email_komentujiciho = komentar.autor.user.email + if email_komentujiciho: + emails.add(email_komentujiciho) + # zodpovedny org if oprava.pdf.org: email_zobpovedny = oprava.pdf.org.user.email if email_zobpovedny: emails.add(email_zobpovedny) + # odstran e-mail autora opravy + email = autor.user.email if email: emails.discard(email) + if not settings.SEND_EMAIL_NOTIFICATIONS: + print "Poslal bych upozornění na tyto adresy: ", " ".join(emails) + return + send_mail(subject, text, from_email, list(emails)) def get_context_data(self, **kwargs): diff --git a/mamweb/settings_common.py b/mamweb/settings_common.py index a1025b07..ad2b7fd7 100644 --- a/mamweb/settings_common.py +++ b/mamweb/settings_common.py @@ -242,6 +242,10 @@ LOGGING = { SEMINAR_RESENI_DIR = os.path.join('reseni') SEMINAR_KONFERY_DIR = os.path.join('konfery') -KOREKTURY_PDF_DIR = os.path.join('korektury','pdf') -KOREKTURY_IMG_DIR = os.path.join('korektury','img') -CISLO_IMG_DIR = os.path.join('cislo','img') +KOREKTURY_PDF_DIR = os.path.join('korektury', 'pdf') +KOREKTURY_IMG_DIR = os.path.join('korektury', 'img') +CISLO_IMG_DIR = os.path.join('cislo', 'img') + + +# E-MAIL NOTIFICATIONS +SEND_EMAIL_NOTIFICATIONS = False diff --git a/mamweb/settings_prod.py b/mamweb/settings_prod.py index b56a9380..8b75ce74 100644 --- a/mamweb/settings_prod.py +++ b/mamweb/settings_prod.py @@ -67,3 +67,5 @@ LOGGING['loggers']['']['handlers'] = ['console', 'mail_admins'] LOGGING['loggers']['django']['handlers'] = ['console', 'mail_admins'] +# E-MAIL NOTIFICATIONS +SEND_EMAIL_NOTIFICATIONS = True diff --git a/mamweb/settings_test.py b/mamweb/settings_test.py index 3d1b0010..7ca1c627 100644 --- a/mamweb/settings_test.py +++ b/mamweb/settings_test.py @@ -10,7 +10,7 @@ import os.path # # Import common settings -from .settings_common import * +from .settings_common import * # zatim nutne, casem snad vyresime # noqa # Quick-start development settings - unsuitable for production @@ -63,6 +63,3 @@ CSRF_COOKIE_SECURE = True LOGGING['loggers']['']['handlers'] = ['console', 'mail_admins'] LOGGING['loggers']['django']['handlers'] = ['console', 'mail_admins'] - - - From 7a4ea302a4c44299c8e5f8c0347c1923e3064848 Mon Sep 17 00:00:00 2001 From: "Tomas \"Jethro\" Pokorny" Date: Tue, 8 Nov 2016 08:46:53 +0100 Subject: [PATCH 7/7] Oprava bugu pri generovani stvrzenek --- seminar/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/seminar/views.py b/seminar/views.py index fbf1a266..141e9492 100644 --- a/seminar/views.py +++ b/seminar/views.py @@ -555,7 +555,8 @@ def soustredeniStvrzenkyExportView(request,soustredeni,first_num): 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) + subprocess.call(["cslatex","stvrzenky.tex"],cwd = tempdir) + subprocess.call(["dvipdf","stvrzenky.dvi"],cwd = tempdir) with open(tempdir+"/stvrzenky.pdf","rb") as pdffile: response = HttpResponse(pdffile.read(),content_type='application/pdf')