|
@ -10,96 +10,93 @@ from .models import Problem, Cislo, Reseni, Nastaveni, Rocnik, Soustredeni |
|
|
from .ovvpfile import OvvpFile |
|
|
from .ovvpfile import OvvpFile |
|
|
|
|
|
|
|
|
class ExportIndexView(generic.View): |
|
|
class ExportIndexView(generic.View): |
|
|
def get(self, request): |
|
|
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]) |
|
|
|
|
|
|
|
|
ls = [] |
|
|
return HttpResponse('\n'.join(ls) + '\n', content_type='text/plain; charset=utf-8') |
|
|
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]) |
|
|
|
|
|
|
|
|
|
|
|
return HttpResponse('\n'.join(ls) + '\n', content_type='text/plain; charset=utf-8') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def default_ovvpfile(event, rocnik): |
|
|
def default_ovvpfile(event, rocnik): |
|
|
of = OvvpFile() |
|
|
of = OvvpFile() |
|
|
of.headers['version'] = '1' |
|
|
of.headers['version'] = '1' |
|
|
of.headers['event'] = event |
|
|
of.headers['event'] = event |
|
|
of.headers['year'] = force_text(rocnik.prvni_rok) |
|
|
of.headers['year'] = force_text(rocnik.prvni_rok) |
|
|
of.headers['date'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") |
|
|
of.headers['date'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") |
|
|
of.headers['id-scope'] = 'mam' |
|
|
of.headers['id-scope'] = 'mam' |
|
|
of.headers['id-generation'] = '1' |
|
|
of.headers['id-generation'] = '1' |
|
|
return of |
|
|
return of |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ExportSousView(generic.View): |
|
|
class ExportSousView(generic.View): |
|
|
|
|
|
|
|
|
def get(self, request, datum_zacatku=None): |
|
|
def get(self, request, datum_zacatku=None): |
|
|
try: |
|
|
try: |
|
|
dz = django.utils.dateparse.parse_date(datum_zacatku) |
|
|
dz = django.utils.dateparse.parse_date(datum_zacatku) |
|
|
except: |
|
|
except: |
|
|
dz = None |
|
|
dz = None |
|
|
if dz is None: |
|
|
if dz is None: |
|
|
raise django.http.Http404() |
|
|
raise django.http.Http404() |
|
|
|
|
|
|
|
|
s = get_object_or_404(Soustredeni, datum_zacatku=dz, exportovat=True) |
|
|
|
|
|
|
|
|
|
|
|
akce = {Soustredeni.TYP_JARNI: 'MaM.sous.jaro', |
|
|
s = get_object_or_404(Soustredeni, datum_zacatku=dz, exportovat=True) |
|
|
Soustredeni.TYP_PODZIMNI: 'MaM.sous.podzim', |
|
|
|
|
|
Soustredeni.TYP_VIKEND: 'MaM.vikend', |
|
|
|
|
|
}[s.typ] |
|
|
|
|
|
|
|
|
|
|
|
of = default_ovvpfile(akce, s.rocnik) |
|
|
akce = {Soustredeni.TYP_JARNI: 'MaM.sous.jaro', |
|
|
of.headers['x-event-begin'] = s.datum_zacatku.isoformat() |
|
|
Soustredeni.TYP_PODZIMNI: 'MaM.sous.podzim', |
|
|
of.headers['x-event-end'] = s.datum_konce.isoformat() |
|
|
Soustredeni.TYP_VIKEND: 'MaM.vikend', |
|
|
of.headers['x-event-location'] = s.misto |
|
|
}[s.typ] |
|
|
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 = default_ovvpfile(akce, s.rocnik) |
|
|
of.rows.append(u.export_row()) |
|
|
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'] |
|
|
|
|
|
|
|
|
return of.to_HttpResponse() |
|
|
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) |
|
|
class ExportRocnikView(generic.View): |
|
|
class ExportRocnikView(generic.View): |
|
|
|
|
|
|
|
|
def get(self, request, prvni_rok=None): |
|
|
def get(self, request, prvni_rok=None): |
|
|
try: |
|
|
try: |
|
|
pr = int(prvni_rok) |
|
|
pr = int(prvni_rok) |
|
|
except: |
|
|
except: |
|
|
pr = None |
|
|
pr = None |
|
|
if pr is None: |
|
|
if pr is None: |
|
|
raise django.http.Http404() |
|
|
raise django.http.Http404() |
|
|
|
|
|
|
|
|
rocnik = get_object_or_404(Rocnik, prvni_rok=pr, exportovat=True) |
|
|
rocnik = get_object_or_404(Rocnik, prvni_rok=pr, exportovat=True) |
|
|
cislo = rocnik.posledni_zverejnena_vysledkovka_cislo() |
|
|
cislo = rocnik.posledni_zverejnena_vysledkovka_cislo() |
|
|
vysledky = VysledkyKCisluZaRocnik.objects.filter(cislo = cislo).select_related("resitel").order_by('-body').all() |
|
|
resitele = views.aktivniResitele(cislo.rocnik.rocnik, cislo.poradi, True) |
|
|
|
|
|
slovnik_body = secti_body_za_rocnik(cislo, resitele) |
|
|
of = default_ovvpfile('MaM.rocnik', rocnik) |
|
|
_, setrizeni_resitele, setrizene_body = setrid_resitele_a_body(slovnik_body) |
|
|
of.headers['comment'] = u'MaM-Web export aktivnich resitelu rocniku {rocnik} do cisla {cislo}'.format( |
|
|
|
|
|
rocnik=rocnik, cislo=cislo) |
|
|
of = default_ovvpfile('MaM.rocnik', rocnik) |
|
|
of.columns = ['id', 'name', 'surname', 'gender', 'born', 'email', 'end-year', |
|
|
of.headers['comment'] = u'MaM-Web export aktivnich resitelu rocniku {rocnik} do cisla {cislo}'.format(rocnik=rocnik, cislo=cislo) |
|
|
'street', 'town', 'postcode', 'country', 'spam-flag', 'spam-date', |
|
|
of.columns = ['id', 'name', 'surname', 'gender', 'born', 'email', 'end-year', |
|
|
'school', 'school-name', 'points', 'rank',] |
|
|
'street', 'town', 'postcode', 'country', 'spam-flag', 'spam-date', |
|
|
|
|
|
'school', 'school-name', 'points', 'rank',] |
|
|
posledni_body = 100000 |
|
|
|
|
|
posledni_poradi = 0 |
|
|
# počítání pořadí řešitelů |
|
|
for vi in range(len(vysledky)): |
|
|
posledni_body = 100000 |
|
|
|
|
|
posledni_poradi = 0 |
|
|
v = vysledky[vi] |
|
|
for i in range(len(setrizeni_resitele)): |
|
|
rd = v.resitel.export_row() |
|
|
rd = setrizeni_resitele[i].export_row() |
|
|
|
|
|
|
|
|
if posledni_body > v.body: |
|
|
if posledni_body > body[i]: |
|
|
posledni_body = v.body |
|
|
posledni_body = body[i] |
|
|
posledni_poradi = vi + 1 |
|
|
posledni_poradi = i + 1 |
|
|
rd['rank'] = posledni_poradi |
|
|
rd['rank'] = posledni_poradi |
|
|
rd['points'] = v.body |
|
|
rd['points'] = body[i] |
|
|
|
|
|
|
|
|
of.rows.append(rd) |
|
|
of.rows.append(rd) |
|
|
|
|
|
|
|
|
return of.to_HttpResponse() |
|
|
return of.to_HttpResponse() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|