From 2a292f3a828a62241c377d6d0ab1f77e050c0d5f Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Tue, 30 Mar 2021 22:26:37 +0200 Subject: [PATCH 01/25] =?UTF-8?q?Templatetagy=20na=20hezk=C3=A9=20vykreslo?= =?UTF-8?q?v=C3=A1n=C3=AD=20a=20dohled=C3=A1v=C3=A1n=C3=AD=20deadlin=C5=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Nikdo neví, k čemu jsou dobré, ale už jsou napsané... --- seminar/templatetags/deadliny.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 seminar/templatetags/deadliny.py diff --git a/seminar/templatetags/deadliny.py b/seminar/templatetags/deadliny.py new file mode 100644 index 00000000..29ea5c79 --- /dev/null +++ b/seminar/templatetags/deadliny.py @@ -0,0 +1,24 @@ +from django import template +from seminar.utils import TypDeadline, deadline +register = template.Library() + +@register.filter(name='deadline') +def deadline_text(datum): + typ, cislo, deadline = deadline(datum) + strings = { + TypDeadline.PredDeadline: f"1. deadline čísla {cislo} ({datum})", + TypDeadline.SousDeadline: f"Soustřeďkový deadline čísla {cislo} ({datum})", + TypDeadline.FinalDeadline: f"Finální deadline čísla {cislo} ({datum})", + } + return strings[typ] + +@register.filter(name='deadline_html') +def deadline_html(datum): + typ, _, _ = deadline(datum) + text = deadline_text(datum) + classes = { + TypDeadline.PredDeadline: 'preddeadline', + TypDeadline.SousDeadline: 'sous_deadline', + TypDeadline.FinalDeadline: 'final_deadline', + } + return f'{text}' From b37953bc902f07084886d5da37d5f543735429d4 Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Tue, 30 Mar 2021 22:31:50 +0200 Subject: [PATCH 02/25] =?UTF-8?q?Fix=20=C5=A1patn=C3=A1=20prom=C4=9Bnn?= =?UTF-8?q?=C3=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/templatetags/deadliny.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/seminar/templatetags/deadliny.py b/seminar/templatetags/deadliny.py index 29ea5c79..18bfbf08 100644 --- a/seminar/templatetags/deadliny.py +++ b/seminar/templatetags/deadliny.py @@ -6,9 +6,9 @@ register = template.Library() def deadline_text(datum): typ, cislo, deadline = deadline(datum) strings = { - TypDeadline.PredDeadline: f"1. deadline čísla {cislo} ({datum})", - TypDeadline.SousDeadline: f"Soustřeďkový deadline čísla {cislo} ({datum})", - TypDeadline.FinalDeadline: f"Finální deadline čísla {cislo} ({datum})", + TypDeadline.PredDeadline: f"1. deadline čísla {cislo} ({deadline})", + TypDeadline.SousDeadline: f"Soustřeďkový deadline čísla {cislo} ({deadline})", + TypDeadline.FinalDeadline: f"Finální deadline čísla {cislo} ({deadline})", } return strings[typ] From 70c3ec8b6c9127332ff2ebd7091faec57f81cf0f Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Tue, 30 Mar 2021 23:01:31 +0200 Subject: [PATCH 03/25] =?UTF-8?q?Hodn=C4=9B=20oprav?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Neumím kódit :-) --- seminar/templatetags/deadliny.py | 11 ++++++----- seminar/utils.py | 14 ++++++++------ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/seminar/templatetags/deadliny.py b/seminar/templatetags/deadliny.py index 18bfbf08..b7a0142d 100644 --- a/seminar/templatetags/deadliny.py +++ b/seminar/templatetags/deadliny.py @@ -1,14 +1,15 @@ from django import template +from django.utils.safestring import mark_safe from seminar.utils import TypDeadline, deadline register = template.Library() @register.filter(name='deadline') def deadline_text(datum): - typ, cislo, deadline = deadline(datum) + typ, cislo, dl = deadline(datum) strings = { - TypDeadline.PredDeadline: f"1. deadline čísla {cislo} ({deadline})", - TypDeadline.SousDeadline: f"Soustřeďkový deadline čísla {cislo} ({deadline})", - TypDeadline.FinalDeadline: f"Finální deadline čísla {cislo} ({deadline})", + TypDeadline.PredDeadline: f"1. deadline čísla {cislo} ({dl})", + TypDeadline.SousDeadline: f"Soustřeďkový deadline čísla {cislo} ({dl})", + TypDeadline.FinalDeadline: f"Finální deadline čísla {cislo} ({dl})", } return strings[typ] @@ -21,4 +22,4 @@ def deadline_html(datum): TypDeadline.SousDeadline: 'sous_deadline', TypDeadline.FinalDeadline: 'final_deadline', } - return f'{text}' + return mark_safe(f'{text}') diff --git a/seminar/utils.py b/seminar/utils.py index a41b4111..68bce110 100644 --- a/seminar/utils.py +++ b/seminar/utils.py @@ -309,7 +309,7 @@ def deadline_v_rocniku(datum, rocnik): deadliny.append((TypDeadline.FinalDeadline, c, c.datum_deadline)) deadliny = sorted(deadliny, key=lambda x: x[2]) # podle data for dl in deadliny: - if datum <= dl: + if datum <= dl[2]: # První takový deadline je ten nejtěsnější return dl @@ -319,20 +319,22 @@ def deadline(datum): Vrací trojici (TypDeadline, Cislo, datumDeadline: date). """ + if isinstance(datum, datetime.datetime): + datum = datum.date() rok = datum.year # Dva ročníky podezřelé z obsahování dat - pozdejsi_rocnik = m.Rocnik.filter(prvni_rok=rok) - drivejsi_rocnik = m.Rocnik.filter(druhy_rok=rok) - if any( + pozdejsi_rocnik = m.Rocnik.objects.filter(prvni_rok=rok) + drivejsi_rocnik = m.Rocnik.objects.filter(prvni_rok=rok-1) + if any([ pozdejsi_rocnik.count() > 1, drivejsi_rocnik.count() > 1, - ): + ]): raise ValueError(f"Více ročníků začíná/končí stejným rokem: {rok}") pozdejsi_rocnik = pozdejsi_rocnik.first() if pozdejsi_rocnik.count() > 0 else None drivejsi_rocnik = drivejsi_rocnik.first() if drivejsi_rocnik.count() > 0 else None # Předpokládáme, že neexistuje číslo, které má deadline ale nemá finální deadline. - posledni_deadline_drivejsiho_rocniku = m.Cislo.objects.get(rocnik=drivejsi_rocnik, datum_deadline__isnull=False).datum_deadline + posledni_deadline_drivejsiho_rocniku = m.Cislo.objects.filter(rocnik=drivejsi_rocnik, datum_deadline__isnull=False).last().datum_deadline if datum <= posledni_deadline_drivejsiho_rocniku: return deadline_v_rocniku(datum, drivejsi_rocnik) From 08e31a849ca6926b190e383dce24c210b713725e Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Tue, 30 Mar 2021 23:01:58 +0200 Subject: [PATCH 04/25] =?UTF-8?q?Zobrazen=C3=AD=20deadlinu=20doru=C4=8Den?= =?UTF-8?q?=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/templates/seminar/odevzdavatko/detail.html | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/seminar/templates/seminar/odevzdavatko/detail.html b/seminar/templates/seminar/odevzdavatko/detail.html index dadeff41..14094fb8 100644 --- a/seminar/templates/seminar/odevzdavatko/detail.html +++ b/seminar/templates/seminar/odevzdavatko/detail.html @@ -1,5 +1,6 @@ {% extends "base.html" %} {% load static %} +{% load deadliny %} {% block content %} @@ -62,7 +63,9 @@ $(document).ready(function(){

