Merge branch 'data_migrations' of gimli.ms.mff.cuni.cz:/akce/mam/git/mamweb into data_migrations
This commit is contained in:
commit
0b40d04fad
3 changed files with 221 additions and 3 deletions
|
@ -121,3 +121,92 @@ class PrihlaskaForm(forms.Form):
|
|||
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'))
|
||||
|
||||
|
||||
class EditForm(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(label='Telefon',max_length=256, required=False)
|
||||
datum_narozeni = forms.DateField(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 a řešení',choices = Resitel.ZASILAT_CHOICES, 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')
|
||||
#
|
||||
# except ObjectDoesNotExist:
|
||||
# pass
|
||||
# return username
|
||||
#
|
||||
# def clean_email(self):
|
||||
# err_logger = logging.getLogger('seminar.prihlaska.problem')
|
||||
# email = self.cleaned_data.get('email')
|
||||
# try:
|
||||
# Osoba.objects.get(email=email)
|
||||
# msg = "Email {} exists".format(email)
|
||||
# err_logger.info(msg)
|
||||
# raise forms.ValidationError('Email je již použit')
|
||||
#
|
||||
# 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'))
|
||||
|
|
78
seminar/templates/seminar/edit.html
Normal file
78
seminar/templates/seminar/edit.html
Normal file
|
@ -0,0 +1,78 @@
|
|||
{% extends "seminar/zadani/base.html" %}
|
||||
{% load staticfiles %}
|
||||
|
||||
{% block script %}
|
||||
<!--script type="text/javascript" src="{% static 'admin/js/vendor/jquery/jquery.js' %}"></script!-->
|
||||
{{form.media}}
|
||||
<script src="{% static 'seminar/prihlaska.js' %}"></script>
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
<h1>
|
||||
{% block nadpis1a %}{% block nadpis1b %}
|
||||
Změna osobních údajů
|
||||
{% endblock %}{% endblock %}
|
||||
</h1>
|
||||
<form action="{% url 'seminar_resitel_edit' %}" method="post">
|
||||
{% csrf_token %}
|
||||
{{form.non_field_errors}}
|
||||
<ul class="form">
|
||||
<li>
|
||||
Přihlašovací údaje
|
||||
</li><li>
|
||||
{% include "seminar/prihlaska_field.html" with field=form.username %}
|
||||
</li><li>
|
||||
Osobní údaje
|
||||
</li><li>
|
||||
{% include "seminar/prihlaska_field.html" with field=form.jmeno %}
|
||||
</li><li>
|
||||
{% include "seminar/prihlaska_field.html" with field=form.prijmeni %}
|
||||
</li><li>
|
||||
{% include "seminar/prihlaska_field.html" with field=form.pohlavi_muz%}
|
||||
</li><li>
|
||||
{% include "seminar/prihlaska_field.html" with field=form.email %}
|
||||
</li><li>
|
||||
{% include "seminar/prihlaska_field.html" with field=form.telefon %}
|
||||
</li><li>
|
||||
{% include "seminar/prihlaska_field.html" with field=form.datum_narozeni %}
|
||||
</li><li>
|
||||
<hr>
|
||||
Bydliště
|
||||
</li><li>
|
||||
{% include "seminar/prihlaska_field.html" with field=form.ulice %}
|
||||
</li><li>
|
||||
{% include "seminar/prihlaska_field.html" with field=form.mesto %}
|
||||
</li><li>
|
||||
{% include "seminar/prihlaska_field.html" with field=form.psc %}
|
||||
</li><li>
|
||||
{% include "seminar/prihlaska_field.html" with field=form.stat %}
|
||||
</li>
|
||||
<li id="id_li_stat_text">
|
||||
{% include "seminar/prihlaska_field.html" with field=form.stat_text %}
|
||||
</li><li>
|
||||
<hr>
|
||||
{% include "seminar/prihlaska_field.html" with field=form.skola %}
|
||||
</li><li>
|
||||
<button id="id_skola_text_button" type="button">Škola není v seznamu</button>
|
||||
</li>
|
||||
<li id="id_li_skola_nazev">
|
||||
Vyplň prosím celý název a adresu školy.<br>
|
||||
{% include "seminar/prihlaska_field.html" with field=form.skola_nazev %}
|
||||
</li>
|
||||
<li id="id_li_skola_adresa">
|
||||
{% include "seminar/prihlaska_field.html" with field=form.skola_adresa %}
|
||||
</li><li>
|
||||
{% include "seminar/prihlaska_field.html" with field=form.rok_maturity %}
|
||||
</li><li>
|
||||
{% include "seminar/prihlaska_field.html" with field=form.zasilat %}
|
||||
</li><li>
|
||||
{% include "seminar/prihlaska_field.html" with field=form.spam %}
|
||||
</li>
|
||||
</ul>
|
||||
<input type="submit" value="Změnit">
|
||||
</form>
|
||||
<script>
|
||||
$("#id_stat").on("change",addrCountryChanged);
|
||||
$("#id_skola_text_button").on("click",schoolNotInList);
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
@ -20,7 +20,7 @@ from .models import Problem, Cislo, Reseni, Nastaveni, Rocnik, Soustredeni, Orga
|
|||
#from .models import VysledkyZaCislo, VysledkyKCisluZaRocnik, VysledkyKCisluOdjakziva
|
||||
from . import utils
|
||||
from .unicodecsv import UnicodeWriter
|
||||
from .forms import PrihlaskaForm, LoginForm
|
||||
from .forms import PrihlaskaForm, LoginForm, EditForm
|
||||
|
||||
from datetime import timedelta, date, datetime
|
||||
from django.utils import timezone
|
||||
|
@ -1071,8 +1071,6 @@ class ResitelView(LoginRequiredMixin,generic.DetailView):
|
|||
return Resitel.objects.get(osoba__user=self.request.user)
|
||||
|
||||
## Formulare
|
||||
def resitelEditView(request):
|
||||
pass
|
||||
def resetPasswordView(request):
|
||||
pass
|
||||
|
||||
|
@ -1109,6 +1107,59 @@ def prihlaska_log_gdpr_safe(logger, gdpr_logger, msg, form_data):
|
|||
logger.warn(msg)
|
||||
gdpr_logger.warn(msg+", form:{}".format(form_data))
|
||||
|
||||
from django.forms.models import model_to_dict
|
||||
def resitelEditView(request):
|
||||
err_logger = logging.getLogger('seminar.prihlaska.problem')
|
||||
## Načtení objektu Osoba a Resitel, patrici k aktuálně přihlášenému uživately
|
||||
u = request.user
|
||||
osoba_edit = Osoba.objects.get(user=u)
|
||||
resitel_edit = osoba_edit.resitel
|
||||
user_edit = osoba_edit.user
|
||||
## Vytvoření slovníku, kterým předvyplním formulář
|
||||
prefill_1=model_to_dict(user_edit)
|
||||
prefill_2=model_to_dict(resitel_edit)
|
||||
prefill_3=model_to_dict(osoba_edit)
|
||||
prefill_1.update(prefill_2)
|
||||
prefill_1.update(prefill_3)
|
||||
form = EditForm(initial=prefill_1)
|
||||
## Změna údajů a jejich uložení
|
||||
if request.method == 'POST':
|
||||
form = EditForm(request.POST)
|
||||
if form.is_valid():
|
||||
## Změny v osobě
|
||||
fcd = form.cleaned_data
|
||||
osoba_edit.jmeno = fcd['jmeno']
|
||||
osoba_edit.prijmeni = fcd['prijmeni']
|
||||
osoba_edit.pohlavi_muz = fcd['pohlavi_muz']
|
||||
osoba_edit.email = fcd['email']
|
||||
osoba_edit.telefon = fcd['telefon']
|
||||
osoba_edit.ulice = fcd['ulice']
|
||||
osoba_edit.mesto = fcd['mesto']
|
||||
osoba_edit.psc = fcd['psc']
|
||||
## Změny v osobě s podmínkami
|
||||
if fcd.get('spam',False):
|
||||
osoba_edit.datum_souhlasu_zasilani = date.today()
|
||||
if fcd.get('stat','') in ('CZ','SK'):
|
||||
osoba_edit.stat = fcd['stat']
|
||||
else:
|
||||
## Neznámá země
|
||||
msg = "Unknown country {}".format(fcd['stat_text'])
|
||||
|
||||
## Změny v řešiteli
|
||||
resitel_edit.skola = fcd['skola']
|
||||
resitel_edit.rok_maturity = fcd['rok_maturity']
|
||||
resitel_edit.zasilat = fcd['zasilat']
|
||||
if fcd.get('skola'):
|
||||
resitel_edit.skola = fcd['skola']
|
||||
else:
|
||||
# Unknown school - log it
|
||||
msg = "Unknown school {}, {}".format(fcd['skola_nazev'],fcd['skola_adresa'])
|
||||
resitel_edit.save()
|
||||
osoba_edit.save()
|
||||
return HttpResponseRedirect('/thanks/')
|
||||
else:
|
||||
## Stránka před odeslaním formuláře = předvyplněný formulář
|
||||
return render(request, 'seminar/edit.html', {'form': form})
|
||||
|
||||
def prihlaskaView(request):
|
||||
generic_logger = logging.getLogger('seminar.prihlaska')
|
||||
|
|
Loading…
Reference in a new issue