Merge branch 'develop' into test
This commit is contained in:
commit
a0c511fca8
5 changed files with 90 additions and 2 deletions
|
@ -28,7 +28,9 @@ INTERNAL_IPS = ['127.0.0.1']
|
||||||
|
|
||||||
TEMPLATES[0]['OPTIONS']['debug'] = True
|
TEMPLATES[0]['OPTIONS']['debug'] = True
|
||||||
|
|
||||||
ALLOWED_HOSTS = ['127.0.0.1', '192.168.43.34']
|
from ipaddress import ip_network
|
||||||
|
ALLOWED_HOSTS = [str(ip) for ip in ip_network('192.168.0.0/16')]
|
||||||
|
ALLOWED_HOSTS.append('127.0.0.1')
|
||||||
|
|
||||||
# Database
|
# Database
|
||||||
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
|
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
|
||||||
|
|
|
@ -7,6 +7,7 @@ from django.views.generic.base import TemplateView
|
||||||
from django.contrib.auth.models import User, Permission, Group
|
from django.contrib.auth.models import User, Permission, Group
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
|
from django.http import HttpResponse
|
||||||
|
|
||||||
import seminar.models as s
|
import seminar.models as s
|
||||||
import seminar.models as m
|
import seminar.models as m
|
||||||
|
@ -14,6 +15,7 @@ from .forms import PrihlaskaForm, ProfileEditForm, PoMaturiteProfileEditForm
|
||||||
|
|
||||||
from datetime import date
|
from datetime import date
|
||||||
import logging
|
import logging
|
||||||
|
import csv
|
||||||
|
|
||||||
from seminar.views import formularOKView
|
from seminar.views import formularOKView
|
||||||
from various.autentizace.views import LoginView
|
from various.autentizace.views import LoginView
|
||||||
|
@ -304,3 +306,71 @@ def profilView(request):
|
||||||
return ResitelView.as_view()(request)
|
return ResitelView.as_view()(request)
|
||||||
else:
|
else:
|
||||||
return LoginView.as_view()(request)
|
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
|
||||||
|
|
|
@ -119,7 +119,9 @@
|
||||||
|
|
||||||
{% if user.je_org %}
|
{% if user.je_org %}
|
||||||
<div class='mam-org-only'>
|
<div class='mam-org-only'>
|
||||||
<a href='vysledkovka.tex' download>Výsledkovka ročníku (LaTeX, včetně neveřejných)</a>
|
<p><a href='vysledkovka.tex' download>Výsledkovka ročníku (LaTeX, včetně neveřejných)</a></p>
|
||||||
|
{# FIXME: Sice to sem asi nepatří sémanticky, ale bylo to nejjednodušší… #}
|
||||||
|
<p><a href='{% url 'seminar_rocnik_resitele_csv' rocnik=rocnik.rocnik %}' download>CSV export řešitelů</a></p>
|
||||||
<h2>Výsledková listina včetně neveřejných bodů</h2>
|
<h2>Výsledková listina včetně neveřejných bodů</h2>
|
||||||
{% include "vysledkovky/vysledkovka_rocnik_neverejna.html" %}
|
{% include "vysledkovky/vysledkovka_rocnik_neverejna.html" %}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -36,6 +36,11 @@ urlpatterns = [
|
||||||
org_required(views.RocnikVysledkovkaView.as_view()),
|
org_required(views.RocnikVysledkovkaView.as_view()),
|
||||||
name='seminar_rocnik_vysledkovka'
|
name='seminar_rocnik_vysledkovka'
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
'rocnik/<int:rocnik>/resitele.csv',
|
||||||
|
org_required(views.resiteleRocnikuCsvExportView),
|
||||||
|
name='seminar_rocnik_resitele_csv'
|
||||||
|
),
|
||||||
path(
|
path(
|
||||||
'cislo/<int:rocnik>.<str:cislo>/vysledkovka.tex',
|
'cislo/<int:rocnik>.<str:cislo>/vysledkovka.tex',
|
||||||
org_required(views.CisloVysledkovkaView.as_view()),
|
org_required(views.CisloVysledkovkaView.as_view()),
|
||||||
|
|
|
@ -390,6 +390,15 @@ class RocnikView(generic.DetailView):
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
def resiteleRocnikuCsvExportView(request, rocnik):
|
||||||
|
from personalni.views import dataResiteluCsvResponse
|
||||||
|
assert request.method in ('GET', 'HEAD')
|
||||||
|
return dataResiteluCsvResponse(
|
||||||
|
utils.resi_v_rocniku(
|
||||||
|
m.Rocnik.objects.get(rocnik=rocnik)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# FIXME: Pozor, výš je ještě jeden ProblemView!
|
# FIXME: Pozor, výš je ještě jeden ProblemView!
|
||||||
#class ProblemView(generic.DetailView):
|
#class ProblemView(generic.DetailView):
|
||||||
|
|
Loading…
Reference in a new issue