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.
97 lines
3.3 KiB
97 lines
3.3 KiB
3 years ago
|
import django
|
||
|
from django.shortcuts import get_object_or_404
|
||
10 years ago
|
from django.http import HttpResponse
|
||
5 years ago
|
from django.urls import reverse
|
||
10 years ago
|
from django.views import generic
|
||
10 years ago
|
from django.utils.encoding import force_text
|
||
|
|
||
3 years ago
|
from .utils import default_ovvpfile
|
||
|
from seminar.models import Rocnik, Soustredeni
|
||
4 years ago
|
from seminar.views import vysledkovka
|
||
4 years ago
|
from seminar.utils import aktivniResitele
|
||
10 years ago
|
|
||
|
class ExportIndexView(generic.View):
|
||
5 years ago
|
def get(self, request):
|
||
|
ls = []
|
||
|
for r in Rocnik.objects.filter(exportovat = True):
|
||
|
url = reverse('seminar_export_rocnik', kwargs={'prvni_rok': r.prvni_rok})
|
||
|
ls.append(url.split('/')[-1])
|
||
|
for s in Soustredeni.objects.filter(exportovat = True):
|
||
|
url = reverse('seminar_export_sous', kwargs={'datum_zacatku': s.datum_zacatku.isoformat()})
|
||
|
ls.append(url.split('/')[-1])
|
||
10 years ago
|
|
||
5 years ago
|
return HttpResponse('\n'.join(ls) + '\n', content_type='text/plain; charset=utf-8')
|
||
10 years ago
|
|
||
|
|
||
10 years ago
|
class ExportSousView(generic.View):
|
||
|
|
||
5 years ago
|
def get(self, request, datum_zacatku=None):
|
||
|
try:
|
||
|
dz = django.utils.dateparse.parse_date(datum_zacatku)
|
||
|
except:
|
||
|
dz = None
|
||
|
if dz is None:
|
||
|
raise django.http.Http404()
|
||
|
|
||
|
s = get_object_or_404(Soustredeni, datum_zacatku=dz, exportovat=True)
|
||
|
|
||
|
akce = {Soustredeni.TYP_JARNI: 'MaM.sous.jaro',
|
||
|
Soustredeni.TYP_PODZIMNI: 'MaM.sous.podzim',
|
||
|
Soustredeni.TYP_VIKEND: 'MaM.vikend',
|
||
|
}[s.typ]
|
||
|
|
||
|
of = default_ovvpfile(akce, s.rocnik)
|
||
|
of.headers['x-event-begin'] = s.datum_zacatku.isoformat()
|
||
|
of.headers['x-event-end'] = s.datum_konce.isoformat()
|
||
|
of.headers['x-event-location'] = s.misto
|
||
|
of.headers['comment'] = u'MaM-Web export ucastniku soustredeni v {x-event-location} od {x-event-begin} do {x-event-end}'.format(**of.headers)
|
||
|
of.columns = ['id', 'name', 'surname', 'gender', 'email', 'end-year', 'school', 'school-name']
|
||
|
|
||
|
for u in s.ucastnici.all():
|
||
|
of.rows.append(u.export_row())
|
||
|
|
||
|
return of.to_HttpResponse()
|
||
|
|
||
|
# POZOR! Předělání na nový model neotestováno v reálu (ale zase jen drobné změny)
|
||
10 years ago
|
class ExportRocnikView(generic.View):
|
||
|
|
||
5 years ago
|
def get(self, request, prvni_rok=None):
|
||
|
try:
|
||
|
pr = int(prvni_rok)
|
||
|
except:
|
||
|
pr = None
|
||
|
if pr is None:
|
||
|
raise django.http.Http404()
|
||
|
|
||
|
rocnik = get_object_or_404(Rocnik, prvni_rok=pr, exportovat=True)
|
||
|
cislo = rocnik.posledni_zverejnena_vysledkovka_cislo()
|
||
4 years ago
|
resitele = aktivniResitele(cislo, True)
|
||
4 years ago
|
slovnik_body = vysledkovka.secti_body_za_rocnik(cislo, resitele, False)
|
||
4 years ago
|
setrizeni_resitele, body = vysledkovka.setrid_resitele_a_body(slovnik_body)
|
||
5 years ago
|
|
||
|
of = default_ovvpfile('MaM.rocnik', rocnik)
|
||
|
of.headers['comment'] = u'MaM-Web export aktivnich resitelu rocniku {rocnik} do cisla {cislo}'.format(rocnik=rocnik, cislo=cislo)
|
||
|
of.columns = ['id', 'name', 'surname', 'gender', 'born', 'email', 'end-year',
|
||
|
'street', 'town', 'postcode', 'country', 'spam-flag', 'spam-date',
|
||
|
'school', 'school-name', 'points', 'rank',]
|
||
4 years ago
|
|
||
|
resitele_slovnik = {}
|
||
|
for r in resitele:
|
||
|
resitele_slovnik[r.id] = r
|
||
|
|
||
5 years ago
|
# počítání pořadí řešitelů
|
||
|
posledni_body = 100000
|
||
|
posledni_poradi = 0
|
||
|
for i in range(len(setrizeni_resitele)):
|
||
4 years ago
|
rd = resitele_slovnik[setrizeni_resitele[i]].export_row()
|
||
5 years ago
|
|
||
|
if posledni_body > body[i]:
|
||
|
posledni_body = body[i]
|
||
|
posledni_poradi = i + 1
|
||
|
rd['rank'] = posledni_poradi
|
||
|
rd['points'] = body[i]
|
||
|
|
||
|
of.rows.append(rd)
|
||
|
|
||
|
return of.to_HttpResponse()
|