Řešitelé: {{ object.resitele.all | join:", " }}

{# https://docs.djangoproject.com/en/3.1/ref/models/instances/#django.db.models.Model.get_FOO_display #} -

Forma: {{ object.get_forma_display }}, doručeno {{ object.cas_doruceni }}

+

Forma: {{ object.get_forma_display }}

+ +

Doručeno {{ object.cas_doruceni }}, deadline: {{object.cas_doruceni | deadline_html }}

{# Soubory: #}

Přílohy:

From 41e95fc5742fe0445f3dcdf62ddecaff1f2a93fe Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Wed, 31 Mar 2021 21:30:51 +0200 Subject: [PATCH 05/25] =?UTF-8?q?Zalo=C5=BEena=20aplikace=20'various'=20na?= =?UTF-8?q?=20random=20v=C4=9Bci?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mamweb/settings_common.py | 2 ++ various/__init__.py | 0 various/admin.py | 3 +++ various/apps.py | 5 +++++ various/context_processors.py | 14 ++++++++++++++ various/migrations/__init__.py | 0 various/models.py | 3 +++ various/tests.py | 3 +++ various/views.py | 3 +++ 9 files changed, 33 insertions(+) create mode 100644 various/__init__.py create mode 100644 various/admin.py create mode 100644 various/apps.py create mode 100644 various/context_processors.py create mode 100644 various/migrations/__init__.py create mode 100644 various/models.py create mode 100644 various/tests.py create mode 100644 various/views.py diff --git a/mamweb/settings_common.py b/mamweb/settings_common.py index 75a5493c..925d5961 100644 --- a/mamweb/settings_common.py +++ b/mamweb/settings_common.py @@ -78,6 +78,7 @@ TEMPLATES = [ 'django.contrib.messages.context_processors.messages', 'sekizai.context_processors.sekizai', 'header_fotky.context_processors.vzhled', + 'various.context_processors.april', ) }, }, @@ -132,6 +133,7 @@ INSTALLED_APPS = ( 'korektury', 'prednasky', 'header_fotky', + 'various', # Admin upravy: diff --git a/various/__init__.py b/various/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/various/admin.py b/various/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/various/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/various/apps.py b/various/apps.py new file mode 100644 index 00000000..c24a4428 --- /dev/null +++ b/various/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class VariousConfig(AppConfig): + name = 'various' diff --git a/various/context_processors.py b/various/context_processors.py new file mode 100644 index 00000000..c0be2975 --- /dev/null +++ b/various/context_processors.py @@ -0,0 +1,14 @@ +def april(req): + if 'X-April' in req.headers: + try: + year = int(req.headers['X-April']) + return {'april': year} + except: + pass # Fall-back to regular behaviour + + import datetime + today = datetime.date.today() + if today.day == 1 and today.month == 4: + return {'april': today.year} + return {} + diff --git a/various/migrations/__init__.py b/various/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/various/models.py b/various/models.py new file mode 100644 index 00000000..71a83623 --- /dev/null +++ b/various/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/various/tests.py b/various/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/various/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/various/views.py b/various/views.py new file mode 100644 index 00000000..91ea44a2 --- /dev/null +++ b/various/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. From afff7973fed8f541b10fa9300490af5d30a210db Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Wed, 31 Mar 2021 21:34:08 +0200 Subject: [PATCH 06/25] =?UTF-8?q?Apr=C3=ADl=202021:=20Rotace=20webu=20:-)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mamweb/templates/base.html | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/mamweb/templates/base.html b/mamweb/templates/base.html index b79060b5..3b6b4f25 100644 --- a/mamweb/templates/base.html +++ b/mamweb/templates/base.html @@ -131,6 +131,50 @@ $("a[rel^='gallery-image']").prettyPhoto(prettyparams); }); + {% if april == 2021 %} + + {% endif %} {% render_block "js" %} From f1aa2d63684917b259e058c21bc61d37543416e3 Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Wed, 31 Mar 2021 21:40:33 +0200 Subject: [PATCH 07/25] =?UTF-8?q?Fix=20bugu,=20kdy=20se=20na=20apr=C3=ADla?= =?UTF-8?q?=20objev=C3=AD=20na=20chv=C3=ADli=20str=C3=A1nka=20norm=C3=A1ln?= =?UTF-8?q?=C4=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mamweb/templates/base.html | 6 ++---- various/context_processors.py | 1 + 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/mamweb/templates/base.html b/mamweb/templates/base.html index 3b6b4f25..8f2b7a7d 100644 --- a/mamweb/templates/base.html +++ b/mamweb/templates/base.html @@ -169,10 +169,8 @@ return Math.floor(360*Math.random()); } - $(document).ready(function(){ - $('.container').css('margin', 0); - rotace_a_posun($('.container'), randomUhel()); - }); + $('.container').css('margin', 0); + rotace_a_posun($('.container'), randomUhel()); {% endif %} {% render_block "js" %} diff --git a/various/context_processors.py b/various/context_processors.py index c0be2975..28a34858 100644 --- a/various/context_processors.py +++ b/various/context_processors.py @@ -1,4 +1,5 @@ def april(req): + return {'april': 2021} if 'X-April' in req.headers: try: year = int(req.headers['X-April']) From a68e04abe00cf63f71dc922dc608631aa6560f21 Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Wed, 31 Mar 2021 21:41:14 +0200 Subject: [PATCH 08/25] =?UTF-8?q?Apr=C3=ADl=20nen=C3=AD=20po=C5=99=C3=A1d?= =?UTF-8?q?=20:-D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- various/context_processors.py | 1 - 1 file changed, 1 deletion(-) diff --git a/various/context_processors.py b/various/context_processors.py index 28a34858..c0be2975 100644 --- a/various/context_processors.py +++ b/various/context_processors.py @@ -1,5 +1,4 @@ def april(req): - return {'april': 2021} if 'X-April' in req.headers: try: year = int(req.headers['X-April']) From 0b9110cf6841bb583c263a453879f75a915fea2f Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Tue, 6 Apr 2021 20:30:48 +0200 Subject: [PATCH 09/25] =?UTF-8?q?Odevzd=C3=A1v=C3=A1tko:=20shlukov=C3=A1n?= =?UTF-8?q?=C3=AD=20=C5=99e=C5=A1en=C3=AD=20podle=20deadline?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/templates/seminar/odevzdavatko/seznam.html | 6 +++++- seminar/views/odevzdavatko.py | 10 ++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/seminar/templates/seminar/odevzdavatko/seznam.html b/seminar/templates/seminar/odevzdavatko/seznam.html index b58dcb54..2b3f332a 100644 --- a/seminar/templates/seminar/odevzdavatko/seznam.html +++ b/seminar/templates/seminar/odevzdavatko/seznam.html @@ -1,11 +1,15 @@ {% extends "base.html" %} +{% load deadliny %} {% block content %} +{% for dl, mnozina_reseni in reseni_podle_deadlinu.items %} +

{{ dl.2 | deadline_html }}

    - {% for obj in object_list %} + {% for obj in mnozina_reseni %}
  • {{ obj }} ({{ obj.get_forma_display }} {{ obj.cas_doruceni }}) {% endfor %}
+{% endfor %} {% endblock %} diff --git a/seminar/views/odevzdavatko.py b/seminar/views/odevzdavatko.py index 5c64bc11..4a58be05 100644 --- a/seminar/views/odevzdavatko.py +++ b/seminar/views/odevzdavatko.py @@ -8,12 +8,13 @@ from django.db import transaction from dataclasses import dataclass import datetime +from itertools import groupby import logging import seminar.models as m import seminar.forms as f from seminar.forms import OdevzdavatkoTabulkaFiltrForm as FiltrForm -from seminar.utils import aktivniResitele, resi_v_rocniku +from seminar.utils import aktivniResitele, resi_v_rocniku, deadline logger = logging.getLogger(__name__) @@ -169,7 +170,12 @@ class ReseniProblemuView(MultipleObjectTemplateResponseMixin, MultipleObjectMixi return redirect(reverse("odevzdavatko_detail_reseni", kwargs={"pk": jedine_reseni.id})) context = self.get_context_data() return self.render_to_response(context) - # Kontext automaticky? + + def get_context_data(self, *args, **kwargs): + ctx = super().get_context_data(*args, **kwargs) + # FIXME: Lepší by bylo předat groupby do template. + ctx['reseni_podle_deadlinu'] = {k: list(v) for k,v in groupby(ctx['object_list'], lambda r: deadline(r.cas_doruceni))} + return ctx ## XXX: https://docs.djangoproject.com/en/3.1/topics/class-based-views/mixins/#avoid-anything-more-complex class DetailReseniView(DetailView): From 653a564bfdc34e0774d790d71c6867595932b475 Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Tue, 6 Apr 2021 20:39:18 +0200 Subject: [PATCH 10/25] =?UTF-8?q?Odevzd=C3=A1v=C3=A1tko:=20pl=C3=A1=C4=8D?= =?UTF-8?q?=20v=20koment=C3=A1=C5=99=C3=ADch=20nad=20Django=20templates?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/views/odevzdavatko.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/seminar/views/odevzdavatko.py b/seminar/views/odevzdavatko.py index 4a58be05..3aa7e469 100644 --- a/seminar/views/odevzdavatko.py +++ b/seminar/views/odevzdavatko.py @@ -173,7 +173,9 @@ class ReseniProblemuView(MultipleObjectTemplateResponseMixin, MultipleObjectMixi def get_context_data(self, *args, **kwargs): ctx = super().get_context_data(*args, **kwargs) - # FIXME: Lepší by bylo předat groupby do template. + # XXX: Předat groupby do template nejde: https://stackoverflow.com/questions/6906593/itertools-groupby-in-a-django-template + # Django má {% regroup %}, ale ten potřebuje, aby klíč byl atribut položky: https://docs.djangoproject.com/en/3.2/ref/templates/builtins/#regroup + # Takže rozbalíme groupby do slovníku klíč → seznam sami (dictionary comphrehension) ctx['reseni_podle_deadlinu'] = {k: list(v) for k,v in groupby(ctx['object_list'], lambda r: deadline(r.cas_doruceni))} return ctx From aa8bb6dde485d3a79356fef43a72799bf987a31f Mon Sep 17 00:00:00 2001 From: Jonas Havelka Date: Tue, 6 Apr 2021 22:32:42 +0200 Subject: [PATCH 11/25] =?UTF-8?q?Vyslou=C5=BEil=C3=BDm=20=C3=BA=C4=8Dastn?= =?UTF-8?q?=C3=ADk=C5=AFm=20zkrouhnout=20zm=C4=9Bnu=20=C3=BAdaj=C5=AF.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (Hlavně kvůli orgům, kteří nemohli editovat bez změny roku maturity) --- seminar/forms.py | 24 +++++++++++++++++++++- seminar/templates/seminar/profil/edit.html | 2 ++ seminar/views/views_all.py | 18 ++++++++++------ 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/seminar/forms.py b/seminar/forms.py index 8f6950fa..4db77c18 100644 --- a/seminar/forms.py +++ b/seminar/forms.py @@ -142,6 +142,28 @@ class PrihlaskaForm(forms.Form): elif data.get('skola_adresa')=='': self.add_error('skola_adresa',forms.ValidationError('Je nutné vyplnit adresu školy')) +# Editační formulář bez řešitele. +class ProfileEditFormPoMat(forms.Form): + username = forms.CharField(label='Přihlašovací jméno', + max_length=256, + required=True) + + jmeno = forms.CharField(label='Jméno', max_length=256, required=True) + prijmeni = forms.CharField(label='Příjmení', max_length=256, required=True) + pohlavi_muz = forms.ChoiceField(label='Pohlaví', + choices = ((True,'muž'),(False,'žena')), required=True) + email = forms.EmailField(label='E-mail',max_length=256, required=True) + telefon = forms.CharField(widget=TelInput(),label='Telefon',max_length=256, required=False) + datum_narozeni = forms.DateField(widget=DateInput(),label='Datum narození', required=False) + ulice = forms.CharField(label='Ulice', max_length=256, required=False) + mesto = forms.CharField(label='Město', max_length=256, required=False) + psc = forms.CharField(label='PSČ', max_length=32, required=False) + stat = forms.ChoiceField(label='Stát', + choices = (('CZ', 'Česká Republika'), + ('SK', 'Slovenská Republika'), + ('other', 'Jiné')), + required=False) + stat_text = forms.CharField(label='Stát', max_length=256, required=False) class ProfileEditForm(forms.Form): username = forms.CharField(label='Přihlašovací jméno', @@ -181,7 +203,7 @@ class ProfileEditForm(forms.Form): rok_maturity = forms.IntegerField( label='Rok maturity', - min_value=date.today().year, + min_value=date.today().year, max_value=date.today().year+8, required=True) zasilat = forms.ChoiceField(label='Kam zasílat čísla a řešení',choices = Resitel.ZASILAT_CHOICES, required=True) diff --git a/seminar/templates/seminar/profil/edit.html b/seminar/templates/seminar/profil/edit.html index 9f94090e..89ad6b8c 100644 --- a/seminar/templates/seminar/profil/edit.html +++ b/seminar/templates/seminar/profil/edit.html @@ -61,6 +61,7 @@ {% include "seminar/profil/prihlaska_field.html" with field=form.stat_text id="id_li_stat_text"%} +{% if not PoMat %} {# Vysloužilým účastníkům skrýt editaci školy apod. #}

@@ -95,6 +96,7 @@
+{% endif %} diff --git a/seminar/views/views_all.py b/seminar/views/views_all.py index 49180550..81a15071 100644 --- a/seminar/views/views_all.py +++ b/seminar/views/views_all.py @@ -26,7 +26,7 @@ import seminar.models as m from seminar.models import Problem, Cislo, Reseni, Nastaveni, Rocnik, Soustredeni, Organizator, Resitel, Novinky, Soustredeni_Ucastnici, Pohadka, Tema, Clanek, Osoba, Skola # Tohle je stare a chceme se toho zbavit. Pouzivejte s.ToCoChci #from .models import VysledkyZaCislo, VysledkyKCisluZaRocnik, VysledkyKCisluOdjakziva from seminar import utils, treelib -from seminar.forms import PrihlaskaForm, LoginForm, ProfileEditForm +from seminar.forms import PrihlaskaForm, LoginForm, ProfileEditForm, ProfileEditFormPoMat import seminar.forms as f import seminar.templatetags.treenodes as tnltt import seminar.views.views_rest as vr @@ -1095,15 +1095,21 @@ def resitelEditView(request): user_edit = osoba_edit.user ## Vytvoření slovníku, kterým předvyplním formulář prefill_1=model_to_dict(user_edit) - if resitel_edit: + if resitel_edit and resitel_edit.rok_maturity >= date.today().year: prefill_2=model_to_dict(resitel_edit) prefill_1.update(prefill_2) prefill_3=model_to_dict(osoba_edit) prefill_1.update(prefill_3) - form = ProfileEditForm(initial=prefill_1) + if resitel_edit and resitel_edit.rok_maturity < date.today().year: + form = ProfileEditFormPoMat(initial=prefill_1) + else: + form = ProfileEditForm(initial=prefill_1) ## Změna údajů a jejich uložení if request.method == 'POST': - form = ProfileEditForm(request.POST) + if resitel_edit and resitel_edit.rok_maturity < date.today().year: + form = ProfileEditFormPoMat(request.POST) + else: + form = ProfileEditForm(request.POST) if form.is_valid(): ## Změny v osobě fcd = form.cleaned_data @@ -1124,7 +1130,7 @@ def resitelEditView(request): ## Neznámá země msg = "Unknown country {}".format(fcd['stat_text']) - if resitel_edit: + if resitel_edit and resitel_edit.rok_maturity >= date.today().year: ## Změny v řešiteli resitel_edit.skola = fcd['skola'] resitel_edit.rok_maturity = fcd['rok_maturity'] @@ -1140,7 +1146,7 @@ def resitelEditView(request): return formularOKView(request) else: ## Stránka před odeslaním formuláře = předvyplněný formulář - return render(request, 'seminar/profil/edit.html', {'form': form}) + return render(request, 'seminar/profil/edit.html', {'form': form, 'PoMat': resitel_edit and resitel_edit.rok_maturity < date.today().year}) def prihlaskaView(request): generic_logger = logging.getLogger('seminar.prihlaska') From 795ab3471475307d4d3482c32a6aaf0a19e85d8c Mon Sep 17 00:00:00 2001 From: Jonas Havelka Date: Tue, 6 Apr 2021 23:11:22 +0200 Subject: [PATCH 12/25] Fix convert to gs --- seminar/models.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/seminar/models.py b/seminar/models.py index 63c9bdfa..afa54367 100644 --- a/seminar/models.py +++ b/seminar/models.py @@ -602,13 +602,18 @@ class Cislo(SeminarModelBase): png_filename = pathlib.Path(tempfile.mkdtemp(), 'nahled.png') subprocess.run([ - "convert", - "-density", "300x300", - "-geometry", "{}x{}".format(VYSKA, sirka), - "-background", "white", - "-flatten", - "{}[0]".format(self.pdf.path), # titulní strana - png_filename + "gs", + "-sstdout=%stderr", + "-dSAFER", + "-dNOPAUSE", + "-dBATCH", + "-dNOPROMPT", + "-sDEVICE=pngalpha", + "-r{}x{}".format(VYSKA, sirka), + "-dFirstPage=1d", + "-dLastPage=1d", + "-sOutputFile=" + str(png_filename), + "-f%s" % self.pdf.path ], check=True, capture_output=True From 36c8acbbd6205aba540fbf53bc12f6f7bbab250e Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Tue, 6 Apr 2021 23:33:10 +0200 Subject: [PATCH 13/25] =?UTF-8?q?Odevzd=C3=A1v=C3=A1tko:=20p=C5=99ehled=20?= =?UTF-8?q?=C5=99e=C5=A1en=C3=AD=20pro=20=C5=99e=C5=A1itele=20(o=C5=A1kliv?= =?UTF-8?q?=C3=BD)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/urls.py | 1 + seminar/views/odevzdavatko.py | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/seminar/urls.py b/seminar/urls.py index e5b79e01..5b469170 100644 --- a/seminar/urls.py +++ b/seminar/urls.py @@ -173,4 +173,5 @@ urlpatterns = [ path('temp/reseni/', org_required(viewMethodSwitch(get=views.DetailReseniView.as_view(), post=views.hodnoceniReseniView)), name='odevzdavatko_detail_reseni'), path('temp/reseni/all', org_required(views.SeznamReseniView.as_view())), path('temp/reseni/akt', org_required(views.SeznamAktualnichReseniView.as_view())), + path('temp/reseni/resitel', resitel_required(views.PrehledOdevzdanychReseni.as_view())), ] diff --git a/seminar/views/odevzdavatko.py b/seminar/views/odevzdavatko.py index 3aa7e469..585727a5 100644 --- a/seminar/views/odevzdavatko.py +++ b/seminar/views/odevzdavatko.py @@ -25,6 +25,8 @@ logger = logging.getLogger(__name__) # - ReseniProblemuView # - Detail konkrétního řešení -- všechny soubory, datum, ... # - DetailReseniView +# - Pro řešitele: přehled jejich odevzdaných řešení +# - PrehledOdevzdanychReseni # # Taky se může hodit: # - Tabulka všech řešitelů x všech problémů? @@ -238,6 +240,29 @@ def hodnoceniReseniView(request, pk, *args, **kwargs): return redirect(success_url) +class PrehledOdevzdanychReseni(ListView): + model = m.Hodnoceni + template_name = 'seminar/odevzdavatko/resitel_prehled.html' + + def get_queryset(self): + if not self.request.user.is_authenticated: + raise RuntimeError("Uživatel měl být přihlášený!") + resitel = m.Resitel.objects.get(osoba__user=self.request.user) + qs = super().get_queryset() + qs = qs.filter(reseni__resitele__in=[resitel]) + return qs + + def get_context_data(self, *args, **kwargs): + ctx = super().get_context_data(*args, **kwargs) + # Ročník určujeme podle čísla, do jehož deadlinu došlo řešení. + # Chceme to mít seřazené, takže místo comphrerehsion ručně postavíme pole polí. Django templates neumí použít OrderedDict :-/ + podle_rocniku = [] + for rocnik, hodnoceni in groupby(ctx['object_list'], lambda ho: deadline(ho.reseni.cas_doruceni)[1].rocnik): + podle_rocniku.append((rocnik, list(hodnoceni))) + ctx['podle_rocniku'] = reversed(podle_rocniku) # Od nejnovějšího ročníku + # TODO: Umožnit stažení / zobrazení řešení + return ctx + # Přehled všech řešení kvůli debugování class SeznamReseniView(ListView): From 757d3189e70950081cfd9f1f8540e750f7841a28 Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Tue, 13 Apr 2021 23:06:50 +0200 Subject: [PATCH 14/25] =?UTF-8?q?Template=20pro=20p=C5=99ehled=20poslan?= =?UTF-8?q?=C3=BDch=20=C5=99e=C5=A1en=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../seminar/odevzdavatko/resitel_prehled.html | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 seminar/templates/seminar/odevzdavatko/resitel_prehled.html diff --git a/seminar/templates/seminar/odevzdavatko/resitel_prehled.html b/seminar/templates/seminar/odevzdavatko/resitel_prehled.html new file mode 100644 index 00000000..43a95d95 --- /dev/null +++ b/seminar/templates/seminar/odevzdavatko/resitel_prehled.html @@ -0,0 +1,25 @@ +{% extends "base.html" %} +{% load static %} +{% load deadliny %} + +{% block content %} +{% for rocnik, hodnoceni in podle_rocniku %} +

Ročník {{ rocnik }}

+ + + + + + + + {% for hodn in hodnoceni %} + + + + + + + {% endfor %} +
DoručenoProblémBodyDeadline
{{ hodn.reseni.cas_doruceni }}{{ hodn.problem }}{{ hodn.body|default_if_none:"---" }}{{ hodn.reseni.cas_doruceni | deadline_html }}
+{% endfor %} +{% endblock %} From adef6c662718eb6eab480af9409a0749fd21bb7b Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Wed, 14 Apr 2021 01:11:51 +0200 Subject: [PATCH 15/25] =?UTF-8?q?Styl=20p=C5=99ehledu=20=C5=99e=C5=A1en?= =?UTF-8?q?=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../seminar/odevzdavatko/resitel_prehled.html | 15 ++++++++++++++- seminar/templatetags/deadliny.py | 12 +++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/seminar/templates/seminar/odevzdavatko/resitel_prehled.html b/seminar/templates/seminar/odevzdavatko/resitel_prehled.html index 43a95d95..be2e94bd 100644 --- a/seminar/templates/seminar/odevzdavatko/resitel_prehled.html +++ b/seminar/templates/seminar/odevzdavatko/resitel_prehled.html @@ -2,10 +2,23 @@ {% load static %} {% load deadliny %} +{% block custom_css %} + +{% endblock custom_css %} + {% block content %} {% for rocnik, hodnoceni in podle_rocniku %}

Ročník {{ rocnik }}

- +
diff --git a/seminar/templatetags/deadliny.py b/seminar/templatetags/deadliny.py index b7a0142d..81500d73 100644 --- a/seminar/templatetags/deadliny.py +++ b/seminar/templatetags/deadliny.py @@ -13,10 +13,20 @@ def deadline_text(datum): } return strings[typ] +@register.filter(name='deadline_kratseji') +def deadline_kratsi_text(datum): + typ, cislo, dl = deadline(datum) + strings = { + TypDeadline.PredDeadline: f"1. deadline {cislo}", + TypDeadline.SousDeadline: f"Soustřeďkový deadline {cislo}", + TypDeadline.FinalDeadline: f"Finální deadline {cislo}", + } + return strings[typ] + @register.filter(name='deadline_html') def deadline_html(datum): typ, _, _ = deadline(datum) - text = deadline_text(datum) + text = deadline_kratsi_text(datum) classes = { TypDeadline.PredDeadline: 'preddeadline', TypDeadline.SousDeadline: 'sous_deadline', From fdac1a643dc6c5c4ebdd4df1ae74b0374a679a07 Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Wed, 14 Apr 2021 01:29:29 +0200 Subject: [PATCH 16/25] =?UTF-8?q?Odkazy=20na=20p=C5=99ehled=20odevzdan?= =?UTF-8?q?=C3=BDch=20=C5=99e=C5=A1en=C3=AD=20z=20profilu=20a=20z=20men?= =?UTF-8?q?=C3=AD=C4=8Dka?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit + lepší URL --- data/sitetree.json | 32 +++++++++++++++++-- seminar/templates/seminar/profil/resitel.html | 1 + seminar/urls.py | 2 +- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/data/sitetree.json b/data/sitetree.json index 26c70ca3..2c1b1a65 100644 --- a/data/sitetree.json +++ b/data/sitetree.json @@ -700,8 +700,8 @@ "inmenu": true, "insitetree": true, "parent": 21, - "sort_order": 37, - "title": "Odevzdaná řešení", + "sort_order": 38, + "title": "Došlá řešení", "tree": 1, "url": "odevzdavatko_tabulka", "urlaspattern": true @@ -724,7 +724,7 @@ "inmenu": true, "insitetree": true, "parent": 21, - "sort_order": 38, + "sort_order": 42, "title": "Odhlásit se", "tree": 1, "url": "logout", @@ -806,5 +806,31 @@ }, "model": "sitetree.treeitem", "pk": 41 + }, + { + "fields": { + "access_guest": false, + "access_loggedin": false, + "access_perm_type": 1, + "access_permissions": [ + 2 + ], + "access_restricted": true, + "alias": null, + "description": "", + "hidden": false, + "hint": "", + "inbreadcrumbs": true, + "inmenu": true, + "insitetree": true, + "parent": 21, + "sort_order": 37, + "title": "Odevzdaná řešení", + "tree": 1, + "url": "seminar_resitel_odevzdana_reseni", + "urlaspattern": true + }, + "model": "sitetree.treeitem", + "pk": 42 } ] \ No newline at end of file diff --git a/seminar/templates/seminar/profil/resitel.html b/seminar/templates/seminar/profil/resitel.html index 8f29d246..364bd541 100644 --- a/seminar/templates/seminar/profil/resitel.html +++ b/seminar/templates/seminar/profil/resitel.html @@ -11,6 +11,7 @@ Odhlásit se
Upravit údaje
+Odevzdaná řešení
{% endblock %} diff --git a/seminar/urls.py b/seminar/urls.py index 5b469170..8ee67404 100644 --- a/seminar/urls.py +++ b/seminar/urls.py @@ -135,6 +135,7 @@ urlpatterns = [ path('prihlasit/', views.LoginView.as_view(), name='login'), path('odhlasit/', views.LogoutView.as_view(), name='logout'), path('resitel/', resitel_required(views.ResitelView.as_view()), name='seminar_resitel'), + path('resitel/odevzdana_reseni/', resitel_required(views.PrehledOdevzdanychReseni.as_view()), name='seminar_resitel_odevzdana_reseni'), path('reset-hesla/', views.PasswordResetView.as_view(), name='reset_password'), path('zmena-hesla/', views.PasswordChangeView.as_view(), name='change_password'), path('reset-hesla/2/', views.PasswordResetDoneView.as_view(), name='reset_password_done'), @@ -173,5 +174,4 @@ urlpatterns = [ path('temp/reseni/', org_required(viewMethodSwitch(get=views.DetailReseniView.as_view(), post=views.hodnoceniReseniView)), name='odevzdavatko_detail_reseni'), path('temp/reseni/all', org_required(views.SeznamReseniView.as_view())), path('temp/reseni/akt', org_required(views.SeznamAktualnichReseniView.as_view())), - path('temp/reseni/resitel', resitel_required(views.PrehledOdevzdanychReseni.as_view())), ] From 4b9168c918f74a46716d5f06291c5d6a9585adc2 Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Wed, 14 Apr 2021 01:30:54 +0200 Subject: [PATCH 17/25] =?UTF-8?q?Men=C3=AD=C4=8Dko:=20Hinty=20ohledn=C4=9B?= =?UTF-8?q?=20doru=C4=8Den=C3=BDch=20a=20odeslan=C3=BDch=20=C5=99e=C5=A1en?= =?UTF-8?q?=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Zobrazují se po najetí myší, což je nerušivé ale potenciálně užitečné --- data/sitetree.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/sitetree.json b/data/sitetree.json index 2c1b1a65..b910e5be 100644 --- a/data/sitetree.json +++ b/data/sitetree.json @@ -695,7 +695,7 @@ "alias": null, "description": "", "hidden": false, - "hint": "", + "hint": "To, co ŘEŠITELÉ poslali", "inbreadcrumbs": true, "inmenu": true, "insitetree": true, @@ -819,7 +819,7 @@ "alias": null, "description": "", "hidden": false, - "hint": "", + "hint": "To, co jsem JÁ odevzdal", "inbreadcrumbs": true, "inmenu": true, "insitetree": true, From 82627c2be3e0d14389b2bf7efe1d45a367c03b52 Mon Sep 17 00:00:00 2001 From: Jonas Havelka Date: Wed, 14 Apr 2021 08:02:38 +0200 Subject: [PATCH 18/25] =?UTF-8?q?Fix=20data=20narozen=C3=AD=20v=20osobn?= =?UTF-8?q?=C3=ADch=20=C3=BAdaj=C3=ADch=20(prefill=20a=20ukl=C3=A1d=C3=A1n?= =?UTF-8?q?=C3=AD)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/views/views_all.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/seminar/views/views_all.py b/seminar/views/views_all.py index 81a15071..88d21272 100644 --- a/seminar/views/views_all.py +++ b/seminar/views/views_all.py @@ -1100,6 +1100,8 @@ def resitelEditView(request): prefill_1.update(prefill_2) prefill_3=model_to_dict(osoba_edit) prefill_1.update(prefill_3) + if 'datum_narozeni' in prefill_1: + prefill_1['datum_narozeni'] = str(prefill_1['datum_narozeni']) if resitel_edit and resitel_edit.rok_maturity < date.today().year: form = ProfileEditFormPoMat(initial=prefill_1) else: @@ -1121,6 +1123,7 @@ def resitelEditView(request): osoba_edit.ulice = fcd['ulice'] osoba_edit.mesto = fcd['mesto'] osoba_edit.psc = fcd['psc'] + osoba_edit.datum_narozeni = fcd['datum_narozeni'] ## Změny v osobě s podmínkami if fcd.get('spam',False): osoba_edit.datum_souhlasu_zasilani = date.today() From 19a566d6267e30f6c79d2fcb5bf9c1613653ecd9 Mon Sep 17 00:00:00 2001 From: Jonas Havelka Date: Thu, 15 Apr 2021 09:24:37 +0200 Subject: [PATCH 19/25] PoMat -> PoMaturite --- seminar/forms.py | 2 +- seminar/templates/seminar/profil/edit.html | 2 +- seminar/views/views_all.py | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/seminar/forms.py b/seminar/forms.py index 4db77c18..7aaa78b4 100644 --- a/seminar/forms.py +++ b/seminar/forms.py @@ -143,7 +143,7 @@ class PrihlaskaForm(forms.Form): self.add_error('skola_adresa',forms.ValidationError('Je nutné vyplnit adresu školy')) # Editační formulář bez řešitele. -class ProfileEditFormPoMat(forms.Form): +class ProfileEditFormPoMaturite(forms.Form): username = forms.CharField(label='Přihlašovací jméno', max_length=256, required=True) diff --git a/seminar/templates/seminar/profil/edit.html b/seminar/templates/seminar/profil/edit.html index 89ad6b8c..a5aacd0e 100644 --- a/seminar/templates/seminar/profil/edit.html +++ b/seminar/templates/seminar/profil/edit.html @@ -61,7 +61,7 @@ {% include "seminar/profil/prihlaska_field.html" with field=form.stat_text id="id_li_stat_text"%}
Doručeno Problém
-{% if not PoMat %} {# Vysloužilým účastníkům skrýt editaci školy apod. #} +{% if not po_maturite %} {# Vysloužilým účastníkům skrýt editaci školy apod. #}

diff --git a/seminar/views/views_all.py b/seminar/views/views_all.py index 88d21272..3ba73886 100644 --- a/seminar/views/views_all.py +++ b/seminar/views/views_all.py @@ -26,7 +26,7 @@ import seminar.models as m from seminar.models import Problem, Cislo, Reseni, Nastaveni, Rocnik, Soustredeni, Organizator, Resitel, Novinky, Soustredeni_Ucastnici, Pohadka, Tema, Clanek, Osoba, Skola # Tohle je stare a chceme se toho zbavit. Pouzivejte s.ToCoChci #from .models import VysledkyZaCislo, VysledkyKCisluZaRocnik, VysledkyKCisluOdjakziva from seminar import utils, treelib -from seminar.forms import PrihlaskaForm, LoginForm, ProfileEditForm, ProfileEditFormPoMat +from seminar.forms import PrihlaskaForm, LoginForm, ProfileEditForm, ProfileEditFormPoMaturite import seminar.forms as f import seminar.templatetags.treenodes as tnltt import seminar.views.views_rest as vr @@ -1103,13 +1103,13 @@ def resitelEditView(request): if 'datum_narozeni' in prefill_1: prefill_1['datum_narozeni'] = str(prefill_1['datum_narozeni']) if resitel_edit and resitel_edit.rok_maturity < date.today().year: - form = ProfileEditFormPoMat(initial=prefill_1) + form = ProfileEditFormPoMaturite(initial=prefill_1) else: form = ProfileEditForm(initial=prefill_1) ## Změna údajů a jejich uložení if request.method == 'POST': if resitel_edit and resitel_edit.rok_maturity < date.today().year: - form = ProfileEditFormPoMat(request.POST) + form = ProfileEditFormPoMaturite(request.POST) else: form = ProfileEditForm(request.POST) if form.is_valid(): @@ -1149,7 +1149,7 @@ def resitelEditView(request): return formularOKView(request) else: ## Stránka před odeslaním formuláře = předvyplněný formulář - return render(request, 'seminar/profil/edit.html', {'form': form, 'PoMat': resitel_edit and resitel_edit.rok_maturity < date.today().year}) + return render(request, 'seminar/profil/edit.html', {'form': form, 'po_maturite': resitel_edit and resitel_edit.rok_maturity < date.today().year}) def prihlaskaView(request): generic_logger = logging.getLogger('seminar.prihlaska') From fec62b8c5e036f5b867081d25aa4834b75b4b794 Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Tue, 20 Apr 2021 19:42:27 +0200 Subject: [PATCH 20/25] Migr 0052: debug prints --- .../migrations/0052_user_to_organizator.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/seminar/migrations/0052_user_to_organizator.py b/seminar/migrations/0052_user_to_organizator.py index db3827ce..a4326eb5 100644 --- a/seminar/migrations/0052_user_to_organizator.py +++ b/seminar/migrations/0052_user_to_organizator.py @@ -4,6 +4,10 @@ from __future__ import unicode_literals from django.db import migrations +import logging + +logger = logging.getLogger(__name__) + def spoj_k_organizatorum_osoby(apps, scema_editor): Organizator = apps.get_model('seminar', 'Organizator') Resitel = apps.get_model('seminar', 'Resitel') @@ -12,11 +16,18 @@ def spoj_k_organizatorum_osoby(apps, scema_editor): # 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: + if user is None: + logger.error(f'Org {org} nemá uživatele!') osoba = Osoba(user=user) + else: + logger.info(f'Org {org} má uživatele {user}') + resitele = Resitel.objects.filter(user=user) + if resitele.count() != 0: + osoba = resitele.first().osoba + logger.info(f'Našel jsem řešitele {resitle.first()}, používám jeho Osobu') + else: + logger.warning(f'Org neměl řešitele, zakládám novou Osobu.') + osoba = Osoba(user=user) # Přesun informací z usera do osoby # pro řešitele již v minule migraci From 978b87203ac71d00efa721dc602e1ef420211ca1 Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Tue, 20 Apr 2021 22:03:14 +0200 Subject: [PATCH 21/25] More fix, dunno --- .../migrations/0052_user_to_organizator.py | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/seminar/migrations/0052_user_to_organizator.py b/seminar/migrations/0052_user_to_organizator.py index a4326eb5..6518ca69 100644 --- a/seminar/migrations/0052_user_to_organizator.py +++ b/seminar/migrations/0052_user_to_organizator.py @@ -15,19 +15,38 @@ def spoj_k_organizatorum_osoby(apps, scema_editor): for org in Organizator.objects.all(): # Spárování organizátora s osobou + # Myšlenka: Když najdeme řešitele pro daného uživatele, tak se vezme Osoba příslušná uživateli, + # Pokud nenajdeme uživatele, tak ještě zkusíme dohledat Osobu podle e-mailu user = org.user if user is None: logger.error(f'Org {org} nemá uživatele!') + # Je to podezřelé, ale prostě vyrobíme novou osobu. osoba = Osoba(user=user) else: - logger.info(f'Org {org} má uživatele {user}') - resitele = Resitel.objects.filter(user=user) - if resitele.count() != 0: - osoba = resitele.first().osoba - logger.info(f'Našel jsem řešitele {resitle.first()}, používám jeho Osobu') - else: + logger.info(f'Org {org.user.email}(ID: {org.id}) má uživatele {user}') + # 💢💢💢 Python nemá goto, ale prý má výjimky… 💢💢💢 + class EndException(Exception): pass + try: + # Hledáme podle uživatele + resitele = Resitel.objects.filter(user=user) + if resitele.count() != 0 and user is not None: + osoba = resitele.first().osoba + logger.info(f'Našel jsem řešitele {resitele.first().email} podle uživatele, používám jeho Osobu') + raise EndException + + # Hledáme podle e-mailu + osoby = Osoba.objects.filter(email=user.email) + if osoby.count() != 0 and user.email != '': + osoba = osoby.first() + if osoba.user is None: + osoba.user = user + logger.info(f'Našel jsem Osobu {osoby.first().email} podle e-mailu') + raise EndException + + # Fallback logger.warning(f'Org neměl řešitele, zakládám novou Osobu.') osoba = Osoba(user=user) + except EndException: pass # Přesun informací z usera do osoby # pro řešitele již v minule migraci @@ -57,7 +76,10 @@ def fix_problem(apps, schema_editor): else: pr.autor = None if pr.opravovatel is not None: - pr.opravovatele.add(Organizator.objects.filter(osoba__user=pr.opravovatel).first()) + if Organizator.objects.filter(osoba__user=pr.opravovatel).first() is not None: + pr.opravovatele.add(Organizator.objects.filter(osoba__user=pr.opravovatel).first()) + else: + logger.error(f'WTF, nespárovaný opravovatel {pr.opravovatel} problému {pr}') pr.save() def fix_pohadka(apps, schema_editor): From 3324afcba4162b15f6ac9e395d4fdd8990ecaad9 Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Tue, 20 Apr 2021 22:28:06 +0200 Subject: [PATCH 22/25] =?UTF-8?q?Stejn=C3=BD=20fix=20i=20ve=20squashed=20m?= =?UTF-8?q?igraci?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../0001_squashed_0067_auto_20190814_0805.py | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/seminar/migrations/0001_squashed_0067_auto_20190814_0805.py b/seminar/migrations/0001_squashed_0067_auto_20190814_0805.py index f819f047..5e79c390 100644 --- a/seminar/migrations/0001_squashed_0067_auto_20190814_0805.py +++ b/seminar/migrations/0001_squashed_0067_auto_20190814_0805.py @@ -107,12 +107,38 @@ def spoj_k_organizatorum_osoby(apps, scema_editor): for org in Organizator.objects.all(): # Spárování organizátora s osobou + # Myšlenka: Když najdeme řešitele pro daného uživatele, tak se vezme Osoba příslušná uživateli, + # Pokud nenajdeme uživatele, tak ještě zkusíme dohledat Osobu podle e-mailu user = org.user - resitele = Resitel.objects.filter(user=user) - if resitele.count() != 0: - osoba = resitele.first().osoba - else: + if user is None: + logger.error(f'Org {org} nemá uživatele!') + # Je to podezřelé, ale prostě vyrobíme novou osobu. osoba = Osoba(user=user) + else: + logger.info(f'Org {org.user.email}(ID: {org.id}) má uživatele {user}') + # 💢💢💢 Python nemá goto, ale prý má výjimky… 💢💢💢 + class EndException(Exception): pass + try: + # Hledáme podle uživatele + resitele = Resitel.objects.filter(user=user) + if resitele.count() != 0 and user is not None: + osoba = resitele.first().osoba + logger.info(f'Našel jsem řešitele {resitele.first().email} podle uživatele, používám jeho Osobu') + raise EndException + + # Hledáme podle e-mailu + osoby = Osoba.objects.filter(email=user.email) + if osoby.count() != 0 and user.email != '': + osoba = osoby.first() + if osoba.user is None: + osoba.user = user + logger.info(f'Našel jsem Osobu {osoby.first().email} podle e-mailu') + raise EndException + + # Fallback + logger.warning(f'Org neměl řešitele, zakládám novou Osobu.') + osoba = Osoba(user=user) + except EndException: pass # Přesun informací z usera do osoby # pro řešitele již v minule migraci @@ -142,7 +168,10 @@ def fix_problem(apps, schema_editor): else: pr.autor = None if pr.opravovatel is not None: - pr.opravovatele.add(Organizator.objects.filter(osoba__user=pr.opravovatel).first()) + if Organizator.objects.filter(osoba__user=pr.opravovatel).first() is not None: + pr.opravovatele.add(Organizator.objects.filter(osoba__user=pr.opravovatel).first()) + else: + logger.error(f'WTF, nespárovaný opravovatel {pr.opravovatel} problému {pr}') pr.save() def fix_pohadka(apps, schema_editor): From 1d062680f66aeaa36c00f045fd1fc71c6de4dfde Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Sat, 24 Apr 2021 02:13:29 +0200 Subject: [PATCH 23/25] =?UTF-8?q?Oprava=20migr=200052,=20kter=C3=A1=20rozb?= =?UTF-8?q?=C3=ADjela=20Osoby=20Org=C5=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Snad opravuje #1140 --- .../0001_squashed_0067_auto_20190814_0805.py | 22 ++++++++++--------- .../migrations/0052_user_to_organizator.py | 22 ++++++++++--------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/seminar/migrations/0001_squashed_0067_auto_20190814_0805.py b/seminar/migrations/0001_squashed_0067_auto_20190814_0805.py index 5e79c390..143403b9 100644 --- a/seminar/migrations/0001_squashed_0067_auto_20190814_0805.py +++ b/seminar/migrations/0001_squashed_0067_auto_20190814_0805.py @@ -114,6 +114,7 @@ def spoj_k_organizatorum_osoby(apps, scema_editor): logger.error(f'Org {org} nemá uživatele!') # Je to podezřelé, ale prostě vyrobíme novou osobu. osoba = Osoba(user=user) + # Téhle osobě nejdou nastavit detaily, protože žádné nemáme. else: logger.info(f'Org {org.user.email}(ID: {org.id}) má uživatele {user}') # 💢💢💢 Python nemá goto, ale prý má výjimky… 💢💢💢 @@ -138,17 +139,18 @@ def spoj_k_organizatorum_osoby(apps, scema_editor): # Fallback logger.warning(f'Org neměl řešitele, zakládám novou Osobu.') osoba = Osoba(user=user) - except EndException: pass - # 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 usera do osoby + # pro osoby z řešitelů (jediné dosud existující osoby) 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() + + except EndException: pass # Přesun informací z organizátora do jeho osoby osoba.prezdivka = org.prezdivka if org.prezdivka is not None else '' diff --git a/seminar/migrations/0052_user_to_organizator.py b/seminar/migrations/0052_user_to_organizator.py index 6518ca69..4aef1a1d 100644 --- a/seminar/migrations/0052_user_to_organizator.py +++ b/seminar/migrations/0052_user_to_organizator.py @@ -22,6 +22,7 @@ def spoj_k_organizatorum_osoby(apps, scema_editor): logger.error(f'Org {org} nemá uživatele!') # Je to podezřelé, ale prostě vyrobíme novou osobu. osoba = Osoba(user=user) + # Téhle osobě nejdou nastavit detaily, protože žádné nemáme. else: logger.info(f'Org {org.user.email}(ID: {org.id}) má uživatele {user}') # 💢💢💢 Python nemá goto, ale prý má výjimky… 💢💢💢 @@ -46,17 +47,18 @@ def spoj_k_organizatorum_osoby(apps, scema_editor): # Fallback logger.warning(f'Org neměl řešitele, zakládám novou Osobu.') osoba = Osoba(user=user) - except EndException: pass - # 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 usera do osoby + # pro osoby z řešitelů (jediné dosud existující osoby) 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() + + except EndException: pass # Přesun informací z organizátora do jeho osoby osoba.prezdivka = org.prezdivka if org.prezdivka is not None else '' From f29ff541dc104f3dfee066bcfa63b10f37409dcb Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Sat, 24 Apr 2021 02:20:59 +0200 Subject: [PATCH 24/25] Migr 0052 e-maily nejsou case-sensitive --- seminar/migrations/0001_squashed_0067_auto_20190814_0805.py | 2 +- seminar/migrations/0052_user_to_organizator.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/seminar/migrations/0001_squashed_0067_auto_20190814_0805.py b/seminar/migrations/0001_squashed_0067_auto_20190814_0805.py index 143403b9..eb2d950f 100644 --- a/seminar/migrations/0001_squashed_0067_auto_20190814_0805.py +++ b/seminar/migrations/0001_squashed_0067_auto_20190814_0805.py @@ -128,7 +128,7 @@ def spoj_k_organizatorum_osoby(apps, scema_editor): raise EndException # Hledáme podle e-mailu - osoby = Osoba.objects.filter(email=user.email) + osoby = Osoba.objects.filter(email__iexact=user.email) if osoby.count() != 0 and user.email != '': osoba = osoby.first() if osoba.user is None: diff --git a/seminar/migrations/0052_user_to_organizator.py b/seminar/migrations/0052_user_to_organizator.py index 4aef1a1d..47d151ae 100644 --- a/seminar/migrations/0052_user_to_organizator.py +++ b/seminar/migrations/0052_user_to_organizator.py @@ -36,7 +36,7 @@ def spoj_k_organizatorum_osoby(apps, scema_editor): raise EndException # Hledáme podle e-mailu - osoby = Osoba.objects.filter(email=user.email) + osoby = Osoba.objects.filter(email__iexact=user.email) if osoby.count() != 0 and user.email != '': osoba = osoby.first() if osoba.user is None: From 677d868d8a96f6d8969403ad5012c9aecb9f58c9 Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Tue, 27 Apr 2021 19:34:11 +0200 Subject: [PATCH 25/25] =?UTF-8?q?Migr=20005[12]:=20Nemazat=20u=C5=BEivatel?= =?UTF-8?q?=C5=AFm=20data?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix #1142 --- seminar/migrations/0051_resitel_to_osoba.py | 13 +++++-------- seminar/migrations/0052_user_to_organizator.py | 5 ++--- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/seminar/migrations/0051_resitel_to_osoba.py b/seminar/migrations/0051_resitel_to_osoba.py index 17237bd0..04220896 100644 --- a/seminar/migrations/0051_resitel_to_osoba.py +++ b/seminar/migrations/0051_resitel_to_osoba.py @@ -28,26 +28,23 @@ def resitel_to_osoba(apps,schema_editor): if u.first_name: if not o.jmeno: o.jmeno = u.first_name - u.first_name = 'Použij osobu!' + u.first_name += ' (Uživatel!)' elif o.jmeno == u.first_name: - u.first_name = 'Použij osobu!' + u.first_name += ' (Uživatel!)' 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!' + u.last_name += ' (Uživatel!)' elif o.prijmeni == u.last_name: - u.last_name = 'Použij osobu!' + u.last_name += ' (Uživatel!)' 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: + elif o.email != u.email: raise ValueError('o.email a u.email rozdílné: "{}" vs. "{}"'.format(o.email, u.email)) u.save() diff --git a/seminar/migrations/0052_user_to_organizator.py b/seminar/migrations/0052_user_to_organizator.py index 47d151ae..fec3c2af 100644 --- a/seminar/migrations/0052_user_to_organizator.py +++ b/seminar/migrations/0052_user_to_organizator.py @@ -53,9 +53,8 @@ def spoj_k_organizatorum_osoby(apps, scema_editor): 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.jmeno += " (Uživatel!)" + user.prijmeni += " (Uživatel!)" user.save() except EndException: pass