+
+ {# Projdi vsechny prednasky #}
+ {% for prednaska in object_list %}
+ -
+ {{prednaska.nazev}} ({{prednaska.obor}},{{prednaska.obtiznost}}) - {{prednaska.org}}
+
+ {% endfor %}
+
+{% endblock %}
+
diff --git a/prednasky/templates/prednasky/seznam_prednasek_export.txt b/prednasky/templates/prednasky/seznam_prednasek_export.txt
new file mode 100644
index 00000000..2defc91e
--- /dev/null
+++ b/prednasky/templates/prednasky/seznam_prednasek_export.txt
@@ -0,0 +1,21 @@
+{% block content %}
+{% spaceless %}
+{% for hlas in hlasovani %}
+hlas({{hlas.ucastnik}},{{hlas.prednaska.id}},{{hlas.body}})
+{% endfor %}
+{% for prednaska in prednasky %}
+prednaska({{prednaska.id}},{{prednaska.org.id}},{{prednaska.obtiznost}},{{prednaska.obor}})
+{% endfor %}
+{% for org in orgove %}
+org({{org.id}},4,0,15)
+{% endfor %}
+{% for org in orgove %}
+{{org.id}};{{org}}
+{% endfor %}
+{% for prednaska in prednasky %}
+{{prednaska.id}};{{prednaska.nazev}};{{prednaska.org.id}}
+{{prednaska.body}}
+{% endfor %}
+{% endspaceless %}
+{% endblock %}
+
diff --git a/prednasky/urls.py b/prednasky/urls.py
new file mode 100644
index 00000000..013db150
--- /dev/null
+++ b/prednasky/urls.py
@@ -0,0 +1,15 @@
+from django.conf.urls import * # NOQA
+from django.conf.urls import patterns, url
+from django.contrib.auth.decorators import user_passes_test
+from . import views
+
+staff_member_required = user_passes_test(lambda u: u.is_staff)
+
+urlpatterns = [
+ url(r'^prednasky/$', views.newPrednaska),
+ url(r'^prednasky/hotovo$', views.Prednaska_hotovo),
+ url(r'^prednasky/metaseznam_prednasek$', staff_member_required(views.MetaSeznamListView.as_view()), name='metaseznam-list'),
+ url(r'^prednasky/seznam_prednasek/(?P\d+)/$', staff_member_required(views.SeznamListView.as_view()), name='seznam-list'),
+ url(r'^prednasky/seznam_prednasek/(?P\d+)/export$', staff_member_required(views.SeznamExportView), name='seznam-export'),
+# url(r'^korektury/help/', staff_member_required(views.KorekturyHelpView.as_view()), name='korektury-help'),
+]
diff --git a/prednasky/views.py b/prednasky/views.py
index ede98aee..e25af366 100644
--- a/prednasky/views.py
+++ b/prednasky/views.py
@@ -1,4 +1,5 @@
-from django.shortcuts import render
+from django.shortcuts import render,get_object_or_404
+from django.views import generic
from prednasky.forms import NewPrednaskyForm
from prednasky.models import Seznam, Hlasovani, Prednaska
from django.shortcuts import HttpResponseRedirect
@@ -24,7 +25,7 @@ def newPrednaska(request):
hlasovani.prednaska = Prednaska.objects.filter(pk = int(i[1:]))[0]
hlasovani.body = int(request.POST[i])
hlasovani.ucastnik = jmeno
- hlasovani.seznam = seznam
+ hlasovani.seznam = seznam
hlasovani.save()
# presmerovani na prave vzniklou galerii
@@ -40,6 +41,36 @@ def newPrednaska(request):
def Prednaska_hotovo(request):
return render(request, 'prednasky/hotovo.html')
-
-# Create your views here.
+class MetaSeznamListView(generic.ListView):
+ model = Seznam
+ template_name = 'prednasky/metaseznam_prednasek.html'
+
+class SeznamListView(generic.ListView):
+ template_name = 'prednasky/seznam_prednasek.html'
+ def get_queryset(self):
+ print self.kwargs
+ self.seznam = get_object_or_404(Seznam,id=self.kwargs["seznam"])
+ return Prednaska.objects.filter(seznamy = self.seznam)
+
+
+def SeznamExportView(request,seznam):
+ seznam_obj = Seznam.objects.get(id=seznam)
+ hlasovani = Hlasovani.objects.filter(seznam=seznam)
+ prednasky = Prednaska.objects.filter(seznamy=seznam)
+ orgove = set(map(lambda x:x.org,prednasky))
+ ucastnici = list(set(map(lambda x:x.ucastnik,hlasovani)))
+
+ for p in prednasky:
+ p.body = []
+ for u in ucastnici:
+ p.body.append(hlasovani.get(ucastnik=u,prednaska=p).body)
+
+ for h in hlasovani:
+ h.ucastnik = hash(h.ucastnik)
+
+ return render(request, 'prednasky/seznam_prednasek_export.txt',
+ {"hlasovani":hlasovani,"prednasky":prednasky,"orgove":orgove},
+ content_type="text/plain")
+
+
diff --git a/seminar/admin.py b/seminar/admin.py
index 45cc5fb7..3a61d461 100644
--- a/seminar/admin.py
+++ b/seminar/admin.py
@@ -11,7 +11,7 @@ from django.db import models
from django.contrib.auth.models import User
-from seminar.models import Skola, Resitel, Rocnik, Cislo, Problem, Reseni, PrilohaReseni, Nastaveni, Soustredeni, Soustredeni_Ucastnici, Soustredeni_Organizatori, Novinky, Organizator, Prispevek, Pohadka
+from seminar.models import Skola, Resitel, Rocnik, Cislo, Problem, Reseni, PrilohaReseni, Nastaveni, Soustredeni, Soustredeni_Ucastnici, Soustredeni_Organizatori, Novinky, Organizator, Prispevek, Pohadka, Konfera
from autocomplete_light import shortcuts as autocomplete_light
@@ -181,6 +181,7 @@ class Soustredeni_UcastniciInline(admin.TabularInline):
qs = super(Soustredeni_UcastniciInline, self).get_queryset(request)
return qs.select_related('resitel', 'soustredeni')
+
class Soustredeni_OrganizatoriInline(admin.TabularInline):
form = autocomplete_light.modelform_factory(Soustredeni_Organizatori, autocomplete_fields=['organizator'], fields=['organizator'],)
model = Soustredeni_Organizatori
@@ -468,6 +469,20 @@ class SoustredeniAdmin(VersionAdmin):
admin.site.register(Soustredeni, SoustredeniAdmin)
+### Konfery
+class KonferaAdminForm(forms.ModelForm):
+ class Meta:
+ model=Konfera
+ exclude = []
+
+class KonferaAdmin(VersionAdmin):
+ form = KonferaAdminForm
+ list_filter = ['soustredeni']
+ list_display = ['nazev','soustredeni','organizator','typ_prezentace']
+# inlines = [Konfera_UcastniciInline]
+
+admin.site.register(Konfera,KonferaAdmin)
+
### Novinky
class NovinkyAdminForm(forms.ModelForm):
diff --git a/seminar/migrations/0042_auto_20161005_0847.py b/seminar/migrations/0042_auto_20161005_0847.py
new file mode 100644
index 00000000..27930952
--- /dev/null
+++ b/seminar/migrations/0042_auto_20161005_0847.py
@@ -0,0 +1,31 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+import seminar.models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('seminar', '0041_konfery'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='konfera',
+ name='materialy',
+ field=models.FileField(help_text='Dal\u0161\xed materi\xe1ly ke konfe\u0159e zabalen\xe9 do jednoho souboru', upload_to=seminar.models.generate_filename_konfera, verbose_name='materialy', blank=True),
+ ),
+ migrations.AlterField(
+ model_name='konfera',
+ name='prezentace',
+ field=models.FileField(help_text='Prezentace nebo fotka posteru', upload_to=seminar.models.generate_filename_konfera, verbose_name='prezentace', blank=True),
+ ),
+ migrations.AlterField(
+ model_name='konfera',
+ name='prispevek',
+ field=models.ForeignKey(related_name='konfery', on_delete=django.db.models.deletion.SET_NULL, blank=True, to='seminar.Problem', help_text='\xda\u010dastnick\xfd p\u0159\xedp\u011bvek o konfe\u0159e', null=True, verbose_name='p\u0159\xedsp\u011bvek do \u010d\xedsla'),
+ ),
+ ]
diff --git a/seminar/models.py b/seminar/models.py
index 4c8fc3f0..5a478feb 100644
--- a/seminar/models.py
+++ b/seminar/models.py
@@ -859,7 +859,7 @@ class Konfera(models.Model):
org_poznamka = models.TextField(u'neveřejná poznámka', blank=True,
help_text=u'Neveřejná poznámka ke konfeře(plain text)')
prispevek = models.ForeignKey(Problem, verbose_name=u'příspěvek do čísla', related_name='konfery',
- help_text=u'Účastnický přípěvek o konfeře',on_delete = models.SET_NULL, null=True)
+ help_text=u'Účastnický přípěvek o konfeře',on_delete = models.SET_NULL, null=True, blank=True)
TYP_VELETRH = 'veletrh'
TYP_PREZENTACE = 'prezentace'
TYP_CHOICES = [
@@ -868,9 +868,9 @@ class Konfera(models.Model):
]
typ_prezentace = models.CharField(u'typ prezentace', max_length=16, choices=TYP_CHOICES, blank=False, default=TYP_VELETRH)
prezentace = models.FileField(u'prezentace',help_text = u'Prezentace nebo fotka posteru',
- upload_to = generate_filename_konfera)
+ upload_to = generate_filename_konfera, blank=True)
materialy = models.FileField(u'materialy',help_text = u'Další materiály ke konfeře zabalené do jednoho souboru',
- upload_to = generate_filename_konfera)
+ upload_to = generate_filename_konfera, blank=True)
def __str__(self):
return force_unicode(u"%s: (%s)" % (self.nazev, self.soustredeni))
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/templates/seminar/soustredeni/seznam_soustredeni.html b/seminar/templates/seminar/soustredeni/seznam_soustredeni.html
index fcbcde26..18447a67 100644
--- a/seminar/templates/seminar/soustredeni/seznam_soustredeni.html
+++ b/seminar/templates/seminar/soustredeni/seznam_soustredeni.html
@@ -46,7 +46,11 @@
{% if user.is_staff %}
{% endif %}
diff --git a/seminar/templates/seminar/soustredeni/seznam_ucastniku.html b/seminar/templates/seminar/soustredeni/seznam_ucastniku.html
new file mode 100644
index 00000000..e5f40aaf
--- /dev/null
+++ b/seminar/templates/seminar/soustredeni/seznam_ucastniku.html
@@ -0,0 +1,39 @@
+{% load static %}
+
+
+ Seznam účastníků
+
+
+
+
+
+
+ {% with object_list|first as afirst %}
+ {{afirst.soustredeni.misto}}
+ {% endwith %}
+ - účastníci
+
+
+
+ Jméno |
+ Maturita |
+ Mobil |
+ |
+
+ {% for sous_ucast in object_list %}
+
+ {{sous_ucast.resitel}} |
+ {{sous_ucast.resitel.rok_maturity}} |
+ {{sous_ucast.resitel.telefon}} |
+ |
+
+
+
+ {% empty %}
+ Žádní účastníci nebyli...
+ {% endfor %}
+
+
+
+
+
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 %}
diff --git a/seminar/unicodecsv.py b/seminar/unicodecsv.py
new file mode 100644
index 00000000..48274a20
--- /dev/null
+++ b/seminar/unicodecsv.py
@@ -0,0 +1,61 @@
+import csv, codecs, cStringIO
+
+class UTF8Recoder:
+ """
+ Iterator that reads an encoded stream and reencodes the input to UTF-8
+ """
+ def __init__(self, f, encoding):
+ self.reader = codecs.getreader(encoding)(f)
+
+ def __iter__(self):
+ return self
+
+ def next(self):
+ return self.reader.next().encode("utf-8")
+
+class UnicodeReader:
+ """
+ A CSV reader which will iterate over lines in the CSV file "f",
+ which is encoded in the given encoding.
+ """
+
+ def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds):
+ f = UTF8Recoder(f, encoding)
+ self.reader = csv.reader(f, dialect=dialect, **kwds)
+
+ def next(self):
+ row = self.reader.next()
+ return [unicode(s, "utf-8") for s in row]
+
+ def __iter__(self):
+ return self
+
+class UnicodeWriter:
+ """
+ A CSV writer which will write rows to CSV file "f",
+ which is encoded in the given encoding.
+ """
+
+ def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds):
+ # Redirect output to a queue
+ self.queue = cStringIO.StringIO()
+ self.writer = csv.writer(self.queue, dialect=dialect, **kwds)
+ self.stream = f
+ self.encoder = codecs.getincrementalencoder(encoding)()
+
+ def writerow(self, row):
+ self.writer.writerow([s.encode("utf-8") for s in row])
+ # Fetch UTF-8 output from the queue ...
+ data = self.queue.getvalue()
+ data = data.decode("utf-8")
+ # ... and reencode it into the target encoding
+ data = self.encoder.encode(data)
+ # write to the target stream
+ self.stream.write(data)
+ # empty queue
+ self.queue.truncate(0)
+
+ def writerows(self, rows):
+ for row in rows:
+ self.writerow(row)
+
diff --git a/seminar/urls.py b/seminar/urls.py
index 725a6037..f7228b47 100644
--- a/seminar/urls.py
+++ b/seminar/urls.py
@@ -3,16 +3,11 @@ from django.conf.urls import patterns, url
from django.contrib.auth.decorators import user_passes_test
from . import views, export
from utils import staff_member_required
-from prednasky.views import newPrednaska, Prednaska_hotovo
from django.views.generic.base import RedirectView
staff_member_required = user_passes_test(lambda u: u.is_staff)
urlpatterns = [
- # prednasky
- url(r'^prednasky/$', newPrednaska),
- url(r'^prednasky/hotovo$', Prednaska_hotovo),
-
# REDIRECTy
url(r'^jak-resit/$', RedirectView.as_view(url='/co-je-MaM/jak-resit/')),
@@ -33,6 +28,9 @@ urlpatterns = [
url(r'^soustredeni/probehlo/$', views.SoustredeniListView.as_view(),
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')),
# Zadani
diff --git a/seminar/views.py b/seminar/views.py
index b8c8345b..141e9492 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
@@ -14,6 +14,7 @@ from django.contrib.auth import authenticate, login
from .models import Problem, Cislo, Reseni, Nastaveni, Rocnik, Soustredeni, Organizator, Resitel, Novinky, Soustredeni_Ucastnici, Pohadka, Prispevek
from .models import VysledkyZaCislo, VysledkyKCisluZaRocnik, VysledkyKCisluOdjakziva
from . import utils
+from .unicodecsv import UnicodeWriter
from datetime import timedelta, date, datetime
from itertools import groupby
@@ -26,6 +27,7 @@ import unicodedata
import json
import traceback
import sys
+import csv
def verejna_temata(rocnik):
@@ -528,9 +530,52 @@ 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):
+ model = Soustredeni_Ucastnici
+ template_name = 'seminar/soustredeni/seznam_ucastniku.html'
+
+ def get_queryset(self):
+ 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(["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')
+ shutil.rmtree(tempdir)
+ return response
+
+
+def soustredeniUcastniciExportView(request,soustredeni):
+ 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"'
+
+ writer = UnicodeWriter(response)
+ writer.writerow(["jmeno", "prijmeni", "rok_maturity", "telefon", "email", "ulice", "mesto", "psc","stat"])
+ for u in ucastnici:
+ writer.writerow([u.jmeno, u.prijmeni, str(u.rok_maturity), u.telefon, u.email, u.ulice, u.mesto, u.psc, u.stat.name])
+ return response
+
### Články