Velky fix a rework views na body (a sablon)
* vysledkovka.tex neni uplne hotova (ani nebyla)
This commit is contained in:
parent
f776c4aef2
commit
c71f08b0bc
6 changed files with 85 additions and 30 deletions
|
@ -5,7 +5,8 @@ from django.core.urlresolvers import reverse
|
|||
from django.views import generic
|
||||
from django.utils.encoding import force_text
|
||||
|
||||
from .models import Problem, Cislo, Reseni, VysledkyKCislu, Nastaveni, Rocnik, Soustredeni
|
||||
from .models import Problem, Cislo, Reseni, Nastaveni, Rocnik, Soustredeni
|
||||
from .models import VysledkyZaCislo, VysledkyKCisluZaRocnik, VysledkyKCisluOdjakziva
|
||||
from .ovvpfile import OvvpFile
|
||||
|
||||
class ExportIndexView(generic.View):
|
||||
|
@ -75,7 +76,7 @@ class ExportRocnikView(generic.View):
|
|||
|
||||
rocnik = get_object_or_404(Rocnik, prvni_rok=pr, exportovat=True)
|
||||
cislo = rocnik.posledni_zverejnena_vysledkovka_cislo()
|
||||
vysledky = VysledkyKCislu.objects.filter(cislo = cislo).select_related("resitel").order_by('-body_celkem').all()
|
||||
vysledky = VysledkyKCisluZaRocnik.objects.filter(cislo = cislo).select_related("resitel").order_by('-body').all()
|
||||
|
||||
of = default_ovvpfile('MaM.rocnik', rocnik)
|
||||
of.headers['comment'] = u'MaM-Web export aktivnich resitelu rocniku {rocnik} do cisla {cislo}'.format(
|
||||
|
@ -91,11 +92,11 @@ class ExportRocnikView(generic.View):
|
|||
v = vysledky[vi]
|
||||
rd = v.resitel.export_row()
|
||||
|
||||
if posledni_body > v.body_celkem:
|
||||
posledni_body = v.body_celkem
|
||||
if posledni_body > v.body:
|
||||
posledni_body = v.body
|
||||
posledni_poradi = vi + 1
|
||||
rd['rank'] = posledni_poradi
|
||||
rd['points'] = v.body_celkem
|
||||
rd['points'] = v.body
|
||||
|
||||
of.rows.append(rd)
|
||||
|
||||
|
|
51
seminar/migrations/0029_fix_body_celkem_views.py
Normal file
51
seminar/migrations/0029_fix_body_celkem_views.py
Normal file
|
@ -0,0 +1,51 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
import django_countries.fields
|
||||
import seminar.models
|
||||
import django.utils.timezone
|
||||
from django.conf import settings
|
||||
|
||||
CREATE_VIEWS="""
|
||||
|
||||
drop view seminar_body_k_cislu_rocnik;
|
||||
create view seminar_body_k_cislu_rocnik as
|
||||
select
|
||||
seminar_cisla.id || '-' || min_body.resitel_id as id,
|
||||
seminar_cisla.id as cislo_id,
|
||||
min_body.resitel_id as resitel_id,
|
||||
sum(min_body.body) as body
|
||||
from
|
||||
seminar_cisla
|
||||
inner join seminar_body_za_cislo as min_body on
|
||||
(min_body.rocnik_id = seminar_cisla.rocnik_id and seminar_cisla.cislo >= min_body.cislo)
|
||||
group by seminar_cisla.id, min_body.resitel_id
|
||||
order by body desc;
|
||||
|
||||
drop view seminar_body_k_cislu_odjakziva;
|
||||
create view seminar_body_k_cislu_odjakziva as
|
||||
select
|
||||
seminar_cisla.id || '-' || min_body.resitel_id as id,
|
||||
seminar_cisla.id as cislo_id,
|
||||
min_body.resitel_id as resitel_id,
|
||||
sum(min_body.body) as body
|
||||
from
|
||||
seminar_cisla
|
||||
inner join seminar_rocniky on
|
||||
(seminar_cisla.rocnik_id = seminar_rocniky.id)
|
||||
inner join seminar_body_za_cislo as min_body on
|
||||
(min_body.rocnik_id = seminar_cisla.rocnik_id and seminar_cisla.cislo >= min_body.cislo) or
|
||||
(min_body.rocnik < seminar_rocniky.rocnik)
|
||||
group by seminar_cisla.id, min_body.resitel_id
|
||||
order by body desc;
|
||||
"""
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [("seminar", "0028_add_body_celkem_views")]
|
||||
|
||||
operations = [
|
||||
migrations.RunSQL(sql=CREATE_VIEWS)
|
||||
]
|
||||
|
|
@ -661,15 +661,15 @@ class VysledkyZaCislo(VysledkyBase):
|
|||
managed = False
|
||||
|
||||
|
||||
class VysledkyKCislu(VysledkyBase):
|
||||
class VysledkyKCisluZaRocnik(VysledkyBase):
|
||||
|
||||
class Meta:
|
||||
db_table = 'seminar_body_k_cislu_rocnik'
|
||||
abstract = False
|
||||
managed = False
|
||||
|
||||
body_celkem = models.DecimalField(max_digits=8, decimal_places=1, db_column='body_celkem',
|
||||
verbose_name=u'body celkem do čísla (za ročník)')
|
||||
# body = models.DecimalField(max_digits=8, decimal_places=1, db_column='body',
|
||||
# verbose_name=u'body do čísla (za ročník)')
|
||||
|
||||
|
||||
class VysledkyKCisluOdjakziva(VysledkyBase):
|
||||
|
@ -679,8 +679,8 @@ class VysledkyKCisluOdjakziva(VysledkyBase):
|
|||
abstract = False
|
||||
managed = False
|
||||
|
||||
body_celkem = models.DecimalField(max_digits=8, decimal_places=1, db_column='body_celkem',
|
||||
verbose_name=u'body celkem do čísla (i minulé ročníky)')
|
||||
# body = models.DecimalField(max_digits=8, decimal_places=1, db_column='body',
|
||||
# verbose_name=u'body do čísla (i minulé ročníky)')
|
||||
|
||||
|
||||
@reversion.register(ignore_duplicate_revisions=True)
|
||||
|
|
|
@ -34,17 +34,19 @@
|
|||
{% for p in problemy %}
|
||||
<th class='border-r'><a href="{{ p.verejne_url }}">{{ p.cislo_zadani.cislo }}.{{ p.kod }}</a>
|
||||
{% endfor %}
|
||||
<th class='border-r'>Sum
|
||||
<th class='border-r'>Sum<sup>-1</sup>
|
||||
<th>Celkem
|
||||
<th>Odjakživa
|
||||
{% for rv in vysledkovka %}
|
||||
<tr>
|
||||
<td class='border-r'>{{ rv.poradi }}
|
||||
<th class='border-r'>{{ rv.resitel.plne_jmeno }} [{{ rv.resitel.id }}]
|
||||
<th class='border-r'>{{ rv.resitel.plne_jmeno }} {{ rv.titul }}
|
||||
{% for b in rv.body %}
|
||||
<td class='border-r'>{{ b }}
|
||||
{% endfor %}
|
||||
<td class='border-r'>{{ rv.vysledek.body |default:0 }}
|
||||
<td>{{ rv.vysledek.body_celkem }}
|
||||
<td class='border-r'>{{ rv.body_minule }}
|
||||
<td><b>{{ rv.body_celkem_rocnik }}</b>
|
||||
<td>{{ rv.body_celkem_odjakziva }}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
|
|
@ -22,12 +22,12 @@
|
|||
{% for rv in vysledkovka %}
|
||||
{{ rv.poradi }} &
|
||||
{% if rv.resitel.titul %}
|
||||
\titul{ {{ rv.resitel.titul }} }
|
||||
\titul{ {{ rv.titul }} }
|
||||
{% endif %}
|
||||
{{ rv.resitel.plne_jmeno }} & {{ rv.resitel.rocnik |default:"" }} & {{ rv.body_minule }}
|
||||
{% for b in rv.body %}
|
||||
{{ b }} &
|
||||
{% endfor %}
|
||||
{{ rv.vysledek.body |default:0 }} & {{ rv.vysledek.body_celkem }} \\
|
||||
{{ rv.body_celkem_rocnik |default:0 }} & {{ rv.body_celkem_minule }} \\
|
||||
{% endfor %}
|
||||
\end{longtable}
|
||||
|
|
|
@ -5,7 +5,8 @@ from django.views import generic
|
|||
from django.utils.translation import ugettext as _
|
||||
from django.http import Http404
|
||||
|
||||
from .models import Problem, Cislo, Reseni, VysledkyKCislu, Nastaveni, Rocnik, Soustredeni, Organizator, Resitel
|
||||
from .models import Problem, Cislo, Reseni, Nastaveni, Rocnik, Soustredeni, Organizator, Resitel
|
||||
from .models import VysledkyZaCislo, VysledkyKCisluZaRocnik, VysledkyKCisluOdjakziva
|
||||
from . import utils
|
||||
|
||||
def AktualniZadaniView(request):
|
||||
|
@ -74,7 +75,7 @@ class CisloView(generic.DetailView):
|
|||
def get_context_data(self, **kwargs):
|
||||
context = super(CisloView, self).get_context_data(**kwargs)
|
||||
|
||||
vysledky = VysledkyKCislu.objects.filter(cislo = context['cislo']).order_by('-body_celkem').select_related("resitel")
|
||||
vysledky = VysledkyKCisluZaRocnik.objects.filter(cislo = context['cislo']).order_by('-body').select_related("resitel")
|
||||
reseni = Reseni.objects.filter(cislo_body = context['cislo']).select_related("resitel")
|
||||
|
||||
problemy = sorted(list(set([r.problem for r in reseni])), key=lambda x:(0 if x.typ==Problem.TYP_ULOHA else 1,x.kod))
|
||||
|
@ -97,16 +98,20 @@ class CisloView(generic.DetailView):
|
|||
tv = RadekVysledkovky()
|
||||
tv.resitel = v.resitel
|
||||
tv.rocnik = tv.resitel.rocnik(context['cislo'].rocnik)
|
||||
tv.resitel.titul = tv.resitel.titul(v.body_celkem)
|
||||
tv.vysledek = v
|
||||
#odkazuje na VysledkyKCislu
|
||||
tv.body = ['']*len(problemy)
|
||||
#pole bodu za ulohy
|
||||
tv.poradi = ''
|
||||
#defaultni poradi je prazdne - kvuli sdilenym mistum
|
||||
tv.body_minule = 0
|
||||
tv.body_celkem_rocnik = v.body
|
||||
tv.body_celkem_odjakziva = VysledkyKCisluOdjakziva.objects.get(resitel=v.resitel, cislo=context['cislo']).body
|
||||
body_cislo_q = VysledkyZaCislo.objects.filter(resitel=v.resitel, cislo=context['cislo'])
|
||||
tv.body_cislo = body_cislo_q[0].body if len(body_cislo_q) > 0 else 0
|
||||
tv.body_minule = tv.body_celkem_rocnik - tv.body_cislo
|
||||
tv.titul = tv.resitel.titul(tv.body_celkem_odjakziva)
|
||||
#pocet bodu do tohoto cisla
|
||||
if posledni_body > v.body_celkem:
|
||||
if posledni_body > tv.body_celkem_rocnik:
|
||||
if stejne_body.get(posledni_body):
|
||||
konec_rozmezi[posledni_body] = int(predchozi_poradi.poradi) + stejne_body[posledni_body]
|
||||
#druha hranice sdilenych pozic - zacatek + pocet lidi se stejnymi body
|
||||
|
@ -115,16 +120,16 @@ class CisloView(generic.DetailView):
|
|||
elif predchozi_poradi :
|
||||
predchozi_poradi.poradi = '{0}.'.format(predchozi_poradi.poradi)
|
||||
#pokud nebyl rozsah hodnot, pridam tecku za cislo
|
||||
posledni_body = v.body_celkem
|
||||
posledni_body = tv.body_celkem_rocnik
|
||||
tv.poradi = vi + 1
|
||||
#poradi se meni jen u resitele s rozdilnym poctem bodu nez mel minuly
|
||||
predchozi_poradi = tv
|
||||
elif posledni_body == v.body_celkem:
|
||||
if not stejne_body.get(v.body_celkem):
|
||||
stejne_body[v.body_celkem] = 1
|
||||
elif posledni_body == tv.body_celkem_rocnik:
|
||||
if not stejne_body.get(tv.body_celkem_rocnik):
|
||||
stejne_body[tv.body_celkem_rocnik] = 1
|
||||
#pokud klic neexistuje, zalozim novy pro tohoto resitele
|
||||
else:
|
||||
stejne_body[v.body_celkem] += 1
|
||||
stejne_body[tv.body_celkem_rocnik] += 1
|
||||
#rozsirim pocet resitelu sdilejici stejnou pozici
|
||||
vysledky_resitele[v.resitel.id] = tv
|
||||
#odkaz na radek vysledkovky patrici danemu resiteli
|
||||
|
@ -132,10 +137,6 @@ class CisloView(generic.DetailView):
|
|||
|
||||
for r in reseni:
|
||||
vysledky_resitele[r.resitel.id].body[problem_index[r.problem.id]] = r.body
|
||||
body_za_cislo = vysledky_resitele[r.resitel.id].vysledek.body
|
||||
#body za toto cislo, stejne jako tv.vysledek.body
|
||||
body_celkem = vysledky_resitele[r.resitel.id].vysledek.body_celkem
|
||||
vysledky_resitele[r.resitel.id].body_minule = body_celkem - body_za_cislo
|
||||
|
||||
|
||||
context['vysledkovka'] = vysledkovka
|
||||
|
|
Loading…
Reference in a new issue