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>
|
||||
<body>
|
||||
<form action="" method="post">
|
||||
{{ error }}
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<input type="submit" value="Submit">
|
||||
|
@ -3,6 +3,7 @@ from django.template import loader
|
||||
from django.shortcuts import get_object_or_404, render
|
||||
from .models import *
|
||||
from .forms import *
|
||||
import re
|
||||
|
||||
# Create your views here.
|
||||
|
||||
@ -29,12 +30,24 @@ def reservation(request):
|
||||
|
||||
|
||||
def addclient(request):
|
||||
if request.method == "GET":
|
||||
form = ClientForm()
|
||||
template = loader.get_template('form.html')
|
||||
return HttpResponse(template.render({'form': form}, request))
|
||||
elif request.method == "POST":
|
||||
error = ""
|
||||
if request.method == "POST":
|
||||
client = ClientForm(request.POST)
|
||||
if client.is_valid():
|
||||
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