|
|
@ -7,6 +7,7 @@ from django.views.generic.base import TemplateView |
|
|
|
from django.contrib.auth.models import User, Permission, Group |
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin |
|
|
|
from django.db import transaction |
|
|
|
from django.http import HttpResponse |
|
|
|
|
|
|
|
import seminar.models as s |
|
|
|
import seminar.models as m |
|
|
@ -14,6 +15,7 @@ from .forms import PrihlaskaForm, ProfileEditForm, PoMaturiteProfileEditForm |
|
|
|
|
|
|
|
from datetime import date |
|
|
|
import logging |
|
|
|
import csv |
|
|
|
|
|
|
|
from seminar.views import formularOKView |
|
|
|
from various.autentizace.views import LoginView |
|
|
@ -304,3 +306,71 @@ def profilView(request): |
|
|
|
return ResitelView.as_view()(request) |
|
|
|
else: |
|
|
|
return LoginView.as_view()(request) |
|
|
|
|
|
|
|
def dataResiteluCsvResponse(queryset, columns=None, with_header=True): |
|
|
|
"""Pomocná funkce pro vracení dat řešitelů jako CSV. Musí dostat správný QuerySet, který dává Řešitele""" |
|
|
|
# TODO: Možná nějak zobecnit i na Osoby? |
|
|
|
# TODO: Nemá to spíš být class-based? Tohle je efektivně metoda "get", které ale chybí "get_queryset"… |
|
|
|
|
|
|
|
default_columns = ( |
|
|
|
'id', |
|
|
|
'osoba__jmeno', |
|
|
|
'osoba__prijmeni', |
|
|
|
'osoba__prezdivka', |
|
|
|
'osoba__email', |
|
|
|
'osoba__telefon', |
|
|
|
'osoba__user', |
|
|
|
'osoba__datum_narozeni', |
|
|
|
'osoba__pohlavi_muz', |
|
|
|
'osoba__ulice', |
|
|
|
'osoba__mesto', |
|
|
|
'osoba__psc', |
|
|
|
'osoba__stat', |
|
|
|
'skola', # Bude fungovat takhle? |
|
|
|
'poznamka', |
|
|
|
'osoba__poznamka', |
|
|
|
'rok_maturity', |
|
|
|
'zasilat', |
|
|
|
'zasilat_cislo_emailem', |
|
|
|
'osoba__datum_registrace', |
|
|
|
'osoba__datum_souhlasu_udaje', |
|
|
|
'osoba__datum_souhlasu_zasilani', |
|
|
|
) |
|
|
|
if columns is None: columns = default_columns |
|
|
|
|
|
|
|
field_name_overrides = { |
|
|
|
# Zrušení prefixu "osoba__" |
|
|
|
'osoba__jmeno': 'jmeno', |
|
|
|
'osoba__prijmeni': 'prijmeni', |
|
|
|
'osoba__prezdivka': 'prezdivka', |
|
|
|
'osoba__email': 'email', |
|
|
|
'osoba__telefon': 'telefon', |
|
|
|
'osoba__user': 'user', |
|
|
|
'osoba__datum_narozeni': 'datum_narozeni', |
|
|
|
'osoba__pohlavi_muz': 'pohlavi_muz', |
|
|
|
'osoba__ulice': 'ulice', |
|
|
|
'osoba__mesto': 'mesto', |
|
|
|
'osoba__psc': 'psc', |
|
|
|
'osoba__stat': 'stat', |
|
|
|
'osoba__datum_registrace': 'datum_registrace', |
|
|
|
'osoba__datum_souhlasu_udaje': 'datum_souhlasu_udaje', |
|
|
|
'osoba__datum_souhlasu_zasilani':'datum_souhlasu_zasilani', |
|
|
|
} |
|
|
|
|
|
|
|
def get_field_name(column_name): |
|
|
|
if column_name in field_name_overrides: |
|
|
|
return field_name_overrides[column_name] |
|
|
|
return column_name |
|
|
|
|
|
|
|
response = HttpResponse(content_type='text/csv') |
|
|
|
writer = csv.writer(response) |
|
|
|
|
|
|
|
# První řádek je záhlaví |
|
|
|
if with_header: |
|
|
|
writer.writerow(map(get_field_name, columns)) |
|
|
|
|
|
|
|
# Data: |
|
|
|
queryset_list = queryset.values_list(*columns) |
|
|
|
writer.writerows(queryset_list) |
|
|
|
|
|
|
|
return response |
|
|
|