walidacja formularza
This commit is contained in:
parent
531adcee2e
commit
e36992bc3f
BIN
hotel/db.sqlite3
BIN
hotel/db.sqlite3
Binary file not shown.
Binary file not shown.
@ -8,6 +8,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<form action="" method="post">
|
<form action="" method="post">
|
||||||
|
{{ error }}
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ form.as_p }}
|
{{ form.as_p }}
|
||||||
<input type="submit" value="Submit">
|
<input type="submit" value="Submit">
|
||||||
|
@ -3,6 +3,7 @@ from django.template import loader
|
|||||||
from django.shortcuts import get_object_or_404, render
|
from django.shortcuts import get_object_or_404, render
|
||||||
from .models import *
|
from .models import *
|
||||||
from .forms import *
|
from .forms import *
|
||||||
|
import re
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
@ -29,12 +30,24 @@ def reservation(request):
|
|||||||
|
|
||||||
|
|
||||||
def addclient(request):
|
def addclient(request):
|
||||||
if request.method == "GET":
|
error = ""
|
||||||
form = ClientForm()
|
if request.method == "POST":
|
||||||
template = loader.get_template('form.html')
|
|
||||||
return HttpResponse(template.render({'form': form}, request))
|
|
||||||
elif request.method == "POST":
|
|
||||||
client = ClientForm(request.POST)
|
client = ClientForm(request.POST)
|
||||||
client.save()
|
if client.is_valid():
|
||||||
return HttpResponse()
|
if check(client.cleaned_data["id_number"]):
|
||||||
|
client.save()
|
||||||
|
return HttpResponse()
|
||||||
|
error = "Numer dowodu nieprawidłowy"
|
||||||
|
|
||||||
|
form = ClientForm()
|
||||||
|
template = loader.get_template('form.html')
|
||||||
|
return HttpResponse(template.render({'form': form, 'error': error}, request))
|
||||||
|
|
||||||
|
|
||||||
|
def check(numer):
|
||||||
|
pattern = re.compile(r'[A-Z][A-Z][A-Z]\d\d\d\d\d\d')
|
||||||
|
|
||||||
|
return pattern.match(numer)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user