fix formularza i rezerwacji
This commit is contained in:
parent
50b7135472
commit
037ab2737a
BIN
hotel/db.sqlite3
BIN
hotel/db.sqlite3
Binary file not shown.
Binary file not shown.
28
hotel/rooms/templates/error.html
Normal file
28
hotel/rooms/templates/error.html
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
{% load static %}
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<link rel="stylesheet" type="text/css" href="{% static 'style.css' %}">
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Rezerwacja</title>
|
||||||
|
<script>
|
||||||
|
function changeBackground(imageUrl) {
|
||||||
|
if(imageUrl != null) {
|
||||||
|
document.body.style.background = "url(" + imageUrl + ") no-repeat center center fixed";
|
||||||
|
document.body.style.backgroundSize = "cover";
|
||||||
|
localStorage.backgroundImage = imageUrl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body onLoad="changeBackground(imageUrl = localStorage.backgroundImage)">
|
||||||
|
<br>
|
||||||
|
<center>
|
||||||
|
<div id="reservationbox">
|
||||||
|
{{ error }}
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
<a href="{% url 'index' %}"><button>Wróć na stronę główną</button></a>
|
||||||
|
</center>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -18,6 +18,7 @@
|
|||||||
<body onLoad="changeBackground(imageUrl = localStorage.backgroundImage)">
|
<body onLoad="changeBackground(imageUrl = localStorage.backgroundImage)">
|
||||||
<h1>Hotel INO Scrum</h1>
|
<h1>Hotel INO Scrum</h1>
|
||||||
<center><h3>Lista pokoi dostępnych w naszym hotelu</h3></center>
|
<center><h3>Lista pokoi dostępnych w naszym hotelu</h3></center>
|
||||||
|
<center><h3>{{ error }}</h3></center>
|
||||||
<table id="hotels">
|
<table id="hotels">
|
||||||
<col style="width:10%">
|
<col style="width:10%">
|
||||||
<col style="width:30%">
|
<col style="width:30%">
|
||||||
|
@ -4,6 +4,7 @@ from django.shortcuts import get_object_or_404, render
|
|||||||
from .models import *
|
from .models import *
|
||||||
from .forms import *
|
from .forms import *
|
||||||
import re
|
import re
|
||||||
|
import datetime
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
@ -18,16 +19,25 @@ def index(request):
|
|||||||
|
|
||||||
def reservation(request):
|
def reservation(request):
|
||||||
room_number, begin_date, end_date = request.POST['room'], request.POST['begindate'], request.POST['enddate']
|
room_number, begin_date, end_date = request.POST['room'], request.POST['begindate'], request.POST['enddate']
|
||||||
|
try:
|
||||||
|
begin_datetime = datetime.datetime.strptime(begin_date, "%Y-%m-%d")
|
||||||
|
end_datetime = datetime.datetime.strptime(end_date, "%Y-%m-%d")
|
||||||
|
except:
|
||||||
|
return HttpResponse(loader.get_template('error.html').render({'error': "Błąd przy datach"}, request))
|
||||||
|
if begin_datetime == '' or end_datetime == '' or end_datetime < begin_datetime or begin_datetime < datetime.datetime.today() or end_datetime < datetime.datetime.today():
|
||||||
|
return HttpResponse(loader.get_template('error.html').render({'error': "Błąd przy datach"}, request))
|
||||||
|
|
||||||
template = loader.get_template('reservation.html')
|
template = loader.get_template('reservation.html')
|
||||||
error = ""
|
error = ""
|
||||||
reservation = Reservation.objects.filter(room_number=request.POST['room'], begin_date__gte=begin_date, end_date__lte=end_date)
|
reservation = Reservation.objects.filter(room_number=room_number).filter(begin_date__gte=begin_date).filter(end_date__lte=end_date)
|
||||||
|
print(reservation)
|
||||||
if reservation is not None:
|
if reservation:
|
||||||
status = "Pokój " + str(room_number) + " jest już zarezerwowany"
|
status = "Pokój " + str(room_number) + " jest już zarezerwowany"
|
||||||
return HttpResponse(template.render({'status': status}, request))
|
return HttpResponse(template.render({'status': status}, request))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
|
try:
|
||||||
client_id = request.POST['id_number']
|
client_id = request.POST['id_number']
|
||||||
if check(client_id):
|
if check(client_id):
|
||||||
instance = Client.objects.get(id_number=client_id)
|
instance = Client.objects.get(id_number=client_id)
|
||||||
@ -47,7 +57,8 @@ def reservation(request):
|
|||||||
return HttpResponse(template.render({'status': status}, request))
|
return HttpResponse(template.render({'status': status}, request))
|
||||||
|
|
||||||
error = "Numer dowodu nieprawidłowy"
|
error = "Numer dowodu nieprawidłowy"
|
||||||
|
except:
|
||||||
|
pass
|
||||||
form = ClientForm()
|
form = ClientForm()
|
||||||
template = loader.get_template('form.html')
|
template = loader.get_template('form.html')
|
||||||
return HttpResponse(template.render({'form': form, 'error': error, 'room_number': room_number, 'begin_date': begin_date, 'end_date': end_date}, request))
|
return HttpResponse(template.render({'form': form, 'error': error, 'room_number': room_number, 'begin_date': begin_date, 'end_date': end_date}, request))
|
||||||
|
Loading…
Reference in New Issue
Block a user