fix formularza i rezerwacji

This commit is contained in:
Hokan 2019-01-22 22:20:06 +01:00
parent 50b7135472
commit 037ab2737a
5 changed files with 59 additions and 19 deletions

Binary file not shown.

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

View File

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

View File

@ -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,36 +19,46 @@ 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":
client_id = request.POST['id_number'] try:
if check(client_id): client_id = request.POST['id_number']
instance = Client.objects.get(id_number=client_id) if check(client_id):
client = ClientForm(request.POST, instance=instance) instance = Client.objects.get(id_number=client_id)
client = ClientForm(request.POST, instance=instance)
if not Client.objects.get(id_number=client_id): if not Client.objects.get(id_number=client_id):
client.save() client.save()
r = Reservation() r = Reservation()
r.room_number = get_object_or_404(Room, room_number=room_number) 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.client_id = get_object_or_404(Client, id_number=client_id)
r.begin_date = begin_date r.begin_date = begin_date
r.end_date = end_date r.end_date = end_date
r.save() r.save()
status = "Pokój " + str(room_number) + " został pomyślnie zarejestrowany" status = "Pokój " + str(room_number) + " został pomyślnie zarejestrowany"
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))