From c8023244bd539ef77092e6d5c408419b62ad2773 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=C3=A1=C5=A1=20Havelka?= Date: Mon, 13 Mar 2023 23:35:04 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Reforma=20p=C5=99ihl=C3=A1=C5=A1ky=20a=20ed?= =?UTF-8?q?itace=20osobn=C3=ADch=20dat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- personalni/forms.py | 216 ++++++------------ .../templates/personalni/udaje/edit.html | 100 +------- .../templates/personalni/udaje/prihlaska.html | 135 ++--------- .../templates/personalni/udaje/udaje.html | 75 ++++++ 4 files changed, 166 insertions(+), 360 deletions(-) create mode 100644 personalni/templates/personalni/udaje/udaje.html diff --git a/personalni/forms.py b/personalni/forms.py index 2494d08a..3199a8a2 100644 --- a/personalni/forms.py +++ b/personalni/forms.py @@ -25,106 +25,85 @@ class TelInput(forms.TextInput): input_pattern="^[+]?[()/0-9. -]{9,}$" -class PrihlaskaForm(PasswordResetForm): - username = forms.CharField(label='Přihlašovací jméno', - max_length=256, - required=True, - help_text='Tímto jménem se následně budeš přihlašovat pro odevzdání řešení a další činnosti v semináři') +class UdajeForm(forms.Form): + username = None + err_logger = logging.getLogger('seminar.prihlaska.problem') jmeno = forms.CharField(label='Jméno', max_length=256, required=True) prezdivka_resitele = forms.CharField(label='Přezdívka (veřejná)', max_length=256, required=False) 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) + 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 a číslo popisné', 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 = 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) - skola = forms.ModelChoiceField(label="Škola", + skola = forms.ModelChoiceField( + label="Škola", queryset=Skola.objects.all(), widget=autocomplete.ModelSelect2( url='autocomplete_skola', - attrs = {'data-placeholder--id': '-1', - 'data-placeholder--text' : '---', - 'data-allow-clear': 'true'}) - ,required=False) - + attrs={ + 'data-placeholder--id': '-1', + 'data-placeholder--text': '---', + 'data-allow-clear': 'true' + } + ), + required=False, + ) + skola_nazev = forms.CharField(label='Název školy', max_length=256, required=False) skola_adresa = forms.CharField(label='Adresa školy', max_length=256, required=False) -# trida = forms.CharField(label='Třída',max_length=10, required=True) - rok_maturity = forms.IntegerField( - label='Rok maturity', - min_value=date.today().year, + label='Rok maturity', + min_value=date.today().year, max_value=date.today().year+8, - required=True) - zasilat = forms.ChoiceField(label='Kam zasílat čísla (zasílání není zpoplatněno)',choices = Resitel.ZASILAT_CHOICES, required=True, initial=Resitel.ZASILAT_NIKAM) - zasilat_cislo_emailem = forms.BooleanField(label='Chci dostávat e-mailem upozornění na vydání nového čísla', required=False, initial=True) - - jak_se_dozvedeli = forms.CharField(widget=forms.Textarea({"rows": 3, "cols": 20}), label='Jak ses o M&M dozvěděl(a)? (Nechceš-li odpovídat, napiš „nechci uvést“.)', required=True) + required=True, + ) - gdpr = forms.BooleanField(label='Souhlasím se zpracováním osobních údajů', required=True) - spam = forms.BooleanField(label='Souhlasím se zasíláním materiálů od MFF UK', required=False) - - def clean_username(self): - err_logger = logging.getLogger('seminar.prihlaska.problem') - username = self.cleaned_data.get('username') - try: - User.objects.get(username=username) - msg = "Username {} exists".format(username) - err_logger.info(msg) - raise forms.ValidationError('Přihlašovací jméno je již použito') + zasilat = forms.ChoiceField(label='Kam zasílat (odměny, pozvánky, případně čísla nebo propagační materiály)', choices=[it for it in Resitel.ZASILAT_CHOICES if it[0] != Resitel.ZASILAT_NIKAM], required=True, initial=Resitel.ZASILAT_DOMU) + zasilat_cislo_papirove = forms.BooleanField(label='Chci dostávat čísla poštou (zasílání není zpoplatněno)', required=False, initial=False) + zasilat_cislo_emailem = forms.BooleanField(label='Chci dostávat e-mailem upozornění na vydání nového čísla', required=False, initial=True) + spam = forms.BooleanField(label='Souhlasím se zasíláním propagačních materiálů od MFF UK', required=False) - except ObjectDoesNotExist: - pass - return username + def clean_prezdivka_resitele(self): + prezdivka_resitele = self.cleaned_data.get('prezdivka_resitele') + if prezdivka_resitele == '': + return prezdivka_resitele + if Resitel.objects.filter(prezdivka_resitele=prezdivka_resitele).exclude(osoba__user__username=self.username).count() > 0: + raise forms.ValidationError('Přezdívka je již použita') + return prezdivka_resitele def clean_email(self): - err_logger = logging.getLogger('seminar.prihlaska.problem') email = self.cleaned_data.get('email') try: - osoba = Osoba.objects.get(email=email) + osoba = Osoba.objects.exclude(user__username=self.username).get(email=email) msg = "Email {} exists".format(email) if osoba.user is not None: - err_logger.info(msg) + self.err_logger.info(msg) raise forms.ValidationError('E-mail je již použit') else: msg += ', but currently has no User, so allowing registration.' - err_logger.info(msg) + self.err_logger.info(msg) except ObjectDoesNotExist: pass return email - def clean_prezdivka_resitele(self): - prezdivka_resitele = self.cleaned_data.get('prezdivka_resitele') - if prezdivka_resitele == '': - return prezdivka_resitele - if Resitel.objects.filter(prezdivka_resitele=prezdivka_resitele).count() > 0: - raise forms.ValidationError('Přezdívka je již použita') - return prezdivka_resitele - def clean_zasilat(self): zasilat = self.cleaned_data.get('zasilat') ulice = self.cleaned_data.get('ulice') if zasilat == Resitel.ZASILAT_DOMU and ulice == "": - raise forms.ValidationError('Nevyplněná adresa bydliště, nelze zasílat čísla domů.') + raise forms.ValidationError('Nevyplněná adresa bydliště, nelze zasílat domů.') return zasilat def clean(self): super().clean() - - err_logger = logging.getLogger('seminar.prihlaska.problem') data = self.cleaned_data if data.get('stat') != 'other' and data.get('stat_text') != '': @@ -140,106 +119,41 @@ class PrihlaskaForm(PasswordResetForm): self.add_error('skola_adresa',forms.ValidationError('Je nutné vyplnit adresu školy')) -class ProfileEditForm(forms.Form): - username = forms.CharField(label='Přihlašovací jméno', - max_length=256, - required=False, - disabled=True) - - jmeno = forms.CharField(label='Jméno', max_length=256, required=True) - prezdivka_resitele = forms.CharField(label='Přezdívka (veřejná)', max_length=256, required=False) - 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) - - skola = forms.ModelChoiceField(label="Škola", - queryset=Skola.objects.all(), - widget=autocomplete.ModelSelect2( - url='autocomplete_skola', - attrs = {'data-placeholder--id': '-1', - 'data-placeholder--text' : '---', - 'data-allow-clear': 'true'}) - ,required=False) - - skola_nazev = forms.CharField(label='Název školy', max_length=256, required=False) - skola_adresa = forms.CharField(label='Adresa školy', max_length=256, required=False) -# trida = forms.CharField(label='Třída',max_length=10, required=True) - rok_maturity = forms.IntegerField( - label='Rok maturity', - min_value=date.today().year, - max_value=date.today().year+8, - required=True) - zasilat = forms.ChoiceField(label='Kam zasílat čísla',choices = Resitel.ZASILAT_CHOICES, required=True) - zasilat_cislo_emailem = forms.BooleanField(label='Chci dostávat email s upozorněním na vydání nového čísla', required=False) - - spam = forms.BooleanField(label='Souhlasím se zasíláním materiálů od MFF UK', required=False) -# def clean_username(self): -# err_logger = logging.getLogger('seminar.prihlaska.problem') -# username = self.cleaned_data.get('username') -# try: -# User.objects.get(username=username) -# msg = "Username {} exists".format(username) -# err_logger.info(msg) -# raise forms.ValidationError('Přihlašovací jméno je již použito') -# -# except ObjectDoesNotExist: -# pass -# return username -# +class PrihlaskaForm(PasswordResetForm, UdajeForm): + username = forms.CharField( + label='Přihlašovací jméno', + max_length=256, + required=True, + help_text='Tímto jménem se následně budeš přihlašovat pro odevzdání řešení a další činnosti v semináři', + ) - def clean_prezdivka_resitele(self): - prezdivka_resitele = self.cleaned_data.get('prezdivka_resitele') - if prezdivka_resitele == '': - return prezdivka_resitele - if Resitel.objects.filter(prezdivka_resitele=prezdivka_resitele).exclude(osoba__user__username=self.username).count() > 0: - raise forms.ValidationError('Přezdívka je již použita') - return prezdivka_resitele + jak_se_dozvedeli = forms.CharField(widget=forms.Textarea({"rows": 3, "cols": 20}), label='Jak ses o M&M dozvěděl(a)? (Nechceš-li odpovídat, napiš „nechci uvést“.)', required=True) - def clean_email(self): - err_logger = logging.getLogger('seminar.prihlaska.problem') - email = self.cleaned_data.get('email') + gdpr = forms.BooleanField(label='Souhlasím se zpracováním osobních údajů', required=True) + + def clean_username(self): + username = self.cleaned_data.get('username') try: - Osoba.objects.exclude(user__username=self.username).get(email=email) - msg = "Email {} exists (in edit)".format(email) - err_logger.info(msg) - raise forms.ValidationError('Email je již použit') + User.objects.get(username=username) + msg = "Username {} exists".format(username) + self.err_logger.info(msg) + raise forms.ValidationError('Přihlašovací jméno je již použito') except ObjectDoesNotExist: pass - return email - #def clean(self): - # super().clean() - # - # err_logger = logging.getLogger('seminar.prihlaska.problem') - - # data = self.cleaned_data - # if data.get('password') != data.get('password_check'): - # self.add_error('password_check',forms.ValidationError('Hesla se neshodují')) - # if data.get('stat') != '' and data.get('stat_text') != '': - # self.add_error('stat',forms.ValidationError('Nelze mít vybraný stát z menu a zároven zapsaný textem')) - # if data.get('skola') and (data.get('skola_nazev') or data.get('skola_adresa')): - # self.add_error('skola',forms.ValidationError('Pokud je škola v seznamu, nevypisujte ji ručně, pokud není, zrušte výběr ze seznamu (křížek vpravo)')) - # if not data.get('skola'): - # if data.get('skola_nazev')=='' and data.get('skola_adresa')=='': - # self.add_error('skola',forms.ValidationError('Je nutné vyplnit školu')) - # elif data.get('skola_nazev')=='': - # self.add_error('skola_nazev',forms.ValidationError('Je nutné vyplnit název školy')) - # elif data.get('skola_adresa')=='': - # self.add_error('skola_adresa',forms.ValidationError('Je nutné vyplnit adresu školy')) + return username + + +class ProfileEditForm(UdajeForm): + err_logger = logging.getLogger('seminar.edit.problem') + username = forms.CharField( + label='Přihlašovací jméno', + max_length=256, + required=False, + disabled=True, + ) class PoMaturiteProfileEditForm(ProfileEditForm): diff --git a/personalni/templates/personalni/udaje/edit.html b/personalni/templates/personalni/udaje/edit.html index 9091925d..085e4246 100644 --- a/personalni/templates/personalni/udaje/edit.html +++ b/personalni/templates/personalni/udaje/edit.html @@ -1,109 +1,19 @@ {% extends "base.html" %} {% load static %} -{% block script %} - -{% endblock %} - - - {% block content %}

