Compare commits
27 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
bc2db30129 | ||
|
570463a30b | ||
3d4a87e629 | |||
56eeed0f98 | |||
ebff9c20c6 | |||
|
a8e670c996 | ||
bce5c78d35 | |||
|
6affb9915b | ||
|
e3bb9dd669 | ||
|
7f0efb044e | ||
|
ffd81453b7 | ||
|
646e675910 | ||
|
037ab2737a | ||
|
50b7135472 | ||
|
f8a6127c11 | ||
|
71595d5af2 | ||
|
57520b10fa | ||
|
6eb98b1b22 | ||
|
79787db1a5 | ||
4257fd0567 | |||
f48b8d7158 | |||
|
e36992bc3f | ||
|
531adcee2e | ||
|
316043e17f | ||
|
4a7996a075 | ||
|
8f2563c734 | ||
|
8ae157c04b |
BIN
hotel/db.sqlite3
BIN
hotel/hotel/__pycache__/__init__.cpython-37.pyc
Normal file
BIN
hotel/hotel/__pycache__/settings.cpython-37.pyc
Normal file
BIN
hotel/hotel/__pycache__/urls.cpython-37.pyc
Normal file
BIN
hotel/hotel/__pycache__/wsgi.cpython-37.pyc
Normal file
@ -12,6 +12,8 @@ https://docs.djangoproject.com/en/2.1/ref/settings/
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
@ -104,13 +106,13 @@ AUTH_PASSWORD_VALIDATORS = [
|
|||||||
# Internationalization
|
# Internationalization
|
||||||
# https://docs.djangoproject.com/en/2.1/topics/i18n/
|
# https://docs.djangoproject.com/en/2.1/topics/i18n/
|
||||||
|
|
||||||
LANGUAGE_CODE = 'en-us'
|
LANGUAGE_CODE = 'pl'
|
||||||
|
|
||||||
TIME_ZONE = 'UTC'
|
TIME_ZONE = 'UTC'
|
||||||
|
|
||||||
USE_I18N = True
|
USE_I18N = False
|
||||||
|
|
||||||
USE_L10N = True
|
USE_L10N = False
|
||||||
|
|
||||||
USE_TZ = True
|
USE_TZ = True
|
||||||
|
|
||||||
@ -119,3 +121,5 @@ USE_TZ = True
|
|||||||
# https://docs.djangoproject.com/en/2.1/howto/static-files/
|
# https://docs.djangoproject.com/en/2.1/howto/static-files/
|
||||||
|
|
||||||
STATIC_URL = '/static/'
|
STATIC_URL = '/static/'
|
||||||
|
|
||||||
|
|
||||||
|
BIN
hotel/rooms/__pycache__/__init__.cpython-37.pyc
Normal file
BIN
hotel/rooms/__pycache__/admin.cpython-37.pyc
Normal file
BIN
hotel/rooms/__pycache__/apps.cpython-37.pyc
Normal file
BIN
hotel/rooms/__pycache__/forms.cpython-35.pyc
Normal file
BIN
hotel/rooms/__pycache__/forms.cpython-36.pyc
Normal file
BIN
hotel/rooms/__pycache__/forms.cpython-37.pyc
Normal file
BIN
hotel/rooms/__pycache__/models.cpython-37.pyc
Normal file
BIN
hotel/rooms/__pycache__/urls.cpython-37.pyc
Normal file
BIN
hotel/rooms/__pycache__/views.cpython-37.pyc
Normal file
@ -3,4 +3,6 @@ from .models import *
|
|||||||
|
|
||||||
admin.site.register(Room)
|
admin.site.register(Room)
|
||||||
admin.site.register(RoomType)
|
admin.site.register(RoomType)
|
||||||
|
admin.site.register(Reservation)
|
||||||
|
admin.site.register(Client)
|
||||||
|
|
||||||
|
23
hotel/rooms/forms.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
from django.forms import ModelForm
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from .models import *
|
||||||
|
|
||||||
|
|
||||||
|
class ClientForm(ModelForm):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
|
||||||
|
model = Client
|
||||||
|
fields = '__all__'
|
||||||
|
labels = {
|
||||||
|
'id_number': _('Numer dowodu '),
|
||||||
|
'name': _('Imię '),
|
||||||
|
'surname': _('Nazwisko ')
|
||||||
|
}
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(ClientForm, self).__init__(*args, **kwargs)
|
||||||
|
self.fields['id_number'].error_messages = {'required': 'custom required message'}
|
||||||
|
|
||||||
|
|
||||||
|
|
32
hotel/rooms/migrations/0005_client_reservation.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# Generated by Django 2.1.5 on 2019-01-20 11:06
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('rooms', '0004_auto_20190112_2307'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Client',
|
||||||
|
fields=[
|
||||||
|
('id_number', models.CharField(max_length=9, primary_key=True, serialize=False)),
|
||||||
|
('name', models.CharField(max_length=40)),
|
||||||
|
('surname', models.CharField(max_length=40)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Reservation',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('begin_date', models.DateField()),
|
||||||
|
('end_date', models.DateField()),
|
||||||
|
('client_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='rooms.Client')),
|
||||||
|
('room_number', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='rooms.Room')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
17
hotel/rooms/migrations/0006_remove_room_reserved.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# Generated by Django 2.1.5 on 2019-01-22 20:01
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('rooms', '0005_client_reservation'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='room',
|
||||||
|
name='reserved',
|
||||||
|
),
|
||||||
|
]
|
BIN
hotel/rooms/migrations/__pycache__/0001_initial.cpython-37.pyc
Normal file
BIN
hotel/rooms/migrations/__pycache__/__init__.cpython-37.pyc
Normal file
@ -1,5 +1,5 @@
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
from django.core.validators import MinValueValidator
|
from django.core.validators import MinValueValidator, RegexValidator
|
||||||
|
|
||||||
|
|
||||||
class RoomType(models.Model):
|
class RoomType(models.Model):
|
||||||
@ -24,7 +24,24 @@ class Room(models.Model):
|
|||||||
)
|
)
|
||||||
|
|
||||||
room_type = models.ForeignKey(RoomType, on_delete=models.CASCADE)
|
room_type = models.ForeignKey(RoomType, on_delete=models.CASCADE)
|
||||||
reserved = models.BooleanField()
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.room_number)
|
return str(self.room_number)
|
||||||
|
|
||||||
|
|
||||||
|
class Client(models.Model):
|
||||||
|
id_number = models.CharField(max_length=9,
|
||||||
|
primary_key=True)
|
||||||
|
name = models.CharField(max_length=40)
|
||||||
|
surname = models.CharField(max_length=40)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name + self.surname
|
||||||
|
|
||||||
|
|
||||||
|
class Reservation(models.Model):
|
||||||
|
room_number = models.ForeignKey(Room, on_delete=models.CASCADE)
|
||||||
|
client_id = models.ForeignKey(Client, on_delete=models.CASCADE)
|
||||||
|
begin_date = models.DateField()
|
||||||
|
end_date = models.DateField()
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 1.5 MiB |
BIN
hotel/rooms/static/images/background1.jpg
Normal file
After Width: | Height: | Size: 559 KiB |
BIN
hotel/rooms/static/images/background2.jpg
Normal file
After Width: | Height: | Size: 451 KiB |
BIN
hotel/rooms/static/images/background3.jpg
Normal file
After Width: | Height: | Size: 676 KiB |
BIN
hotel/rooms/static/images/background4.jpg
Normal file
After Width: | Height: | Size: 633 KiB |
BIN
hotel/rooms/static/images/background5.jpg
Normal file
After Width: | Height: | Size: 939 KiB |
BIN
hotel/rooms/static/images/ui-icons_444444_256x240.png
Normal file
After Width: | Height: | Size: 6.8 KiB |
BIN
hotel/rooms/static/images/ui-icons_555555_256x240.png
Normal file
After Width: | Height: | Size: 6.9 KiB |
BIN
hotel/rooms/static/images/ui-icons_777620_256x240.png
Normal file
After Width: | Height: | Size: 4.6 KiB |
BIN
hotel/rooms/static/images/ui-icons_777777_256x240.png
Normal file
After Width: | Height: | Size: 6.8 KiB |
BIN
hotel/rooms/static/images/ui-icons_cc0000_256x240.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
hotel/rooms/static/images/ui-icons_ffffff_256x240.png
Normal file
After Width: | Height: | Size: 6.2 KiB |
1311
hotel/rooms/static/jquery-ui.css
vendored
Normal file
@ -22,11 +22,19 @@
|
|||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
html {
|
#images {
|
||||||
background: url(images/background.jpg) no-repeat center center fixed;
|
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
|
||||||
-webkit-background-size: cover;
|
border-collapse: collapse;
|
||||||
-moz-background-size: cover;
|
background-color: white;
|
||||||
-o-background-size: cover;
|
}
|
||||||
|
|
||||||
|
#images th {
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
padding: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
background: url(images/background5.jpg) no-repeat center center fixed;
|
||||||
background-size: cover;
|
background-size: cover;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,3 +56,25 @@ a {
|
|||||||
padding: 30px;
|
padding: 30px;
|
||||||
border: 2px solid grey;
|
border: 2px solid grey;
|
||||||
}
|
}
|
||||||
|
#reservationform {
|
||||||
|
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
|
||||||
|
font-size: 30px;
|
||||||
|
background-color: white;
|
||||||
|
color: black;
|
||||||
|
width: 40%;
|
||||||
|
padding: 10px;
|
||||||
|
border: 2px solid grey;
|
||||||
|
}
|
||||||
|
#page {
|
||||||
|
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
|
||||||
|
display:inline-block;
|
||||||
|
color: #444;
|
||||||
|
border: 1px solid #CCC;
|
||||||
|
background: #efefef;
|
||||||
|
box-shadow: 0 0 5px -1px rgba(0,0,0,0.2);
|
||||||
|
cursor: pointer;
|
||||||
|
vertical-align: middle;
|
||||||
|
max-width: 100px;
|
||||||
|
padding: 5px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
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 = 'static/images/background5.jpg')">
|
||||||
|
<br>
|
||||||
|
<center>
|
||||||
|
<div id="reservationbox">
|
||||||
|
{{ error }}
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
<a href="{% url 'index' %}"><button>Wróć na stronę główną</button></a>
|
||||||
|
</center>
|
||||||
|
</body>
|
||||||
|
</html>
|
45
hotel/rooms/templates/form.html
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
{% load static %}
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<link rel="stylesheet" type="text/css" href="{% static 'style.css' %}">
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Formularz rezerwacji</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 = 'static/images/background5.jpg')">
|
||||||
|
<br>
|
||||||
|
<center>
|
||||||
|
<h1>Formularz rezerwacji</h1>
|
||||||
|
<div id="reservationform">
|
||||||
|
<form action="" method="post">
|
||||||
|
{{ error }}
|
||||||
|
{% csrf_token %}
|
||||||
|
<table>
|
||||||
|
<th><th>
|
||||||
|
{% for field in form %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ field.label }}</td>
|
||||||
|
<td></td><td></td><td></td><td></td>
|
||||||
|
<td>{{ field }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
<input type="hidden" name="room" value="{{ room_number }}">
|
||||||
|
<input type="hidden" name="begindate" value="{{ begin_date }}">
|
||||||
|
<input type="hidden" name="enddate" value="{{ end_date }}">
|
||||||
|
<input type="submit" value="Rezerwuj">
|
||||||
|
</form>
|
||||||
|
</center>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -3,13 +3,65 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<link rel="stylesheet" type="text/css" href="{% static 'style.css' %}">
|
<link rel="stylesheet" type="text/css" href="{% static 'style.css' %}">
|
||||||
|
<link rel="stylesheet" type="text/css" href="{% static 'jquery-ui.css' %}">
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>Hotel INO Scrum</title>
|
<title>Hotel INO Scrum</title>
|
||||||
|
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
|
||||||
|
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
|
||||||
|
<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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$( function() {
|
||||||
|
$( ".datepicker" ).datepicker({ dateFormat: 'dd-mm-yy' }).val();
|
||||||
|
|
||||||
|
$( ".dateform" ).submit(function(event){
|
||||||
|
|
||||||
|
var begindate = $(this).find('input[name=begindate]').val().split("-");
|
||||||
|
var enddate = $(this).find('input[name=enddate]').val().split("-");
|
||||||
|
|
||||||
|
var todayTime = new Date();
|
||||||
|
var dd = today.getDate();
|
||||||
|
var mm = today.getMonth();
|
||||||
|
var yyyy = today.getFullYear();
|
||||||
|
var today = new Date(yyyy, mm, dd);
|
||||||
|
begindate = new Date(begindate[2], begindate[1] - 1, begindate[0]);
|
||||||
|
enddate = new Date(enddate[2], enddate[1] - 1, enddate[0]);
|
||||||
|
if (begindate.getTime() < today.getTime()){
|
||||||
|
alert('Data początkowa jest z przeszłości');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (enddate.getTime() < today.getTime()){
|
||||||
|
alert('Data końcowa jest z przeszłości');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (begindate.getTime() > enddate.getTime()){
|
||||||
|
alert('Data końcowa jest przed początkową');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
} );
|
||||||
|
|
||||||
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body onLoad="changeBackground(imageUrl = 'static/images/background5.jpg')">
|
||||||
<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:30%">
|
||||||
|
<col style="width:15%">
|
||||||
|
<col style="width:45%">
|
||||||
<th>Numer pokoju</th>
|
<th>Numer pokoju</th>
|
||||||
<th>Typ pokoju</th>
|
<th>Typ pokoju</th>
|
||||||
<th>Cena</th>
|
<th>Cena</th>
|
||||||
@ -20,27 +72,35 @@
|
|||||||
<td>{{ room.room_type }}</td>
|
<td>{{ room.room_type }}</td>
|
||||||
<td>{{ room.price }} zł</td>
|
<td>{{ room.price }} zł</td>
|
||||||
<td>
|
<td>
|
||||||
{% if room.reserved %}
|
|
||||||
<form action="{% url 'reservation' %}" method="POST">
|
<form action="{% url 'reservation' %}" class="dateform" method="POST">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<input type="hidden" name="room" value="{{ room.room_number }}">
|
<input type="hidden" name="room" value="{{ room.room_number }}">
|
||||||
<div class="button-box" >
|
<div class="button-box" >
|
||||||
|
Od: <input type="text" class="datepicker" name="begindate" size="6" required>
|
||||||
|
Do: <input type="text" class="datepicker" name="enddate" size="6" required>
|
||||||
<button>Rezerwuj</button>
|
<button>Rezerwuj</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
{% else %}
|
|
||||||
<form action="{% url 'reservation' %}" method="POST">
|
|
||||||
{% csrf_token %}
|
|
||||||
<input type="hidden" name="room" value="{{ room.room_number }}">
|
|
||||||
<div class="button-box" >
|
|
||||||
<button>Rezerwuj</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
<br>
|
||||||
|
<center>
|
||||||
|
{% if firstpage == False %}
|
||||||
|
<a href="{% url 'indexpage' currentpage|add:'-1' %}"><button id="page"><<</button></a>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% for p in pages %}
|
||||||
|
<a href="{% url 'indexpage' p %}"><div id="page">{{ p }}</div></a>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% if lastpage == False %}
|
||||||
|
<a href="{% url 'indexpage' currentpage|add:'+1' %}"><button id="page">>></button></a>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
</center>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -4,9 +4,18 @@
|
|||||||
<head>
|
<head>
|
||||||
<link rel="stylesheet" type="text/css" href="{% static 'style.css' %}">
|
<link rel="stylesheet" type="text/css" href="{% static 'style.css' %}">
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>Zarezerwowano pokój</title>
|
<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>
|
</head>
|
||||||
<body>
|
<body onLoad="changeBackground(imageUrl = 'static/images/background5.jpg')">
|
||||||
<br>
|
<br>
|
||||||
<center>
|
<center>
|
||||||
<div id="reservationbox">
|
<div id="reservationbox">
|
||||||
|
@ -4,5 +4,6 @@ from . import views
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', views.index, name='index'),
|
path('', views.index, name='index'),
|
||||||
|
path('<int:page>', views.index, name='indexpage'),
|
||||||
path('reservation', views.reservation, name='reservation')
|
path('reservation', views.reservation, name='reservation')
|
||||||
]
|
]
|
@ -2,25 +2,102 @@ from django.http import HttpResponse
|
|||||||
from django.template import loader
|
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 django.db.models import Q
|
||||||
|
import datetime
|
||||||
|
import math
|
||||||
|
import re
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
def index(request, page=1):
|
||||||
rooms = Room.objects.all()
|
first_page, last_page = False, False
|
||||||
template = loader.get_template('index.html')
|
if page == 1:
|
||||||
|
first_page = True
|
||||||
|
|
||||||
return HttpResponse(template.render({'rooms': rooms}, request))
|
rooms = Room.objects.all()
|
||||||
|
rooms = rooms.order_by('room_type', 'room_number')
|
||||||
|
|
||||||
|
if page*10 >= len(rooms):
|
||||||
|
last_page = True
|
||||||
|
|
||||||
|
max_pages = math.ceil(len(rooms)/10)
|
||||||
|
|
||||||
|
rooms = rooms[10*(page-1):10*page]
|
||||||
|
template = loader.get_template('index.html')
|
||||||
|
return HttpResponse(template.render({'rooms': rooms,
|
||||||
|
'firstpage': first_page,
|
||||||
|
'lastpage': last_page,
|
||||||
|
'pages': range(1,max_pages+1),
|
||||||
|
'currentpage': page}, request))
|
||||||
|
|
||||||
|
|
||||||
def reservation(request):
|
def reservation(request):
|
||||||
room = get_object_or_404(Room, room_number=request.POST['room'])
|
room_number, begin_date, end_date = request.POST['room'], request.POST['begindate'], request.POST['enddate']
|
||||||
|
begin_datetime = datetime.datetime.strptime(begin_date, "%d-%m-%Y")
|
||||||
|
end_datetime = datetime.datetime.strptime(end_date, "%d-%m-%Y")
|
||||||
|
clientform = {}
|
||||||
template = loader.get_template('reservation.html')
|
template = loader.get_template('reservation.html')
|
||||||
if not room.reserved:
|
error = ""
|
||||||
room.reserved = True
|
reservation = Reservation.objects.filter(room_number=room_number).filter(Q(begin_date__range=(begin_datetime, end_datetime)) | Q(end_date__range=(begin_datetime, end_datetime))).first()
|
||||||
room.save()
|
if not reservation is None:
|
||||||
status = "Pokój " + str(room) + " zarezerwowany pomyślnie"
|
status = "Pokój " + str(room_number) + " jest zajęty"
|
||||||
else:
|
return HttpResponse(template.render({'status': status}, request))
|
||||||
status = "Pokój " + str(room) + " jest już zarezerwowany"
|
|
||||||
|
else:
|
||||||
|
if request.method == "POST":
|
||||||
|
begin = datetime.datetime.strptime(begin_date, "%d-%m-%Y")
|
||||||
|
end = datetime.datetime.strptime(end_date, "%d-%m-%Y")
|
||||||
|
client_id = request.POST.get('id_number', False)
|
||||||
|
if client_id:
|
||||||
|
|
||||||
|
client = ClientForm(request.POST)
|
||||||
|
if client.is_valid():
|
||||||
|
id_number = client.cleaned_data['id_number']
|
||||||
|
clientform = {'id_number': client.cleaned_data['id_number'],
|
||||||
|
'name': client.cleaned_data['name'],
|
||||||
|
'surname': client.cleaned_data['surname']}
|
||||||
|
if check(id_number):
|
||||||
|
if Client.objects.filter(id_number=client_id).first() is None:
|
||||||
|
client.save()
|
||||||
|
else:
|
||||||
|
error = "Zły numer dowodu"
|
||||||
|
form = ClientForm(initial=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))
|
||||||
|
|
||||||
|
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
|
||||||
|
r.end_date = end
|
||||||
|
r.save()
|
||||||
|
|
||||||
|
status = "Pokój " + str(room_number) + " został pomyślnie zarezerwowany"
|
||||||
|
|
||||||
|
return HttpResponse(template.render({'status': status}, request))
|
||||||
|
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
|
form = ClientForm(initial=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))
|
||||||
|
|
||||||
|
def check(numer):
|
||||||
|
pattern = re.compile(r'[A-Z][A-Z][A-Z]\d\d\d\d\d\d')
|
||||||
|
|
||||||
|
return pattern.match(numer)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return HttpResponse(template.render({'status': status}, request))
|
|