From 9374df8c6929db50d65d5334aac60487892534ea Mon Sep 17 00:00:00 2001 From: Mee Date: Fri, 17 May 2019 00:29:43 +0200 Subject: [PATCH 01/15] =?UTF-8?q?Migrace=20Organizatora,=20aby=20se=20u?= =?UTF-8?q?=C5=BE=20nikde=20nepou=C5=BE=C3=ADval=20Djangov=C3=BD=20user?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migrations/0052_user_to_organizator.py | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 seminar/migrations/0052_user_to_organizator.py diff --git a/seminar/migrations/0052_user_to_organizator.py b/seminar/migrations/0052_user_to_organizator.py new file mode 100644 index 00000000..15d9102e --- /dev/null +++ b/seminar/migrations/0052_user_to_organizator.py @@ -0,0 +1,71 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.15 on 2019-05-16 20:59 +from __future__ import unicode_literals + +from django.db import migrations + +def spoj_k_organizatorum_osoby(apps, scema_editor): + Organizator = apps.get_model('seminar', 'Organizator') + Resitel = apps.get_model('seminar', 'Resitel') + for org in Organizator.objects.all(): + + # Spárování organizátora s osobou + user = org.user + resitele = Resitel.objects.filter(user=user) + if resitele.count() != 0: + osoba = resitele.first().osoba + else: + osoba = Osoba(user=user) + org.osoba = osoba + + # Přesun informací z organizátora do jeho osoby + osoba.prezdivka = org.prezdivka + osoba.foto = org.foto + osoba.foto_male = org.foto_male + + # Všechno uložit + osoba.save() + org.save() + +def fix_problem(apps, schema_editor): + Problem = apps.get_model('seminar', 'Problem') + Organizator = apps.get_model('seminar', 'Organizator') + for pr in Problem.objects.all(): + if pr.autor_old is not None: + pr.autor = Organizator.objects.filter(osoba__user=pr.autor_old).first() + else: + pr.autor = None + if pr.opravovatel is not None: + pr.opravovatele.add(Organizator.objects.filter(osoba__user=pr.opravovatel).first()) + pr.save() + +def fix_pohadka(apps, schema_editor): + Pohadka = apps.get_model('seminar', 'Pohadka') + Organizator = apps.get_model('seminar', 'Organizator') + for poh in Pohadka.objects.all(): + if poh.autor_old is not None: + poh.autor = Organizator.objects.filter(osoba__user=poh.autor_old).first() + else: + poh.autor = None + poh.save() + +def fix_novinka(apps, schema_editor): + Novinky = apps.get_model('seminar', 'Novinky') + Organizator = apps.get_model('seminar', 'Organizator') + for nov in Novinky.objects.all(): + nov.autor = Organizator.objects.filter(osoba__user=nov.autor_old).first() + + + +class Migration(migrations.Migration): + + dependencies = [ + ('seminar', '0051_resitel_to_osoba'), + ] + + operations = [ + migrations.RunPython(spoj_k_organizatorum_osoby), + migrations.RunPython(fix_problem), + migrations.RunPython(fix_pohadka), + migrations.RunPython(fix_novinka), + ] From d54ff1be76cdb1a6a5f229d8434c94d84234e440 Mon Sep 17 00:00:00 2001 From: "Tomas \"Jethro\" Pokorny" Date: Fri, 17 May 2019 00:44:24 +0200 Subject: [PATCH 02/15] Bugfixy v migraci --- seminar/migrations/0052_user_to_organizator.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/seminar/migrations/0052_user_to_organizator.py b/seminar/migrations/0052_user_to_organizator.py index 15d9102e..8bdf9ef0 100644 --- a/seminar/migrations/0052_user_to_organizator.py +++ b/seminar/migrations/0052_user_to_organizator.py @@ -7,6 +7,7 @@ from django.db import migrations def spoj_k_organizatorum_osoby(apps, scema_editor): Organizator = apps.get_model('seminar', 'Organizator') Resitel = apps.get_model('seminar', 'Resitel') + Osoba = apps.get_model('seminar', 'Osoba') for org in Organizator.objects.all(): # Spárování organizátora s osobou @@ -21,7 +22,6 @@ def spoj_k_organizatorum_osoby(apps, scema_editor): # Přesun informací z organizátora do jeho osoby osoba.prezdivka = org.prezdivka osoba.foto = org.foto - osoba.foto_male = org.foto_male # Všechno uložit osoba.save() @@ -54,6 +54,7 @@ def fix_novinka(apps, schema_editor): Organizator = apps.get_model('seminar', 'Organizator') for nov in Novinky.objects.all(): nov.autor = Organizator.objects.filter(osoba__user=nov.autor_old).first() + nov.save() From c8dadcd3649469ddfcc6ea3d272f969d71067d39 Mon Sep 17 00:00:00 2001 From: Mee Date: Fri, 17 May 2019 00:44:59 +0200 Subject: [PATCH 03/15] Migr 0052 fix prezdivka --- seminar/migrations/0052_user_to_organizator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seminar/migrations/0052_user_to_organizator.py b/seminar/migrations/0052_user_to_organizator.py index 8bdf9ef0..4ebcd1d0 100644 --- a/seminar/migrations/0052_user_to_organizator.py +++ b/seminar/migrations/0052_user_to_organizator.py @@ -20,7 +20,7 @@ def spoj_k_organizatorum_osoby(apps, scema_editor): org.osoba = osoba # Přesun informací z organizátora do jeho osoby - osoba.prezdivka = org.prezdivka + osoba.prezdivka = org.prezdivka if org.prezdivka is not None else '' osoba.foto = org.foto # Všechno uložit From 6706bebdb74689797eb178acd49a359dc1fcf6cd Mon Sep 17 00:00:00 2001 From: "Tomas \"Jethro\" Pokorny" Date: Fri, 17 May 2019 01:07:06 +0200 Subject: [PATCH 04/15] Osobu je potreba ulozit, nez se da priradit. --- seminar/migrations/0052_user_to_organizator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seminar/migrations/0052_user_to_organizator.py b/seminar/migrations/0052_user_to_organizator.py index 4ebcd1d0..996eb21d 100644 --- a/seminar/migrations/0052_user_to_organizator.py +++ b/seminar/migrations/0052_user_to_organizator.py @@ -17,7 +17,6 @@ def spoj_k_organizatorum_osoby(apps, scema_editor): osoba = resitele.first().osoba else: osoba = Osoba(user=user) - org.osoba = osoba # Přesun informací z organizátora do jeho osoby osoba.prezdivka = org.prezdivka if org.prezdivka is not None else '' @@ -25,6 +24,7 @@ def spoj_k_organizatorum_osoby(apps, scema_editor): # Všechno uložit osoba.save() + org.osoba = osoba org.save() def fix_problem(apps, schema_editor): From f054d9785a75020823759437237c6b8d5a84a3be Mon Sep 17 00:00:00 2001 From: "Tomas \"Jethro\" Pokorny" Date: Fri, 17 May 2019 19:42:49 +0200 Subject: [PATCH 05/15] Opraveno organizuje od a organizuje do --- seminar/migrations/0049_auto_20190430_2354.py | 2 +- .../0053_organizator_organizuje_od_do.py | 36 +++++++++++++++++++ seminar/models.py | 2 +- 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 seminar/migrations/0053_organizator_organizuje_od_do.py diff --git a/seminar/migrations/0049_auto_20190430_2354.py b/seminar/migrations/0049_auto_20190430_2354.py index 7f374be3..8957b010 100644 --- a/seminar/migrations/0049_auto_20190430_2354.py +++ b/seminar/migrations/0049_auto_20190430_2354.py @@ -219,7 +219,7 @@ class Migration(migrations.Migration): migrations.AddField( model_name='organizator', name='organizuje_od', - field=models.DateTimeField(default='1900-01-01T00:00:00', verbose_name='Organizuje od'), + field=models.DateTimeField(null=True,blank=True, verbose_name='Organizuje od'), ), migrations.AddField( model_name='organizator', diff --git a/seminar/migrations/0053_organizator_organizuje_od_do.py b/seminar/migrations/0053_organizator_organizuje_od_do.py new file mode 100644 index 00000000..b94e8032 --- /dev/null +++ b/seminar/migrations/0053_organizator_organizuje_od_do.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.20 on 2019-05-16 21:26 +from __future__ import unicode_literals + +import datetime as dt +from django.db import migrations + +def rok_to_datetime(apps,schema_editor): + Organizator = apps.get_model('seminar','Organizator') + for o in Organizator.objects.all(): + rok = o.organizuje_od_roku + if rok: + o.organizuje_od = dt.datetime(rok,1,1) + rok = o.organizuje_do_roku + if rok: + o.organizuje_do = dt.datetime(rok,12,31) + o.save() + +def datetime_to_rok(apps,schema_editor): + Organizator = apps.get_model('seminar','Organizator') + for o in Organizator.objects.all(): + o.organizuje_od_roku = o.organizuje_od.year + o.organizuje_do_roku = o.organizuje_do.year + o.save() + + + +class Migration(migrations.Migration): + + dependencies = [ + ('seminar', '0052_user_to_organizator'), + ] + + operations = [ + migrations.RunPython(rok_to_datetime, datetime_to_rok), + ] diff --git a/seminar/models.py b/seminar/models.py index 1ab29ee8..8466f5a9 100644 --- a/seminar/models.py +++ b/seminar/models.py @@ -467,7 +467,7 @@ class Organizator(SeminarModelBase): editable=False ) - organizuje_od = models.DateTimeField('Organizuje od', blank=False, null=False, default="1900-01-01T00:00:00") + organizuje_od = models.DateTimeField('Organizuje od', blank=True, null=True) organizuje_do = models.DateTimeField('Organizuje do', blank=True, null=True) From 14bd827df072fe38f4fba20fb4e76cb91d648f8f Mon Sep 17 00:00:00 2001 From: "Tomas \"Jethro\" Pokorny" Date: Fri, 17 May 2019 20:55:19 +0200 Subject: [PATCH 06/15] Pridano migrovani uloh. --- .../0054_problem_to_uloha_tema_clanek.py | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 seminar/migrations/0054_problem_to_uloha_tema_clanek.py diff --git a/seminar/migrations/0054_problem_to_uloha_tema_clanek.py b/seminar/migrations/0054_problem_to_uloha_tema_clanek.py new file mode 100644 index 00000000..66f529df --- /dev/null +++ b/seminar/migrations/0054_problem_to_uloha_tema_clanek.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.20 on 2019-05-17 17:44 +from __future__ import unicode_literals + +from django.db import migrations + +def uloha_to_Uloha(apps,schema_editor): + Problem = apps.get_model('seminar', 'Problem') + Uloha = apps.get_model('seminar', 'Uloha') + Text = apps.get_model('seminar', 'Text') + + ulohy = Problem.objects.filter(typ = 'uloha') + for uold in ulohy: + zadani = Text.objects.create(na_web = uold.text_zadani) + vzorak = Text.objects.create(na_web = uold.text_reseni) + unew = Uloha.objects.create( + nazev = uold.nazev, + stav = uold.stav, + zamereni = uold.zamereni, + poznamka = uold.poznamka, + zadani = zadani, + vzorak = vzorak, + autor = uold.autor, + kod = uold.kod, + cislo_zadani = uold.cislo_zadani_old, + cislo_reseni = uold.cislo_reseni_old, + max_body = uold.body, + vytvoreno = uold.vytvoreno, + ) + unew.opravovatele.add(*uold.opravovatele.all()) + unew.save() + +def tema_to_Tema(apps, schema_editor): + Problem = apps.get_model('seminar', 'Problem') + Tema = apps.get_model('seminar', 'Tema') + Text = apps.get_model('seminar', 'Text') + + temata = Problem.objects.filter(typ = 'tema') +# Bordel bordel bordel. Téma nemá zadání, je potřeba vyrobit TemaVCisleNode + + + +class Migration(migrations.Migration): + + dependencies = [ + ('seminar', '0053_organizator_organizuje_od_do'), + ] + + operations = [ + migrations.RunPython(uloha_to_Uloha), + ] From 31fe029a98ad0eda12e46fc79f31bb41d133d44f Mon Sep 17 00:00:00 2001 From: "Tomas \"Jethro\" Pokorny" Date: Fri, 17 May 2019 21:18:10 +0200 Subject: [PATCH 07/15] Logovaci masinerie explicitne --- mamweb/settings_local.py | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/mamweb/settings_local.py b/mamweb/settings_local.py index 501326dd..885e2b9e 100644 --- a/mamweb/settings_local.py +++ b/mamweb/settings_local.py @@ -47,7 +47,43 @@ DATABASES = { #} # LOGGING +LOGGING = { + 'version': 1, + 'disable_existing_loggers': True, + 'filters': { + 'require_debug_false': { + '()': 'django.utils.log.RequireDebugFalse' + } + }, + 'formatters': { + 'simple': { + 'format': '%(asctime)s - %(name)s - %(levelname)-8s - %(message)s', + }, + }, + 'handlers': { + 'dummy': { + 'class': 'logging.NullHandler', + }, + 'console': { + 'level': 'DEBUG', + 'class': 'logging.StreamHandler', + 'formatter': 'simple', + }, + }, + 'loggers': { + # Vypisovani databazovych dotazu do konzole + 'django.db.backends': { + 'level': 'DEBUG', + 'handlers': ['console'], + 'propagate': False, + }, + '': { + 'handlers': ['console'], + 'level': 'DEBUG', + 'propagate': False, + }, + }, +} # set to 'DEBUG' for EXTRA verbose output -LOGGING['handlers']['console']['level'] = 'INFO' - +# LOGGING['handlers']['console']['level'] = 'INFO' From 2b8241e9eab5c4a96121b0570e4cf2e03942d699 Mon Sep 17 00:00:00 2001 From: "Tomas \"Jethro\" Pokorny" Date: Sat, 18 May 2019 10:26:58 +0200 Subject: [PATCH 08/15] Jmeno, prijmeni a email do osoby, ne do usera. --- seminar/migrations/0051_resitel_to_osoba.py | 29 +++++++++++++++++++ .../migrations/0052_user_to_organizator.py | 10 +++++++ 2 files changed, 39 insertions(+) diff --git a/seminar/migrations/0051_resitel_to_osoba.py b/seminar/migrations/0051_resitel_to_osoba.py index f71d88eb..0eb1433e 100644 --- a/seminar/migrations/0051_resitel_to_osoba.py +++ b/seminar/migrations/0051_resitel_to_osoba.py @@ -23,6 +23,35 @@ def resitel_to_osoba(apps,schema_editor): o.telefon = r.telefon o.ulice = r.ulice o.user = r.user + if o.user: + u = o.user + if u.first_name: + if not o.jmeno: + o.jmeno = u.first_name + u.first_name = 'Použij osobu!' + elif o.jmeno == u.first_name: + u.first_name = 'Použij osobu!' + else: + raise ValueError('jmeno a first_name rozdílné: "{}" vs. "{}"'.format(o.jmeno, u.first_name)) + if u.last_name: + if not o.prijmeni: + o.prijmeni = u.last_name + u.last_name = 'Použij osobu!' + elif o.prijmeni == u.last_name: + u.last_name = 'Použij osobu!' + else: + raise ValueError('prijmeni a last_name rozdílné: "{}" vs. "{}"'.format(o.prijmeni, u.last_name)) + if u.email: + if not o.email: + o.email = u.email + u.email = 'Použij osobu!' + elif o.email == u.email: + u.email = 'Použij osobu!' + else: + raise ValueError('o.email a u.email rozdílné: "{}" vs. "{}"'.format(o.email, u.first_name)) + u.save() + + o.save() r.osoba = o r.save() diff --git a/seminar/migrations/0052_user_to_organizator.py b/seminar/migrations/0052_user_to_organizator.py index 996eb21d..d52e29ca 100644 --- a/seminar/migrations/0052_user_to_organizator.py +++ b/seminar/migrations/0052_user_to_organizator.py @@ -18,6 +18,16 @@ def spoj_k_organizatorum_osoby(apps, scema_editor): else: osoba = Osoba(user=user) + # Přesun informací z usera do osoby + # pro řešitele již v minule migraci + osoba.jmeno = user.first_name + osoba.prijmeni = user.last_name + osoba.email = user.email + user.jmeno = "Použij osobu!" + user.prijmeni = "Použij osobu!" + user.email = "Použij osobu!" + user.save() + # Přesun informací z organizátora do jeho osoby osoba.prezdivka = org.prezdivka if org.prezdivka is not None else '' osoba.foto = org.foto From 4a359615fd8be99ba0481b6484c32ff1a0fe539a Mon Sep 17 00:00:00 2001 From: "Tomas \"Jethro\" Pokorny" Date: Sat, 18 May 2019 10:57:09 +0200 Subject: [PATCH 09/15] =?UTF-8?q?models.py=20vy=C4=8Di=C5=A1t=C4=9Bno=20fo?= =?UTF-8?q?rce=5Funicode,=20u=C4=8Des=C3=A1no=20=5F=5Fstr=5F=5F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/models.py | 95 +++++++++++++++++++++-------------------------- 1 file changed, 42 insertions(+), 53 deletions(-) diff --git a/seminar/models.py b/seminar/models.py index 8466f5a9..f5dd6703 100644 --- a/seminar/models.py +++ b/seminar/models.py @@ -40,13 +40,12 @@ class SeminarModelBase(models.Model): def admin_url(self): model_name = self.__class__.__name__.lower() - return reverse('admin:seminar_%s_change'%(model_name, ), args=(self.id, )) + return reverse('admin:seminar_{}_change'.format(model_name), args=(self.id, )) def verejne_url(self): return None @reversion.register(ignore_duplicates=True) -@python_2_unicode_compatible class Osoba(SeminarModelBase): class Meta: @@ -117,14 +116,14 @@ class Osoba(SeminarModelBase): options={'quality': 95}) def plne_jmeno(self): - return force_unicode('%s %s' % (self.jmeno, self.prijmeni)) + return '{} {}'.format(self.jmeno, self.prijmeni) def inicial_krestni(self): jmena = self.jmeno.split() return " ".join(['{}.'.format(jmeno[0]) for jmeno in jmena]) def __str__(self): - return force_unicode("Osoba({})".format(self.plne_jmeno())) + return self.plne_jmeno() # # Mělo by být částečně vytaženo z Aesopa @@ -132,7 +131,6 @@ class Osoba(SeminarModelBase): # @reversion.register(ignore_duplicates=True) -@python_2_unicode_compatible class Skola(SeminarModelBase): class Meta: @@ -185,7 +183,7 @@ class Skola(SeminarModelBase): blank=True, null=True) def __str__(self): - return force_unicode('%s, %s, %s' % (self.nazev, self.ulice, self.mesto)) + return '{}, {}, {}'.format(self.nazev, self.ulice, self.mesto) class Prijemce(SeminarModelBase): class Meta: @@ -204,10 +202,12 @@ class Prijemce(SeminarModelBase): help_text='Které osobě či na jakou adresu se mají zasílat čísla') # FIXME: možná chceme něco jako vazbu na osobu XOR školu a počet kusů k zaslání + + def __str__(self): + return self.osoba.plne_jmeno() @reversion.register(ignore_duplicates=True) -@python_2_unicode_compatible class Resitel(SeminarModelBase): class Meta: @@ -292,12 +292,11 @@ class Resitel(SeminarModelBase): else: return 'Akad.' def __str__(): - return(force_unicode(u"Řešitel ({})".format(self.osoba.plne_jmeno()))) + return self.osoba.plne_jmeno() @reversion.register(ignore_duplicates=True) -@python_2_unicode_compatible class Rocnik(SeminarModelBase): class Meta: @@ -317,11 +316,11 @@ class Rocnik(SeminarModelBase): help_text='Exportuje se jen podle tohoto flagu (ne veřejnosti), a to jen čísla s veřejnou výsledkovkou') def __str__(self): - return force_unicode('%s (%d/%d)' % (self.rocnik, self.prvni_rok, self.prvni_rok+1)) + return '{} ({}/{})'.format(self.rocnik, self.prvni_rok, self.prvni_rok+1) # Ročník v římských číslech def roman(self): - return force_unicode(roman(int(self.rocnik))) + return roman(int(self.rocnik)) def verejne(self): return len(self.verejna_cisla()) > 0 @@ -367,7 +366,6 @@ def cislo_pdf_filename(self, filename): return os.path.join('cislo', 'pdf', rocnik, '{}-{}.pdf'.format(rocnik, self.cislo)) @reversion.register(ignore_duplicates=True) -@python_2_unicode_compatible class Cislo(SeminarModelBase): class Meta: @@ -418,7 +416,7 @@ class Cislo(SeminarModelBase): def __str__(self): # Potenciální DB HOG, pokud by se ročník necachoval r = Rocnik.cached_rocnik(self.rocnik_id) - return force_unicode('%s.%s' % (r.rocnik, self.cislo, )) + return '{}.{}'.format(r.rocnik, self.cislo) def verejne(self): return self.verejne_db @@ -428,15 +426,15 @@ class Cislo(SeminarModelBase): return reverse('seminar_cislo', kwargs={'rocnik': self.rocnik.rocnik, 'cislo': self.cislo}) def nasledujici(self): - u"Vrací None, pokud je toto poslední" + "Vrací None, pokud je toto poslední" return self.relativni_v_rocniku(1) def predchozi(self): - u"Vrací None, pokud je toto první" + "Vrací None, pokud je toto první" return self.relativni_v_rocniku(-1) def relativni_v_rocniku(self, rel_index): - u"Číslo o `index` dále v ročníku. None pokud neexistuje." + "Číslo o `index` dále v ročníku. None pokud neexistuje." cs = self.rocnik.cisla.order_by('cislo').all() i = list(cs).index(self) + rel_index if (i < 0) or (i >= len(cs)): @@ -453,7 +451,6 @@ class Cislo(SeminarModelBase): return c @reversion.register(ignore_duplicates=True) -@python_2_unicode_compatible class Organizator(SeminarModelBase): # zmena dedicnosti z models.Model na SeminarModelBase, potencialni vznik bugu @@ -486,18 +483,17 @@ class Organizator(SeminarModelBase): def __str__(self): if self.osoba.prezdivka: - return u"%s '%s' %s".format(self.osoba.jmeno, + return "{} '{}' {}".format(self.osoba.jmeno, self.osoba.prezdivka, self.osoba.prijmeni) else: - return u"%s %s".format(self.osoba.jmeno, self.osoba.prijmeni) + return "{} {}".format(self.osoba.jmeno, self.osoba.prijmeni) class Meta: verbose_name = 'Organizátor' verbose_name_plural = 'Organizátoři' @reversion.register(ignore_duplicates=True) -@python_2_unicode_compatible class Soustredeni(SeminarModelBase): class Meta: @@ -546,7 +542,7 @@ class Soustredeni(SeminarModelBase): help_text='Exportuje se jen podle tohoto flagu (ne veřejnosti)') def __str__(self): - return force_unicode('%s (%s)'.format(self.misto, self.datum_zacatku)) + return '{} ({})'.format(self.misto, self.datum_zacatku) def verejne(self): return self.verejne_db @@ -559,7 +555,6 @@ class Soustredeni(SeminarModelBase): @reversion.register(ignore_duplicates=True) -@python_2_unicode_compatible class Problem(SeminarModelBase): class Meta: @@ -616,7 +611,7 @@ class Problem(SeminarModelBase): def __str__(self): - return force_unicode('%s' % (self.nazev, )) + return self.nazev # Implicitini implementace, jednotlivé dědící třídy si přepíšou def kod_v_rocniku(self): @@ -649,7 +644,7 @@ class Problem(SeminarModelBase): if self.body: b = self.body pocet_bodu = int(b) if int(b) == b else b - return u"({}\u2009b)".format(pocet_bodu) if self.body else "" + return "({}\u2009b)".format(pocet_bodu) if self.body else "" class Tema(Problem): class Meta: @@ -670,8 +665,8 @@ class Tema(Problem): def kod_v_rocniku(self): if self.stav == 'zadany': if self.nadproblem: - return force_unicode(self.nadproblem.kod_v_rocniku()+".t{}".format(self.kod)) - return force_unicode("t{}".format(self.kod)) + return self.nadproblem.kod_v_rocniku()+".t{}".format(self.kod) + return "t{}".format(self.kod) return '' class Clanek(Problem): @@ -686,7 +681,7 @@ class Clanek(Problem): # Nemělo by být potřeba # if self.nadproblem: # return force_unicode(self.nadproblem.kod_v_rocniku()+".c{}".format(self.kod)) - return force_unicode("c{}".format(self.kod)) + return "c{}".format(self.kod) return '' class Text(SeminarModelBase): @@ -727,16 +722,15 @@ class Uloha(Problem): def kod_v_rocniku(self): if self.stav == 'zadany': - name=u"{}.u{}".format(self.cislo_zadani.cislo,self.kod) + name="{}.u{}".format(self.cislo_zadani.cislo,self.kod) if self.nadproblem: - return force_unicode(self.nadproblem.kod_v_rocniku()+name) - return force_unicode(name) + return self.nadproblem.kod_v_rocniku()+name + return name return '' @reversion.register(ignore_duplicates=True) -@python_2_unicode_compatible class Reseni(SeminarModelBase): class Meta: @@ -783,8 +777,7 @@ class Reseni(SeminarModelBase): help_text='Udává, zda je řešení zveřejněno') def __str__(self): - return force_unicode(u"%s: %s".format(self.resitel.osoba.plne_jmeno(), - self.problem.nazev)) + return "{}: {}".format(self.resitel.osoba.plne_jmeno(), self.problem.nazev) # NOTE: Potenciální DB HOG (bez select_related) ## Pravdepodobne uz nebude potreba: @@ -814,6 +807,9 @@ class Hodnoceni(SeminarModelBase): problem = models.ForeignKey(Problem, verbose_name='problém') + def __str__(self): + return "{}, {}, {}".format(self.problem, self.reseni, self.body) + ## FIXME: Budeme řešit později, pokud to bude potřeba. @@ -849,7 +845,6 @@ def generate_filename(self, filename): @reversion.register(ignore_duplicates=True) -@python_2_unicode_compatible class PrilohaReseni(SeminarModelBase): class Meta: @@ -871,10 +866,9 @@ class PrilohaReseni(SeminarModelBase): help_text='Neveřejná poznámka k příloze řešení (plain text), např. o původu') def __str__(self): - return force_unicode(self.soubor) + return self.soubor -@python_2_unicode_compatible class Pohadka(SeminarModelBase): u"""Kus pohádky před/za úlohou v čísle""" @@ -917,11 +911,10 @@ class Pohadka(SeminarModelBase): def __str__(self): uryvek = self.text if len(self.text) < 50 else self.text[:(50-3)]+"..." - return force_unicode(uryvek) + return uryvek @reversion.register(ignore_duplicates=True) -@python_2_unicode_compatible class Soustredeni_Ucastnici(SeminarModelBase): # zmena dedicnosti z models.Model na SeminarModelBase, potencialni vznik bugu @@ -942,11 +935,10 @@ class Soustredeni_Ucastnici(SeminarModelBase): help_text='Neveřejná poznámka k účasti (plain text)') def __str__(self): - return force_unicode('%s na %s'.format(self.resitel, self.soustredeni)) + return '{} na {}'.format(self.resitel, self.soustredeni) # NOTE: Poteciální DB HOG bez select_related @reversion.register(ignore_duplicates=True) -@python_2_unicode_compatible class Soustredeni_Organizatori(SeminarModelBase): # zmena dedicnosti z models.Model na SeminarModelBase, potencialni vznik bugu @@ -967,13 +959,12 @@ class Soustredeni_Organizatori(SeminarModelBase): help_text='Neveřejná poznámka k účasti organizátora (plain text)') def __str__(self): - return force_unicode('%s na %s'.format(self.organizator, self.soustredeni)) + return '{} na {}'.format(self.organizator, self.soustredeni) # NOTE: Poteciální DB HOG bez select_related @reversion.register(ignore_duplicates=True) -@python_2_unicode_compatible class Konfera(models.Model): class Meta: db_table = 'seminar_konfera' @@ -1023,12 +1014,11 @@ class Konfera(models.Model): upload_to = generate_filename_konfera, blank=True) def __str__(self): - return force_unicode(u"%s: (%s)".format(self.nazev, self.soustredeni)) + return "{}: ({})".format(self.nazev, self.soustredeni) # Vazebna tabulka. Mozna se generuje automaticky. @reversion.register(ignore_duplicates=True) -@python_2_unicode_compatible class Reseni_Resitele(models.Model): class Meta: @@ -1045,11 +1035,10 @@ class Reseni_Resitele(models.Model): reseni = models.ForeignKey(Reseni, verbose_name='řešení') def __str__(self): - return force_unicode('%s od %s'.format(self.reseni, self.resitel)) + return '{} od {}'.format(self.reseni, self.resitel) # NOTE: Poteciální DB HOG bez select_related @reversion.register(ignore_duplicates=True) -@python_2_unicode_compatible class Konfery_Ucastnici(models.Model): class Meta: @@ -1069,7 +1058,7 @@ class Konfery_Ucastnici(models.Model): help_text='Neveřejná poznámka k účasti (plain text)') def __str__(self): - return force_unicode('%s na %s'.format(self.resitel, self.konfera, )) + return '{} na {}'.format(self.resitel, self.konfera) # NOTE: Poteciální DB HOG bez select_related class Obrazek(SeminarModelBase): @@ -1283,6 +1272,12 @@ class Nastaveni(SingletonModel): @reversion.register(ignore_duplicates=True) @python_2_unicode_compatible class Novinky(models.Model): + + class Meta: + verbose_name = 'Novinka' + verbose_name_plural = 'Novinky' + ordering = ['-datum'] + datum = models.DateField(auto_now_add=True) text = models.TextField('Text novinky', blank=True, null=True) @@ -1302,9 +1297,3 @@ class Novinky(models.Model): def __str__(self): return '[' + str(self.datum) + '] ' + self.text[0:50] - - class Meta: - verbose_name = 'Novinka' - verbose_name_plural = 'Novinky' - ordering = ['-datum'] - From 085dc6ad485a4ad2e5fb537a865cafc6a42c976e Mon Sep 17 00:00:00 2001 From: "Tomas \"Jethro\" Pokorny" Date: Sun, 19 May 2019 10:22:00 +0200 Subject: [PATCH 10/15] Korektury funguji v novem modelu. --- korektury/models.py | 4 ++-- korektury/views.py | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/korektury/models.py b/korektury/models.py index ab9cf62f..553fa797 100644 --- a/korektury/models.py +++ b/korektury/models.py @@ -155,7 +155,7 @@ class Oprava(models.Model): # setattr(self,k,v) def __str__(self): - return force_unicode(u'%s od %s: %s'%(self.status,self.autor,self.text)) + return '{} od {}: {}'.format(self.status,self.autor,self.text) @@ -181,7 +181,7 @@ class Komentar(models.Model): text = models.TextField(u'text komentáře',blank = True, help_text='Text komentáře') def __str__(self): - return force_unicode(u'%s od %s: %s'%(self.cas,self.autor,self.text)) + return '{} od {}: {}'.format(self.cas,self.autor,self.text) diff --git a/korektury/views.py b/korektury/views.py index fe2577bb..a18e5299 100644 --- a/korektury/views.py +++ b/korektury/views.py @@ -35,7 +35,7 @@ class KorekturyView(generic.TemplateView): # prirazeni autora podle prihlaseni autor_user = request.user # pokud existuje ucet (user), ale neni to organizator = 403 - autor = Organizator.objects.filter(user=autor_user).first() + autor = Organizator.objects.filter(osoba__user=autor_user).first() if not autor: return HttpResponseForbidden() @@ -133,24 +133,24 @@ class KorekturyView(generic.TemplateView): # Prijemci e-mailu emails = set() # e-mail autora korektury - email = oprava.autor.user.email + email = oprava.autor.osoba.email if email: emails.add(email) # nalezeni e-mailu na autory komentaru for komentar in oprava.komentar_set.all(): - email_komentujiciho = komentar.autor.user.email + email_komentujiciho = komentar.autor.osoba.email if email_komentujiciho: emails.add(email_komentujiciho) # zodpovedny org if oprava.pdf.org: - email_zobpovedny = oprava.pdf.org.user.email + email_zobpovedny = oprava.pdf.org.osoba.email if email_zobpovedny: emails.add(email_zobpovedny) # odstran e-mail autora opravy - email = autor.user.email + email = autor.osoba.email if email: emails.discard(email) From e90d6a6f83c954c7dc7c092f19e457162b5b00c8 Mon Sep 17 00:00:00 2001 From: "Tomas \"Jethro\" Pokorny" Date: Sun, 19 May 2019 11:06:29 +0200 Subject: [PATCH 11/15] Uklid v CSS korektur. --- korektury/static/korektury/opraf.css | 87 +++++++----------------- korektury/static/korektury/opraf.js | 35 ++-------- korektury/templates/korektury/opraf.html | 19 ++++-- 3 files changed, 46 insertions(+), 95 deletions(-) diff --git a/korektury/static/korektury/opraf.css b/korektury/static/korektury/opraf.css index 33146e1b..4a731de4 100644 --- a/korektury/static/korektury/opraf.css +++ b/korektury/static/korektury/opraf.css @@ -13,72 +13,46 @@ body, img{background:white;} +/* Barvy korektur */ +.k_oprave { + --rgb: 255, 0, 0; +} +.opraveno { + --rgb: 0, 0, 255; +} +.neni_chyba { + --rgb: 128, 128, 128; +} +.k_zaneseni { + --rgb: 0, 255, 0; +} + .pointer-hi, -.pointer, -.pointer-wontfix, -.pointer-wontfix-hi, -.pointer-ready, -.pointer-ready-hi, -.pointer-done, -.pointer-done-hi { +.pointer{ position:absolute; /*border-bottom-left-radius: 10px; */ border-left: 2px solid yellow; border-bottom: 2px solid yellow; + border-color: rgb(var(--rgb),var(--alpha)); } -.pointer-done-hi, -.pointer-wontfix-hi, -.pointer-ready-hi, -.pointer-hi { - border-width: 3px; +.pointer { + border-width: 1px; + --alpha: 0.35; } -.pointer { - border-color: #F00; /*IE*/ - border-color: rgba(255, 0, 0, 0.35); -} .pointer-hi { - border-color: #F00; /*IE*/ - border-color: rgba(255, 0, 0, 1); -} -.pointer-done { - border-color: #00F; /*IE*/ - border-color: rgba(0, 0, 255, 0.2); -} -.pointer-done-hi { - border-color: #00F; /*IE*/ - border-color: rgba(0, 0, 255, 1); -} -.pointer-wontfix { - border-color: #000; /*IE*/ - border-color: rgba(128, 128, 128, 0.2); -} -.pointer-wontfix-hi { - border-color: #000; /*IE*/ - border-color: rgba(128, 128, 128, 1); -} -.pointer-ready { - border-color: #0F0; /*IE*/ - border-color: rgba(0, 255, 0, 0.2); -} -.pointer-ready-hi { - border-color: #0F0; /*IE*/ - border-color: rgba(0, 255, 0, 1); + border-width: 3px; + --alpha: 1; } -.box:hover, -.box-done:hover, -.box-ready:hover, -.box-wontfix:hover{ + +.box:hover{ border-width:3px; margin: 0px; } -.box, -.box-done, -.box-ready, -.box-wontfix { +.box { margin: 1px; background-color: white; width:300px; @@ -86,18 +60,7 @@ img{background:white;} padding: 3px; border: 2px solid black; border-radius: 10px; -} -.box { - border-color: red; -} -.box-done { - border-color: blue; -} -.box-ready { - border-color: rgba(0,255,0,1); -} -.box-wontfix { - border-color: grey; + border-color: rgb(var(--rgb)); } form { display:inline; diff --git a/korektury/static/korektury/opraf.js b/korektury/static/korektury/opraf.js index 5cfe02e2..5d042ec1 100644 --- a/korektury/static/korektury/opraf.js +++ b/korektury/static/korektury/opraf.js @@ -212,45 +212,22 @@ function show_form(img_id, dx, dy, id, text, action) { textarea.focus(); return true; - } -function box_onmouseover(box, stat) +function box_onmouseover(box) { var id = box.id; var pointer = document.getElementById(box.id + '-pointer'); - switch (stat){ - case 'done': - pointer.className = 'pointer-done-hi'; - break; - case 'wontfix': - pointer.className = 'pointer-wontfix-hi'; - break; - case 'ready': - pointer.className = 'pointer-ready-hi'; - break; - default: - pointer.className = 'pointer-hi'; - } + pointer.classList.remove('pointer'); + pointer.classList.add('pointer-hi'); } -function box_onmouseout(box, stat) +function box_onmouseout(box) { var id = box.id; var pointer = document.getElementById(box.id + '-pointer'); - switch (stat){ - case 'done': - pointer.className = 'pointer-done'; - break; - case 'wontfix': - pointer.className = 'pointer-wontfix'; - break; - case 'ready': - pointer.className = 'pointer-ready'; - break; - default: - pointer.className = 'pointer'; - } + pointer.classList.remove('pointer-hi'); + pointer.classList.add('pointer'); } function save_scroll(form) diff --git a/korektury/templates/korektury/opraf.html b/korektury/templates/korektury/opraf.html index fccfc53b..6a7d97c3 100644 --- a/korektury/templates/korektury/opraf.html +++ b/korektury/templates/korektury/opraf.html @@ -20,6 +20,17 @@           | hlavní stránka | wiki | +
+ Zobrazit: + +