{% block nadpis1a %} Změna osobních údajů {% endblock %}

-
- {% csrf_token %} - {{form.non_field_errors}}
+

Změnit heslo

-

- Přihlašovací údaje -

- - {% include "personalni/udaje/prihlaska_field.html" with field=form.username %} -
-

- Změnit heslo -

- -
- -

- Osobní údaje -

- - {% include "personalni/udaje/prihlaska_field.html" with field=form.jmeno %} - {% include "personalni/udaje/prihlaska_field.html" with field=form.prezdivka_resitele %} - {% include "personalni/udaje/prihlaska_field.html" with field=form.prijmeni %} - {% include "personalni/udaje/prihlaska_field.html" with field=form.pohlavi_muz%} - {% include "personalni/udaje/prihlaska_field.html" with field=form.email %} - {% include "personalni/udaje/prihlaska_field.html" with field=form.telefon %} - {% include "personalni/udaje/prihlaska_field.html" with field=form.datum_narozeni %} -
- -
- -

- Bydliště -

- - {% include "personalni/udaje/prihlaska_field.html" with field=form.ulice %} - {% include "personalni/udaje/prihlaska_field.html" with field=form.mesto %} - {% include "personalni/udaje/prihlaska_field.html" with field=form.psc %} - {% include "personalni/udaje/prihlaska_field.html" with field=form.stat %} - {% include "personalni/udaje/prihlaska_field.html" with field=form.stat_text id="id_li_stat_text"%} -
- -
- -

- Škola -

- - {% include "personalni/udaje/prihlaska_field.html" with field=form.skola %} - - - {% include "personalni/udaje/prihlaska_field.html" with field=form.skola_nazev id="id_li_skola_nazev" %} - {% include "personalni/udaje/prihlaska_field.html" with field=form.skola_adresa id="id_li_skola_adresa" %} - {% include "personalni/udaje/prihlaska_field.html" with field=form.rok_maturity %} -
Vyplň prosím celý název a adresu školy.
- -
- -

- Pošta -

- - {% include "personalni/udaje/prihlaska_field.html" with field=form.zasilat %} - {% include "personalni/udaje/prihlaska_field.html" with field=form.zasilat_cislo_emailem %} -
- -
- -

- Zasílání propagačních materiálů -

- - {% include "personalni/udaje/prihlaska_field.html" with field=form.spam %} -
- -
- - + + {% include "personalni/udaje/udaje.html"%} +
- + {% endblock %} diff --git a/personalni/templates/personalni/udaje/prihlaska.html b/personalni/templates/personalni/udaje/prihlaska.html index 33adba03..f26936de 100644 --- a/personalni/templates/personalni/udaje/prihlaska.html +++ b/personalni/templates/personalni/udaje/prihlaska.html @@ -5,16 +5,6 @@ {% endblock %} - - {% block content %}

{% block nadpis1a %} @@ -25,109 +15,26 @@

Tučně popsaná pole jsou povinná.

- {% csrf_token %} - {{form.non_field_errors}} - - -
-

- Přihlašovací údaje -

- - {% include "personalni/udaje/prihlaska_field.html" with field=form.username %} -{# {% include "personalni/udaje/prihlaska_field.html" with field=form.password %}#} -{# {% include "personalni/udaje/prihlaska_field.html" with field=form.password_check %}#} -
- -
- -

- Osobní údaje -

- - {% include "personalni/udaje/prihlaska_field.html" with field=form.jmeno %} - {% include "personalni/udaje/prihlaska_field.html" with field=form.prezdivka_resitele %} - {% include "personalni/udaje/prihlaska_field.html" with field=form.prijmeni %} - {% include "personalni/udaje/prihlaska_field.html" with field=form.pohlavi_muz%} - {% include "personalni/udaje/prihlaska_field.html" with field=form.email %} - {% include "personalni/udaje/prihlaska_field.html" with field=form.telefon %} - {% include "personalni/udaje/prihlaska_field.html" with field=form.datum_narozeni %} -
- -
- -

- Bydliště -

- - {% include "personalni/udaje/prihlaska_field.html" with field=form.ulice %} - {% include "personalni/udaje/prihlaska_field.html" with field=form.mesto %} - {% include "personalni/udaje/prihlaska_field.html" with field=form.psc %} - {% include "personalni/udaje/prihlaska_field.html" with field=form.stat %} - {% include "personalni/udaje/prihlaska_field.html" with field=form.stat_text id="id_li_stat_text"%} -
- -
- -

- Škola -

- - {% include "personalni/udaje/prihlaska_field.html" with field=form.skola %} - - - {% include "personalni/udaje/prihlaska_field.html" with field=form.skola_nazev id="id_li_skola_nazev" %} - {% include "personalni/udaje/prihlaska_field.html" with field=form.skola_adresa id="id_li_skola_adresa" %} - {% include "personalni/udaje/prihlaska_field.html" with field=form.rok_maturity %} -
(Prosíme, zkuste ji najít, téměř jistě ji v seznamu máme. Školy se dobře hledají podle příjmení lidí v jejich názvu, podle ulice, případně název ulice mezera město, atd. Nezadávejte slova, která se často zkracují – gymnázium, střední odborná škola, křestní jména…)
Vyplň prosím celý název a adresu školy.
- -
- -

- Pošta -

- - {% include "personalni/udaje/prihlaska_field.html" with field=form.zasilat %} - {% include "personalni/udaje/prihlaska_field.html" with field=form.zasilat_cislo_emailem %} -
-
- -

- GDPR -

- {% include "personalni/udaje/gdpr.html" %} - - {% include "personalni/udaje/prihlaska_field.html" with field=form.gdpr %} -
- -
- -

- Zasílání propagačních materiálů -

- - {% include "personalni/udaje/prihlaska_field.html" with field=form.spam %} -
- - - -
- -

- Ostatní -

- - {% include "personalni/udaje/prihlaska_field.html" with field=form.jak_se_dozvedeli %} -
- - - - + {% include "personalni/udaje/udaje.html" %} +

+ GDPR +

+ {% include "personalni/udaje/gdpr.html" %} + + {% include "personalni/udaje/prihlaska_field.html" with field=form.gdpr %} +
+ +
+ +

+ Ostatní +

+ + {% include "personalni/udaje/prihlaska_field.html" with field=form.jak_se_dozvedeli %} +
+ +
+ +
- - - {% endblock %} diff --git a/personalni/templates/personalni/udaje/udaje.html b/personalni/templates/personalni/udaje/udaje.html new file mode 100644 index 00000000..f39e8b47 --- /dev/null +++ b/personalni/templates/personalni/udaje/udaje.html @@ -0,0 +1,75 @@ +{% load static %} + +{% block script %} + +{% endblock %} + +{% csrf_token %} +{{form.non_field_errors}} + +
+

+ Přihlašovací údaje +

+ + {% include "personalni/udaje/prihlaska_field.html" with field=form.username %} +
+ +
+ +

+ Osobní údaje +

+ + {% include "personalni/udaje/prihlaska_field.html" with field=form.jmeno %} + {% include "personalni/udaje/prihlaska_field.html" with field=form.prezdivka_resitele %} + {% include "personalni/udaje/prihlaska_field.html" with field=form.prijmeni %} + {% include "personalni/udaje/prihlaska_field.html" with field=form.pohlavi_muz%} + {% include "personalni/udaje/prihlaska_field.html" with field=form.email %} + {% include "personalni/udaje/prihlaska_field.html" with field=form.telefon %} + {% include "personalni/udaje/prihlaska_field.html" with field=form.datum_narozeni %} +
+ +
+ +

+ Škola +

+ + {% include "personalni/udaje/prihlaska_field.html" with field=form.skola %} + + + {% include "personalni/udaje/prihlaska_field.html" with field=form.skola_nazev id="id_li_skola_nazev" %} + {% include "personalni/udaje/prihlaska_field.html" with field=form.skola_adresa id="id_li_skola_adresa" %} + {% include "personalni/udaje/prihlaska_field.html" with field=form.rok_maturity %} +
(Prosíme, zkuste ji najít, téměř jistě ji v seznamu máme. Školy se dobře hledají podle příjmení lidí v jejich názvu, podle ulice, případně název ulice mezera město, atd. Nezadávejte slova, která se často zkracují – gymnázium, střední odborná škola, křestní jména…)
Vyplň prosím celý název a adresu školy.
+ +
+ +

+ Pošta +

+ + {% include "personalni/udaje/prihlaska_field.html" with field=form.zasilat_cislo_emailem %} + {% include "personalni/udaje/prihlaska_field.html" with field=form.zasilat_cislo_papirove %} + {% include "personalni/udaje/prihlaska_field.html" with field=form.spam %} + {% include "personalni/udaje/prihlaska_field.html" with field=form.zasilat %} +
+
+

+ Bydliště (povinné při volbě „domů“) +

+ + {% include "personalni/udaje/prihlaska_field.html" with field=form.ulice %} + {% include "personalni/udaje/prihlaska_field.html" with field=form.mesto %} + {% include "personalni/udaje/prihlaska_field.html" with field=form.psc %} + {% include "personalni/udaje/prihlaska_field.html" with field=form.stat %} + {% include "personalni/udaje/prihlaska_field.html" with field=form.stat_text id="id_li_stat_text"%} +
+ +
+ + From c97a84104169de9540bf2483482eb75b04c71dfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=C3=A1=C5=A1=20Havelka?= Date: Mon, 13 Mar 2023 23:45:05 +0100 Subject: [PATCH 2/2] =?UTF-8?q?Reforma=20nastaven=C3=AD=20zas=C3=ADl=C3=A1?= =?UTF-8?q?n=C3=AD=20po=C5=A1tou?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- personalni/views.py | 7 +++- .../0112_resitel_zasilat_cislo_papirove.py | 42 +++++++++++++++++++ seminar/models/personalni.py | 2 + seminar/models/tvorba.py | 4 +- seminar/templates/seminar/archiv/obalky.tex | 2 + seminar/utils.py | 2 +- 6 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 seminar/migrations/0112_resitel_zasilat_cislo_papirove.py diff --git a/personalni/views.py b/personalni/views.py index a52f7f5f..df1cb8f1 100644 --- a/personalni/views.py +++ b/personalni/views.py @@ -165,6 +165,7 @@ def resitelEditView(request): resitel_edit.rok_maturity = fcd['rok_maturity'] resitel_edit.zasilat = fcd['zasilat'] resitel_edit.zasilat_cislo_emailem = fcd['zasilat_cislo_emailem'] + resitel_edit.zasilat_cislo_papirove = fcd['zasilat_cislo_papirove'] if fcd.get('skola'): resitel_edit.skola = fcd['skola'] else: @@ -267,7 +268,8 @@ def prihlaskaView(request): prezdivka_resitele=fcd['prezdivka_resitele'], rok_maturity = fcd['rok_maturity'], zasilat = fcd['zasilat'], - zasilat_cislo_emailem = fcd['zasilat_cislo_emailem'] + zasilat_cislo_emailem = fcd['zasilat_cislo_emailem'], + zasilat_cislo_papirove = fcd['zasilat_cislo_papirove'], ) if fcd.get('skola'): @@ -284,7 +286,7 @@ def prihlaskaView(request): except m.Resitel.DoesNotExist: # Stejný trik: orig_resitel = r - resitel_attrs = ['skola', 'rok_maturity', 'zasilat', 'zasilat_cislo_emailem'] + resitel_attrs = ['skola', 'rok_maturity', 'zasilat', 'zasilat_cislo_emailem', 'zasilat_cislo_papirove'] for attr in resitel_attrs: new = getattr(r, attr) old = getattr(orig_resitel, attr) @@ -345,6 +347,7 @@ def dataResiteluCsvResponse(queryset, columns=None, with_header=True): 'rok_maturity', 'zasilat', 'zasilat_cislo_emailem', + 'zasilat_cislo_papirove', 'osoba__datum_registrace', 'osoba__datum_souhlasu_udaje', 'osoba__datum_souhlasu_zasilani', diff --git a/seminar/migrations/0112_resitel_zasilat_cislo_papirove.py b/seminar/migrations/0112_resitel_zasilat_cislo_papirove.py new file mode 100644 index 00000000..63660ddc --- /dev/null +++ b/seminar/migrations/0112_resitel_zasilat_cislo_papirove.py @@ -0,0 +1,42 @@ +# Generated by Django 2.2.28 on 2023-03-13 22:02 + +from django.db import migrations, models + +ZASILAT_DOMU = 'domu' +ZASILAT_DO_SKOLY = 'do_skoly' +ZASILAT_NIKAM = 'nikam' + + +def default_zasilat_papirove(apps, schema_editor): + Resitel = apps.get_model('seminar', 'Resitel') + + for resitel in Resitel.objects.all(): + resitel.zasilat_cislo_papirove = resitel.zasilat != ZASILAT_NIKAM + if resitel.zasilat == ZASILAT_NIKAM: + resitel.zasilat = ZASILAT_DOMU if resitel.osoba.ulice else ZASILAT_DO_SKOLY + resitel.save() + + +def vrat_nikam(apps, schema_editor): + Resitel = apps.get_model('seminar', 'Resitel') + + for resitel in Resitel.objects.all(): + if not resitel.zasilat_cislo_papirove: + resitel.zasilat = ZASILAT_NIKAM + resitel.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('seminar', '0111_nikam2nezasilat_papirove'), + ] + + operations = [ + migrations.AddField( + model_name='resitel', + name='zasilat_cislo_papirove', + field=models.BooleanField(default=True, help_text='True pokud chce řešitel dostávat číslo papírově', verbose_name='zasílat číslo papírově'), + ), + migrations.RunPython(default_zasilat_papirove, vrat_nikam), + ] diff --git a/seminar/models/personalni.py b/seminar/models/personalni.py index 9ac85e51..205c9f4a 100644 --- a/seminar/models/personalni.py +++ b/seminar/models/personalni.py @@ -236,6 +236,8 @@ class Resitel(SeminarModelBase): zasilat_cislo_emailem = models.BooleanField('zasílat číslo emailem', help_text='True pokud chce řešitel dostávat číslo emailem', default=False) + zasilat_cislo_papirove = models.BooleanField('zasílat číslo papírově', help_text='True pokud chce řešitel dostávat číslo papírově', default=True) + poznamka = models.TextField('neveřejná poznámka', blank=True, help_text='Neveřejná poznámka k řešiteli (plain text)') diff --git a/seminar/models/tvorba.py b/seminar/models/tvorba.py index f2feb569..af21e587 100644 --- a/seminar/models/tvorba.py +++ b/seminar/models/tvorba.py @@ -290,9 +290,9 @@ class Cislo(SeminarModelBase): paticka = "---\nK odběru těchto e-mailů jste se přihlásili na stránkách https://mam.matfyz.cz. Z odběru se lze odhlásit na https://mam.matfyz.cz/resitel/osobni-udaje/" - posli(text_mailu + paticka, resitele_vsichni.filter(zasilat=pm.Resitel.ZASILAT_NIKAM)) + posli(text_mailu + paticka, resitele_vsichni.filter(zasilat=pm.Resitel.zasilat_cislo_papirove)) posli(text_mailu + 'P. S. Brzy budeme též rozesílat papírovou verzi čísla. Připomínáme, že pokud papírovou verzi čísla nevyužijete, můžete v https://mam.mff.cuni.cz/resitel/osobni-udaje/ zaškrtnout, abychom vám ji neposílali. Čísla vždy můžete nalézt v našem archivu a dál vám budou chodit e-mailem. Děkujeme.\n' + paticka, - resitele_vsichni.exclude(zasilat=pm.Resitel.ZASILAT_NIKAM)) + resitele_vsichni.exclude(zasilat=pm.Resitel.zasilat_cislo_papirove)) def save(self, *args, **kwargs): super().save(*args, **kwargs) diff --git a/seminar/templates/seminar/archiv/obalky.tex b/seminar/templates/seminar/archiv/obalky.tex index ba18d318..9ae62121 100644 --- a/seminar/templates/seminar/archiv/obalky.tex +++ b/seminar/templates/seminar/archiv/obalky.tex @@ -100,6 +100,7 @@ {% with o=r.osoba %} {% with s=r.skola %} {% spaceless %} + {% if r.zasilat_cislo_papirove %} {% if r.zasilat == "do_skoly" %} {% if o.stat == "CZ" %} \obalka{{o.jmeno|sloz}}{{o.prijmeni|sloz}}{{s.nazev|sloz}}{{s.ulice|sloz}}{{s.psc|sloz}}{{s.mesto|sloz}}{{''|sloz}} @@ -115,6 +116,7 @@ {% endif %} {% else %} {% endif %} + {% endif %} {% endspaceless %} {% endwith %} {% endwith %} diff --git a/seminar/utils.py b/seminar/utils.py index e7d52529..e10920b8 100644 --- a/seminar/utils.py +++ b/seminar/utils.py @@ -265,7 +265,7 @@ def merge_resitele(cilovy, zdrojovy): # Postup: # Sjednotit / upravit informace cílového řešitele print('Upravuji data modelu') - fieldy_shoda = ['skola', 'rok_maturity', 'zasilat', 'zasilat_cislo_emailem'] + fieldy_shoda = ['skola', 'rok_maturity', 'zasilat', 'zasilat_cislo_emailem', 'zasilat_cislo_papirove'] for f in fieldy_shoda: zf = getattr(zdrojovy, f)