|
@ -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 |
|
|