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)">
|
||||
<h1>Hotel INO Scrum</h1>
|
||||
<center><h3>Lista pokoi dostępnych w naszym hotelu</h3></center>
|
||||
<center><h3>{{ error }}</h3></center>
|
||||
<table id="hotels">
|
||||
<col style="width:10%">
|
||||
<col style="width:30%">
|
||||
|
@ -4,6 +4,7 @@ from django.shortcuts import get_object_or_404, render
|
||||
from .models import *
|
||||
from .forms import *
|
||||
import re
|
||||
import datetime
|
||||
|
||||
# Create your views here.
|
||||
|
||||
@ -18,36 +19,46 @@ def index(request):
|
||||
|
||||
def reservation(request):
|
||||
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')
|
||||
error = ""
|
||||
reservation = Reservation.objects.filter(room_number=request.POST['room'], begin_date__gte=begin_date, end_date__lte=end_date)
|
||||
|
||||
if reservation is not None:
|
||||
reservation = Reservation.objects.filter(room_number=room_number).filter(begin_date__gte=begin_date).filter(end_date__lte=end_date)
|
||||
print(reservation)
|
||||
if reservation:
|
||||
status = "Pokój " + str(room_number) + " jest już zarezerwowany"
|
||||
return HttpResponse(template.render({'status': status}, request))
|
||||
|
||||
else:
|
||||
if request.method == "POST":
|
||||
client_id = request.POST['id_number']
|
||||
if check(client_id):
|
||||
instance = Client.objects.get(id_number=client_id)
|
||||
client = ClientForm(request.POST, instance=instance)
|
||||
try:
|
||||
client_id = request.POST['id_number']
|
||||
if check(client_id):
|
||||
instance = Client.objects.get(id_number=client_id)
|
||||
client = ClientForm(request.POST, instance=instance)
|
||||
|
||||
if not Client.objects.get(id_number=client_id):
|
||||
client.save()
|
||||
if not Client.objects.get(id_number=client_id):
|
||||
client.save()
|
||||
|
||||
r = Reservation()
|
||||
r.room_number = get_object_or_404(Room, room_number=room_number)
|
||||
r.client_id = get_object_or_404(Client, id_number=client_id)
|
||||
r.begin_date = begin_date
|
||||
r.end_date = end_date
|
||||
r.save()
|
||||
r = Reservation()
|
||||
r.room_number = get_object_or_404(Room, room_number=room_number)
|
||||
r.client_id = get_object_or_404(Client, id_number=client_id)
|
||||
r.begin_date = begin_date
|
||||
r.end_date = end_date
|
||||
r.save()
|
||||
|
||||
status = "Pokój " + str(room_number) + " został pomyślnie zarejestrowany"
|
||||
return HttpResponse(template.render({'status': status}, request))
|
||||
|
||||
error = "Numer dowodu nieprawidłowy"
|
||||
status = "Pokój " + str(room_number) + " został pomyślnie zarejestrowany"
|
||||
return HttpResponse(template.render({'status': status}, request))
|
||||
|
||||
error = "Numer dowodu nieprawidłowy"
|
||||
except:
|
||||
pass
|
||||
form = ClientForm()
|
||||
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))
|
||||
|
Loading…
Reference in New Issue
Block a user