diff --git a/mamweb/static/css/printtable.css b/mamweb/static/css/printtable.css new file mode 100644 index 00000000..9d4baa13 --- /dev/null +++ b/mamweb/static/css/printtable.css @@ -0,0 +1,19 @@ +table { + border-collapse: collapse; + width: 100% +} + +table, th, td { + border: 1px solid black; +} + +td { + width: 1%; + height: 1cm; +} + + +.fill { + width: 100%; + max-width: 100% +} 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 +

+ + + + + + + + {% for sous_ucast in object_list %} + + + + + + + + + {% empty %} + Žádní účastníci nebyli... + {% endfor %} +
JménoMaturitaMobil
{{sous_ucast.resitel}}{{sous_ucast.resitel.rok_maturity}}{{sous_ucast.resitel.telefon}}
+ + + + 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 63666667..2c06e0fb 100644 --- a/seminar/urls.py +++ b/seminar/urls.py @@ -28,6 +28,8 @@ 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+)/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..95df1a2e 100644 --- a/seminar/views.py +++ b/seminar/views.py @@ -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): @@ -531,6 +533,26 @@ def soustredeniObalkyView(request,soustredeni): soustredeni = Soustredeni.objects.filter(id = soustredeni)[0] 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 soustredeniUcastniciExportView(request,soustredeni): + soustredeni = Soustredeni.objects.filter(id = soustredeni)[0] + 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