diff --git a/diff_db_backup.sh b/diff_db_backup.sh index 55d3addf..30999b8e 100755 --- a/diff_db_backup.sh +++ b/diff_db_backup.sh @@ -6,6 +6,12 @@ F2="$2" TMPF1=`tempfile` TMPF2=`tempfile` +if which colordiff; then + DIFF=colordiff +else + DIFF=diff +fi + if [ "z$F1" == "z" ]; then echo "Requies argument" exit 1 @@ -21,7 +27,7 @@ else cat "$F2" | bunzip2 > "$TMPF2" fi -colordiff "$TMPF1" "$TMPF2" +$DIFF "$TMPF1" "$TMPF2" rm "$TMPF1" "$TMPF2" diff --git a/mamweb/settings_prod.py b/mamweb/settings_prod.py index 74897882..29074b48 100644 --- a/mamweb/settings_prod.py +++ b/mamweb/settings_prod.py @@ -5,6 +5,7 @@ from .settings_common import * # See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/ INSTALLED_APPS += ( + 'django_extensions', ) # SECURITY WARNING: keep the secret key used in production secret! diff --git a/seminar/export.py b/seminar/export.py index bc8a72f3..86bce0ac 100644 --- a/seminar/export.py +++ b/seminar/export.py @@ -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) diff --git a/seminar/migrations/0028_add_body_celkem_views.py b/seminar/migrations/0028_add_body_celkem_views.py new file mode 100644 index 00000000..0f6799f0 --- /dev/null +++ b/seminar/migrations/0028_add_body_celkem_views.py @@ -0,0 +1,75 @@ +# -*- 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; +drop view seminar_body_za_cislo; + +create view seminar_body_za_cislo as + select + seminar_reseni.cislo_body_id || '-' || seminar_reseni.resitel_id as id, + seminar_reseni.cislo_body_id as cislo_id, + seminar_reseni.resitel_id as resitel_id, + seminar_cisla.cislo as cislo, + seminar_cisla.rocnik_id as rocnik_id, + seminar_rocniky.rocnik as rocnik, + seminar_cisla.verejna_vysledkovka as verejna_vysledkovka, + sum(seminar_reseni.body) as body + from + seminar_reseni + inner join seminar_cisla on seminar_reseni.cislo_body_id = seminar_cisla.id + inner join seminar_rocniky on seminar_cisla.rocnik_id = seminar_rocniky.id + group by seminar_reseni.cislo_body_id, seminar_reseni.resitel_id, seminar_cisla.cislo, + seminar_cisla.rocnik_id, seminar_rocniky.rocnik, seminar_cisla.verejna_vysledkovka + order by body desc; + +create view seminar_body_k_cislu_rocnik as + select + akt_body.id as id, + akt_body.cislo_id as cislo_id, + akt_body.resitel_id as resitel_id, + akt_body.body as body, + sum(min_body.body) as body_celkem + from + seminar_body_za_cislo as akt_body + inner join seminar_body_za_cislo as min_body on + (akt_body.resitel_id = min_body.resitel_id and + (akt_body.rocnik = min_body.rocnik and akt_body.cislo >= min_body.cislo) + ) + group by akt_body.id, akt_body.cislo_id, akt_body.resitel_id, akt_body.body + order by body_celkem desc; + +create view seminar_body_k_cislu_odjakziva as + select + akt_body.id as id, + akt_body.cislo_id as cislo_id, + akt_body.resitel_id as resitel_id, + akt_body.body as body, + sum(min_body.body) as body_celkem + from + seminar_body_za_cislo as akt_body + inner join seminar_body_za_cislo as min_body on + (akt_body.resitel_id = min_body.resitel_id and + ((akt_body.rocnik = min_body.rocnik and akt_body.cislo >= min_body.cislo) or + (akt_body.rocnik < min_body.rocnik) + ) + ) + group by akt_body.id, akt_body.cislo_id, akt_body.resitel_id, akt_body.body + order by body_celkem desc; + +""" + +class Migration(migrations.Migration): + + dependencies = [("seminar", "0027_export_flag_a_typ_akce")] + + operations = [ + migrations.RunSQL(sql=CREATE_VIEWS) + ] + diff --git a/seminar/migrations/0029_fix_body_celkem_views.py b/seminar/migrations/0029_fix_body_celkem_views.py new file mode 100644 index 00000000..5e287747 --- /dev/null +++ b/seminar/migrations/0029_fix_body_celkem_views.py @@ -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) + ] + diff --git a/seminar/models.py b/seminar/models.py index 2e8daa4a..c484abb8 100644 --- a/seminar/models.py +++ b/seminar/models.py @@ -650,9 +650,9 @@ class VysledkyBase(SeminarModelBase): def __str__(self): return force_unicode(u"%s: %sb (%s)" % (self.resitel.plne_jmeno(), self.body, str(self.cislo))) - # NOTE: DB HOG (ale nepouzivany) + # NOTE: DB zatez pri vypisu (ale nepouzivany) + -@python_2_unicode_compatible class VysledkyZaCislo(VysledkyBase): class Meta: @@ -660,25 +660,27 @@ class VysledkyZaCislo(VysledkyBase): abstract = False managed = False - def __str__(self): - # NOTE: DB HOG (ale nepouzivany) - return force_unicode(u"%s: %sb (za %s)" % (self.resitel.plne_jmeno(), self.body, str(self.cislo))) - -@python_2_unicode_compatible -class VysledkyKCislu(VysledkyBase): +class VysledkyKCisluZaRocnik(VysledkyBase): class Meta: - db_table = 'seminar_body_k_cislu' + 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') +# body = models.DecimalField(max_digits=8, decimal_places=1, db_column='body', +# verbose_name=u'body do čísla (za ročník)') - def __str__(self): - # NOTE: DB HOG (ale nepouzivany) - return force_unicode(u"%s: %sb / %sb (do %s)" % (self.resitel.plne_jmeno(), self.body, self.body_celkem, str(self.cislo))) + +class VysledkyKCisluOdjakziva(VysledkyBase): + + class Meta: + db_table = 'seminar_body_k_cislu_odjakziva' + abstract = False + managed = False + +# body = models.DecimalField(max_digits=8, decimal_places=1, db_column='body', +# verbose_name=u'body do čísla (i minulé ročníky)') @python_2_unicode_compatible diff --git a/seminar/templates/seminar/archiv/cislo.html b/seminar/templates/seminar/archiv/cislo.html index a7096fec..d14073e6 100644 --- a/seminar/templates/seminar/archiv/cislo.html +++ b/seminar/templates/seminar/archiv/cislo.html @@ -34,17 +34,19 @@ {% for p in problemy %}
{% for n, c in jmena_muzu.items %}{{ n }} ({{ c }}), {% endfor %}
+
{% for n, c in jmena_zen.items %}{{ n }} ({{ c }}), {% endfor %}
+
+