Web M&M
https://mam.matfyz.cz
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.9 KiB
55 lines
1.9 KiB
from django.shortcuts import get_object_or_404
|
|
from django.http import HttpResponse
|
|
from django.views import generic
|
|
from seminar.models import Soustredeni, Resitel, Soustredeni_Ucastnici # Tohle je stare a chceme se toho zbavit. Pouzivejte s.ToCoChci
|
|
import csv
|
|
|
|
from seminar.views import obalkyView
|
|
|
|
|
|
class SoustredeniListView(generic.ListView):
|
|
model = Soustredeni
|
|
template_name = 'soustredeni/seznam_soustredeni.html'
|
|
|
|
|
|
def soustredeniObalkyView(request, soustredeni):
|
|
soustredeni = get_object_or_404(Soustredeni, id=soustredeni)
|
|
return obalkyView(request, soustredeni.ucastnici.all())
|
|
|
|
|
|
class SoustredeniUcastniciBaseView(generic.ListView):
|
|
model = Soustredeni_Ucastnici
|
|
|
|
def get_queryset(self):
|
|
soustredeni = get_object_or_404(
|
|
Soustredeni,
|
|
pk=self.kwargs["soustredeni"]
|
|
)
|
|
return Soustredeni_Ucastnici.objects.filter(
|
|
soustredeni=soustredeni).select_related('resitel')
|
|
|
|
|
|
class SoustredeniMailyUcastnikuView(SoustredeniUcastniciBaseView):
|
|
""" Seznam e-mailů řešitelů oddělených čárkami. """
|
|
model = Soustredeni_Ucastnici
|
|
template_name = 'soustredeni/maily_ucastniku.txt'
|
|
|
|
|
|
class SoustredeniUcastniciView(SoustredeniUcastniciBaseView):
|
|
""" HTML tabulka účastníků pro tisk. """
|
|
model = Soustredeni_Ucastnici
|
|
template_name = 'soustredeni/seznam_ucastniku.html'
|
|
|
|
|
|
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 = csv.writer(response)
|
|
writer.writerow(["jmeno", "prijmeni", "rok_maturity", "telefon", "email", "ulice", "mesto", "psc","stat"])
|
|
for u in ucastnici:
|
|
o = u.osoba
|
|
writer.writerow([o.jmeno, o.prijmeni, str(u.rok_maturity), o.telefon, o.email, o.ulice, o.mesto, o.psc, o.stat.name])
|
|
return response
|
|
|