EditView, EditFrom, Edit.html uprava
This commit is contained in:
parent
08eb89d790
commit
5f66fd0b03
3 changed files with 33 additions and 25 deletions
|
@ -123,23 +123,10 @@ class PrihlaskaForm(forms.Form):
|
|||
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,
|
||||
help_text='Tímto jménem se následně budeš přihlašovat pro odevzdání řešení a další činnosti v semináři')
|
||||
password = forms.CharField(
|
||||
label='Heslo',
|
||||
max_length=256,
|
||||
required=False,
|
||||
widget=forms.PasswordInput())
|
||||
password_check = forms.CharField(
|
||||
label='Ověření hesla',
|
||||
max_length=256,
|
||||
required=False,
|
||||
widget=forms.PasswordInput())
|
||||
required=True)
|
||||
|
||||
jmeno = forms.CharField(label='Jméno', max_length=256, required=True)
|
||||
prijmeni = forms.CharField(label='Příjmení', max_length=256, required=True)
|
||||
|
@ -178,7 +165,6 @@ class EditForm(forms.Form):
|
|||
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)
|
||||
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')
|
||||
|
|
|
@ -20,10 +20,6 @@
|
|||
Přihlašovací údaje
|
||||
</li><li>
|
||||
{% include "seminar/prihlaska_field.html" with field=form.username %}
|
||||
</li><li>
|
||||
{% include "seminar/prihlaska_field.html" with field=form.password %}
|
||||
</li><li>
|
||||
{% include "seminar/prihlaska_field.html" with field=form.password_check %}
|
||||
</li><li>
|
||||
Osobní údaje
|
||||
</li><li>
|
||||
|
@ -68,9 +64,6 @@
|
|||
{% 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/gdpr.html" %}
|
||||
{% include "seminar/prihlaska_field.html" with field=form.gdpr %}
|
||||
</li><li>
|
||||
{% include "seminar/prihlaska_field.html" with field=form.spam %}
|
||||
</li>
|
||||
|
|
|
@ -1027,15 +1027,16 @@ def prihlaska_log_gdpr_safe(logger, gdpr_logger, msg, 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(osoba_edit)
|
||||
prefill_1=model_to_dict(user_edit)
|
||||
prefill_2=model_to_dict(resitel_edit)
|
||||
prefill_3=model_to_dict(user_edit)
|
||||
prefill_3=model_to_dict(osoba_edit)
|
||||
prefill_1.update(prefill_2)
|
||||
prefill_1.update(prefill_3)
|
||||
form = EditForm(initial=prefill_1)
|
||||
|
@ -1043,7 +1044,35 @@ def resitelEditView(request):
|
|||
if request.method == 'POST':
|
||||
form = EditForm(request.POST)
|
||||
if form.is_valid():
|
||||
osoba_edit.prijmeni = 'NOVOTA'
|
||||
## 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:
|
||||
|
|
Loading…
Reference in a new issue