Merge branch 'jethro'
This commit is contained in:
commit
f5d8fcbc81
5 changed files with 143 additions and 0 deletions
19
mamweb/static/css/printtable.css
Normal file
19
mamweb/static/css/printtable.css
Normal file
|
@ -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%
|
||||
}
|
39
seminar/templates/seminar/soustredeni/seznam_ucastniku.html
Normal file
39
seminar/templates/seminar/soustredeni/seznam_ucastniku.html
Normal file
|
@ -0,0 +1,39 @@
|
|||
{% load static %}
|
||||
<html lang='cs'>
|
||||
<head>
|
||||
<title>Seznam účastníků</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" type="text/css" href="{% static 'css/printtable.css' %}" />
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>
|
||||
{% with object_list|first as afirst %}
|
||||
{{afirst.soustredeni.misto}}
|
||||
{% endwith %}
|
||||
- účastníci
|
||||
</h1>
|
||||
<table>
|
||||
<tr>
|
||||
<th nowrap>Jméno</th>
|
||||
<th nowrap>Maturita</th>
|
||||
<th nowrap>Mobil</th>
|
||||
<th class="fill"></th>
|
||||
</tr>
|
||||
{% for sous_ucast in object_list %}
|
||||
<tr>
|
||||
<td nowrap>{{sous_ucast.resitel}}</td>
|
||||
<td nowrap>{{sous_ucast.resitel.rok_maturity}}</td>
|
||||
<td nowrap>{{sous_ucast.resitel.telefon}}</td>
|
||||
<td class="fill"></td>
|
||||
|
||||
</tr>
|
||||
|
||||
{% empty %}
|
||||
Žádní účastníci nebyli...
|
||||
{% endfor %}
|
||||
</table>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
|
61
seminar/unicodecsv.py
Normal file
61
seminar/unicodecsv.py
Normal file
|
@ -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)
|
||||
|
|
@ -28,6 +28,8 @@ urlpatterns = [
|
|||
url(r'^soustredeni/probehlo/$', views.SoustredeniListView.as_view(),
|
||||
name = 'seminar_seznam_soustredeni'),
|
||||
url(r'^soustredeni/probehlo/(?P<soustredeni>\d+)/$', views.SoustredeniView.as_view(), name='seminar_soustredeni'),
|
||||
url(r'^soustredeni/(?P<soustredeni>\d+)/seznam_ucastniku$', staff_member_required(views.SoustredeniUcastniciView.as_view()), name='soustredeni_ucastnici'),
|
||||
url(r'^soustredeni/(?P<soustredeni>\d+)/export_ucastniku$', staff_member_required(views.soustredeniUcastniciExportView), name='soustredeni_ucastnici_export'),
|
||||
url(r'^soustredeni/(?P<soustredeni>\d+)/fotogalerie/', include('galerie.urls')),
|
||||
|
||||
# Zadani
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue