Merge branch 'data_migrations' into test
This commit is contained in:
commit
e1ac483c56
6 changed files with 64 additions and 17 deletions
|
@ -142,6 +142,28 @@ class PrihlaskaForm(forms.Form):
|
||||||
elif data.get('skola_adresa')=='':
|
elif data.get('skola_adresa')=='':
|
||||||
self.add_error('skola_adresa',forms.ValidationError('Je nutné vyplnit adresu školy'))
|
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):
|
class ProfileEditForm(forms.Form):
|
||||||
username = forms.CharField(label='Přihlašovací jméno',
|
username = forms.CharField(label='Přihlašovací jméno',
|
||||||
|
@ -181,7 +203,7 @@ class ProfileEditForm(forms.Form):
|
||||||
|
|
||||||
rok_maturity = forms.IntegerField(
|
rok_maturity = forms.IntegerField(
|
||||||
label='Rok maturity',
|
label='Rok maturity',
|
||||||
min_value=date.today().year,
|
min_value=date.today().year,
|
||||||
max_value=date.today().year+8,
|
max_value=date.today().year+8,
|
||||||
required=True)
|
required=True)
|
||||||
zasilat = forms.ChoiceField(label='Kam zasílat čísla a řešení',choices = Resitel.ZASILAT_CHOICES, required=True)
|
zasilat = forms.ChoiceField(label='Kam zasílat čísla a řešení',choices = Resitel.ZASILAT_CHOICES, required=True)
|
||||||
|
|
|
@ -602,13 +602,18 @@ class Cislo(SeminarModelBase):
|
||||||
png_filename = pathlib.Path(tempfile.mkdtemp(), 'nahled.png')
|
png_filename = pathlib.Path(tempfile.mkdtemp(), 'nahled.png')
|
||||||
|
|
||||||
subprocess.run([
|
subprocess.run([
|
||||||
"convert",
|
"gs",
|
||||||
"-density", "300x300",
|
"-sstdout=%stderr",
|
||||||
"-geometry", "{}x{}".format(VYSKA, sirka),
|
"-dSAFER",
|
||||||
"-background", "white",
|
"-dNOPAUSE",
|
||||||
"-flatten",
|
"-dBATCH",
|
||||||
"{}[0]".format(self.pdf.path), # titulní strana
|
"-dNOPROMPT",
|
||||||
png_filename
|
"-sDEVICE=pngalpha",
|
||||||
|
"-r{}x{}".format(VYSKA, sirka),
|
||||||
|
"-dFirstPage=1d",
|
||||||
|
"-dLastPage=1d",
|
||||||
|
"-sOutputFile=" + str(png_filename),
|
||||||
|
"-f%s" % self.pdf.path
|
||||||
],
|
],
|
||||||
check=True,
|
check=True,
|
||||||
capture_output=True
|
capture_output=True
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
{% load deadliny %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
|
{% for dl, mnozina_reseni in reseni_podle_deadlinu.items %}
|
||||||
|
<h1>{{ dl.2 | deadline_html }}</h1>
|
||||||
<ul>
|
<ul>
|
||||||
{% for obj in object_list %}
|
{% for obj in mnozina_reseni %}
|
||||||
<li><a href="{% url 'odevzdavatko_detail_reseni' pk=obj.id %}">{{ obj }}</a> ({{ obj.get_forma_display }} {{ obj.cas_doruceni }})
|
<li><a href="{% url 'odevzdavatko_detail_reseni' pk=obj.id %}">{{ obj }}</a> ({{ obj.get_forma_display }} {{ obj.cas_doruceni }})
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -61,6 +61,7 @@
|
||||||
{% include "seminar/profil/prihlaska_field.html" with field=form.stat_text id="id_li_stat_text"%}
|
{% include "seminar/profil/prihlaska_field.html" with field=form.stat_text id="id_li_stat_text"%}
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
{% if not PoMat %} {# Vysloužilým účastníkům skrýt editaci školy apod. #}
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<h4>
|
<h4>
|
||||||
|
@ -95,6 +96,7 @@
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<input type="submit" value="Změnit">
|
<input type="submit" value="Změnit">
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -8,12 +8,13 @@ from django.db import transaction
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
import datetime
|
import datetime
|
||||||
|
from itertools import groupby
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import seminar.models as m
|
import seminar.models as m
|
||||||
import seminar.forms as f
|
import seminar.forms as f
|
||||||
from seminar.forms import OdevzdavatkoTabulkaFiltrForm as FiltrForm
|
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__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -169,7 +170,14 @@ class ReseniProblemuView(MultipleObjectTemplateResponseMixin, MultipleObjectMixi
|
||||||
return redirect(reverse("odevzdavatko_detail_reseni", kwargs={"pk": jedine_reseni.id}))
|
return redirect(reverse("odevzdavatko_detail_reseni", kwargs={"pk": jedine_reseni.id}))
|
||||||
context = self.get_context_data()
|
context = self.get_context_data()
|
||||||
return self.render_to_response(context)
|
return self.render_to_response(context)
|
||||||
# Kontext automaticky?
|
|
||||||
|
def get_context_data(self, *args, **kwargs):
|
||||||
|
ctx = super().get_context_data(*args, **kwargs)
|
||||||
|
# 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
|
||||||
|
|
||||||
## XXX: https://docs.djangoproject.com/en/3.1/topics/class-based-views/mixins/#avoid-anything-more-complex
|
## XXX: https://docs.djangoproject.com/en/3.1/topics/class-based-views/mixins/#avoid-anything-more-complex
|
||||||
class DetailReseniView(DetailView):
|
class DetailReseniView(DetailView):
|
||||||
|
|
|
@ -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 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 .models import VysledkyZaCislo, VysledkyKCisluZaRocnik, VysledkyKCisluOdjakziva
|
||||||
from seminar import utils, treelib
|
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.forms as f
|
||||||
import seminar.templatetags.treenodes as tnltt
|
import seminar.templatetags.treenodes as tnltt
|
||||||
import seminar.views.views_rest as vr
|
import seminar.views.views_rest as vr
|
||||||
|
@ -1095,15 +1095,21 @@ def resitelEditView(request):
|
||||||
user_edit = osoba_edit.user
|
user_edit = osoba_edit.user
|
||||||
## Vytvoření slovníku, kterým předvyplním formulář
|
## Vytvoření slovníku, kterým předvyplním formulář
|
||||||
prefill_1=model_to_dict(user_edit)
|
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_2=model_to_dict(resitel_edit)
|
||||||
prefill_1.update(prefill_2)
|
prefill_1.update(prefill_2)
|
||||||
prefill_3=model_to_dict(osoba_edit)
|
prefill_3=model_to_dict(osoba_edit)
|
||||||
prefill_1.update(prefill_3)
|
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í
|
## Změna údajů a jejich uložení
|
||||||
if request.method == 'POST':
|
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():
|
if form.is_valid():
|
||||||
## Změny v osobě
|
## Změny v osobě
|
||||||
fcd = form.cleaned_data
|
fcd = form.cleaned_data
|
||||||
|
@ -1124,7 +1130,7 @@ def resitelEditView(request):
|
||||||
## Neznámá země
|
## Neznámá země
|
||||||
msg = "Unknown country {}".format(fcd['stat_text'])
|
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
|
## Změny v řešiteli
|
||||||
resitel_edit.skola = fcd['skola']
|
resitel_edit.skola = fcd['skola']
|
||||||
resitel_edit.rok_maturity = fcd['rok_maturity']
|
resitel_edit.rok_maturity = fcd['rok_maturity']
|
||||||
|
@ -1140,7 +1146,7 @@ def resitelEditView(request):
|
||||||
return formularOKView(request)
|
return formularOKView(request)
|
||||||
else:
|
else:
|
||||||
## Stránka před odeslaním formuláře = předvyplněný formulář
|
## 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):
|
def prihlaskaView(request):
|
||||||
generic_logger = logging.getLogger('seminar.prihlaska')
|
generic_logger = logging.getLogger('seminar.prihlaska')
|
||||||
|
|
Loading…
Reference in a new issue