Vytvareni osoby, usera a resitele pri registraci.
This commit is contained in:
parent
2f3386e84f
commit
c57b99c015
2 changed files with 79 additions and 19 deletions
|
@ -4,7 +4,9 @@ from seminar.models import Resitel
|
||||||
class PrihlaskaForm(forms.Form):
|
class PrihlaskaForm(forms.Form):
|
||||||
jmeno = forms.CharField(label='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)
|
prijmeni = forms.CharField(label='Příjmení', max_length=256, required=True)
|
||||||
pohlavi = forms.ChoiceField(label='Pohlaví',
|
username = forms.CharField(label='Přihlašovací jméno', max_length=256, required=True)
|
||||||
|
# TODO heslo?
|
||||||
|
pohlavi_muz = forms.ChoiceField(label='Pohlaví',
|
||||||
choices = ((True,'muž'),(False,'žena')), required=True)
|
choices = ((True,'muž'),(False,'žena')), required=True)
|
||||||
email = forms.EmailField(label='E-mail',max_length=256, required=True)
|
email = forms.EmailField(label='E-mail',max_length=256, required=True)
|
||||||
telefon = forms.CharField(label='Telefon',max_length=256, required=False)
|
telefon = forms.CharField(label='Telefon',max_length=256, required=False)
|
||||||
|
@ -19,23 +21,24 @@ class PrihlaskaForm(forms.Form):
|
||||||
required=False)
|
required=False)
|
||||||
|
|
||||||
|
|
||||||
skola_stat_select = forms.ChoiceField(label='Stát',
|
# skola_stat_select = forms.ChoiceField(label='Stát',
|
||||||
choices = (('cz', 'Česká Republika'),
|
# choices = (('cz', 'Česká Republika'),
|
||||||
('sk', 'Slovenská Republika'),
|
# ('sk', 'Slovenská Republika'),
|
||||||
('other', 'Jiné')),
|
# ('other', 'Jiné')),
|
||||||
required=True)
|
# required=True)
|
||||||
kraj_select = forms.ChoiceField(label='Kraj',required=True)
|
# kraj_select = forms.ChoiceField(label='Kraj',required=True)
|
||||||
skola_select = forms.ChoiceField(label='Škola',required=True)
|
# skola_select = forms.ChoiceField(label='Škola',required=True)
|
||||||
#kraj
|
#kraj
|
||||||
#škola
|
#škola
|
||||||
trida = forms.CharField(label='Třída',max_length=10, required=True)
|
# trida = forms.CharField(label='Třída',max_length=10, required=True)
|
||||||
#název školy
|
#název školy
|
||||||
#adresa školy
|
#adresa školy
|
||||||
skola_nazev = forms.CharField(label='Název školy', max_length=256, 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)
|
# skola_adresa = forms.CharField(label='Adresa školy', max_length=256, required=False)
|
||||||
|
|
||||||
rok_maturity = forms.IntegerField(label='Rok maturity', min_value=2019, required=True)
|
rok_maturity = forms.IntegerField(label='Rok maturity', min_value=2019, 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)
|
||||||
gdpr = forms.BooleanField(label='Souhlasím se zpracováním osobních údajů', 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)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,9 +9,9 @@ from django.utils.translation import ugettext as _
|
||||||
from django.http import Http404,HttpResponseBadRequest,HttpResponseRedirect
|
from django.http import Http404,HttpResponseBadRequest,HttpResponseRedirect
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.views.decorators.csrf import ensure_csrf_cookie
|
from django.views.decorators.csrf import ensure_csrf_cookie
|
||||||
from django.contrib.auth import authenticate, login
|
from django.contrib.auth import authenticate, login, get_user_model
|
||||||
|
|
||||||
from .models import Problem, Cislo, Reseni, Nastaveni, Rocnik, Soustredeni, Organizator, Resitel, Novinky, Soustredeni_Ucastnici, Pohadka, Tema, Clanek
|
from .models import Problem, Cislo, Reseni, Nastaveni, Rocnik, Soustredeni, Organizator, Resitel, Novinky, Soustredeni_Ucastnici, Pohadka, Tema, Clanek, Osoba
|
||||||
#from .models import VysledkyZaCislo, VysledkyKCisluZaRocnik, VysledkyKCisluOdjakziva
|
#from .models import VysledkyZaCislo, VysledkyKCisluZaRocnik, VysledkyKCisluOdjakziva
|
||||||
from . import utils
|
from . import utils
|
||||||
from .unicodecsv import UnicodeWriter
|
from .unicodecsv import UnicodeWriter
|
||||||
|
@ -951,15 +951,72 @@ def texDownloadView(request, rocnik, cislo):
|
||||||
## Formulare
|
## Formulare
|
||||||
|
|
||||||
def prihlaskaView(request):
|
def prihlaskaView(request):
|
||||||
# if this is a POST request we need to process the form data
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
# create a form instance and populate it with data from the request:
|
|
||||||
form = PrihlaskaForm(request.POST)
|
form = PrihlaskaForm(request.POST)
|
||||||
# check whether it's valid:
|
# TODO vyresit, co se bude v jakych situacich zobrazovat
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
# process the data in form.cleaned_data as required
|
print("Form valid")
|
||||||
# ...
|
try:
|
||||||
# redirect to a new URL:
|
# mame jiz email v databazi?
|
||||||
|
o = Osoba.objects.get(email=form.cleaned_data['email'])
|
||||||
|
print("Email existuje: {}".format(form.cleaned_data))
|
||||||
|
# TODO seřvat a nepustit dál
|
||||||
|
return HttpResponseRedirect('/thanks/')
|
||||||
|
except ObjectDoesNotExist:
|
||||||
|
pass
|
||||||
|
|
||||||
|
User = get_user_model()
|
||||||
|
try:
|
||||||
|
u = User.objects.get(username=form.cleaned_data['username'])
|
||||||
|
print("Username existuje: {}".format(form.cleaned_data))
|
||||||
|
# TODO seřvat a nepustit dál
|
||||||
|
return HttpResponseRedirect('/thanks/')
|
||||||
|
|
||||||
|
except ObjectDoesNotExist:
|
||||||
|
pass
|
||||||
|
|
||||||
|
u = User(username=form.cleaned_data['username'])
|
||||||
|
u.save()
|
||||||
|
|
||||||
|
o = Osoba(
|
||||||
|
jmeno = form.cleaned_data['jmeno'],
|
||||||
|
prijmeni = form.cleaned_data['prijmeni'],
|
||||||
|
pohlavi_muz = form.cleaned_data['pohlavi_muz'],
|
||||||
|
email = form.cleaned_data['email'],
|
||||||
|
telefon = form.cleaned_data.get('telefon',''),
|
||||||
|
datum_narozeni = form.cleaned_data.get('datum_narozeni',None),
|
||||||
|
datum_souhlasu_udaje = date.today(),
|
||||||
|
datum_registrace = date.today(),
|
||||||
|
ulice = form.cleaned_data.get('ulice',''),
|
||||||
|
mesto = form.cleaned_data.get('mesto',''),
|
||||||
|
psc = form.cleaned_data.get('psc',''),
|
||||||
|
poznamka = str(form.cleaned_data)
|
||||||
|
)
|
||||||
|
if form.cleaned_data.get('spam',False):
|
||||||
|
o.datum_souhlasu_zasilani = date.today()
|
||||||
|
if form.cleaned_data.get('stat','') in ('CZ','SK'):
|
||||||
|
o.stat = form.cleaned_data['stat']
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
#TODO jak budeme resit jine staty?
|
||||||
|
|
||||||
|
o.save()
|
||||||
|
o.user = u
|
||||||
|
o.save()
|
||||||
|
|
||||||
|
r = Resitel(
|
||||||
|
rok_maturity = form.cleaned_data['rok_maturity'],
|
||||||
|
zasilat = form.cleaned_data['zasilat']
|
||||||
|
)
|
||||||
|
|
||||||
|
r.save()
|
||||||
|
r.osoba = o
|
||||||
|
#TODO doplnit skolu
|
||||||
|
r.save()
|
||||||
|
|
||||||
|
|
||||||
|
# TODO logovat jednotlive validni formulare do souboru
|
||||||
|
print(form.cleaned_data)
|
||||||
return HttpResponseRedirect('/thanks/')
|
return HttpResponseRedirect('/thanks/')
|
||||||
|
|
||||||
# if a GET (or any other method) we'll create a blank form
|
# if a GET (or any other method) we'll create a blank form
|
||||||
|
|
Loading…
Reference in a new issue