Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
31440f953f |
BIN
db.sqlite3
Normal file
BIN
hotel/db.sqlite3
@ -12,8 +12,6 @@ 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__)))
|
||||||
|
|
||||||
@ -106,13 +104,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 = 'pl'
|
LANGUAGE_CODE = 'en-us'
|
||||||
|
|
||||||
TIME_ZONE = 'UTC'
|
TIME_ZONE = 'UTC'
|
||||||
|
|
||||||
USE_I18N = False
|
USE_I18N = True
|
||||||
|
|
||||||
USE_L10N = False
|
USE_L10N = True
|
||||||
|
|
||||||
USE_TZ = True
|
USE_TZ = True
|
||||||
|
|
||||||
@ -121,5 +119,3 @@ 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/'
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,6 +3,4 @@ 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)
|
|
||||||
|
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
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'}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
|||||||
# 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')),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
]
|
|
@ -1,17 +0,0 @@
|
|||||||
# 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',
|
|
||||||
),
|
|
||||||
]
|
|
@ -1,5 +1,5 @@
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
from django.core.validators import MinValueValidator, RegexValidator
|
from django.core.validators import MinValueValidator
|
||||||
|
|
||||||
|
|
||||||
class RoomType(models.Model):
|
class RoomType(models.Model):
|
||||||
@ -24,24 +24,7 @@ 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()
|
|
||||||
|
|
||||||
|
BIN
hotel/rooms/static/images/background.jpg
Normal file
After Width: | Height: | Size: 1.5 MiB |
Before Width: | Height: | Size: 559 KiB |
Before Width: | Height: | Size: 451 KiB |
Before Width: | Height: | Size: 676 KiB |
Before Width: | Height: | Size: 633 KiB |
Before Width: | Height: | Size: 939 KiB |
Before Width: | Height: | Size: 6.8 KiB |
Before Width: | Height: | Size: 6.9 KiB |
Before Width: | Height: | Size: 4.6 KiB |
Before Width: | Height: | Size: 6.8 KiB |
Before Width: | Height: | Size: 4.5 KiB |
Before Width: | Height: | Size: 6.2 KiB |
1311
hotel/rooms/static/jquery-ui.css
vendored
@ -22,19 +22,11 @@
|
|||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
#images {
|
html {
|
||||||
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
|
background: url(images/background.jpg) no-repeat center center fixed;
|
||||||
border-collapse: collapse;
|
-webkit-background-size: cover;
|
||||||
background-color: white;
|
-moz-background-size: cover;
|
||||||
}
|
-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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,25 +48,3 @@ 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;
|
|
||||||
}
|
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
{% 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>
|
|
@ -1,45 +0,0 @@
|
|||||||
{% 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,65 +3,13 @@
|
|||||||
<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 onLoad="changeBackground(imageUrl = 'static/images/background5.jpg')">
|
<body>
|
||||||
<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>
|
||||||
@ -72,35 +20,27 @@
|
|||||||
<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' %}" class="dateform" method="POST">
|
<form action="{% url 'reservation' %}" 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,18 +4,9 @@
|
|||||||
<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>Rezerwacja</title>
|
<title>Zarezerwowano pokój</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 onLoad="changeBackground(imageUrl = 'static/images/background5.jpg')">
|
<body>
|
||||||
<br>
|
<br>
|
||||||
<center>
|
<center>
|
||||||
<div id="reservationbox">
|
<div id="reservationbox">
|
||||||
|
@ -4,6 +4,5 @@ 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,102 +2,25 @@ 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, page=1):
|
def index(request):
|
||||||
first_page, last_page = False, False
|
|
||||||
if page == 1:
|
|
||||||
first_page = True
|
|
||||||
|
|
||||||
rooms = Room.objects.all()
|
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')
|
template = loader.get_template('index.html')
|
||||||
return HttpResponse(template.render({'rooms': rooms,
|
|
||||||
'firstpage': first_page,
|
return HttpResponse(template.render({'rooms': rooms}, request))
|
||||||
'lastpage': last_page,
|
|
||||||
'pages': range(1,max_pages+1),
|
|
||||||
'currentpage': page}, request))
|
|
||||||
|
|
||||||
|
|
||||||
def reservation(request):
|
def reservation(request):
|
||||||
room_number, begin_date, end_date = request.POST['room'], request.POST['begindate'], request.POST['enddate']
|
room = get_object_or_404(Room, room_number=request.POST['room'])
|
||||||
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')
|
||||||
error = ""
|
if not room.reserved:
|
||||||
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.reserved = True
|
||||||
if not reservation is None:
|
room.save()
|
||||||
status = "Pokój " + str(room_number) + " jest zajęty"
|
status = "Pokój " + str(room) + " zarezerwowany pomyślnie"
|
||||||
return HttpResponse(template.render({'status': status}, request))
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if request.method == "POST":
|
status = "Pokój " + str(room) + " jest już zarezerwowany"
|
||||||
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))
|
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)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
15
manage.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'hotel.settings')
|
||||||
|
try:
|
||||||
|
from django.core.management import execute_from_command_line
|
||||||
|
except ImportError as exc:
|
||||||
|
raise ImportError(
|
||||||
|
"Couldn't import Django. Are you sure it's installed and "
|
||||||
|
"available on your PYTHONPATH environment variable? Did you "
|
||||||
|
"forget to activate a virtual environment?"
|
||||||
|
) from exc
|
||||||
|
execute_from_command_line(sys.argv)
|
BIN
requirements.txt
Normal file
126
settings.py
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
"""
|
||||||
|
Django settings for hotel project.
|
||||||
|
|
||||||
|
Generated by 'django-admin startproject' using Django 2.1.5.
|
||||||
|
|
||||||
|
For more information on this file, see
|
||||||
|
https://docs.djangoproject.com/en/2.1/topics/settings/
|
||||||
|
|
||||||
|
For the full list of settings and their values, see
|
||||||
|
https://docs.djangoproject.com/en/2.1/ref/settings/
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
import django_heroku
|
||||||
|
|
||||||
|
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||||
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
|
|
||||||
|
# Quick-start development settings - unsuitable for production
|
||||||
|
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
|
||||||
|
|
||||||
|
# SECURITY WARNING: keep the secret key used in production secret!
|
||||||
|
SECRET_KEY = 'qjkrranvqc3a+8!+6p4pxlk(w3dvuzt#dab1k2ajuqe+xza2@a'
|
||||||
|
|
||||||
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
|
DEBUG = True
|
||||||
|
|
||||||
|
ALLOWED_HOSTS = []
|
||||||
|
|
||||||
|
|
||||||
|
# Application definition
|
||||||
|
|
||||||
|
INSTALLED_APPS = [
|
||||||
|
'rooms.apps.RoomsConfig',
|
||||||
|
'django.contrib.admin',
|
||||||
|
'django.contrib.auth',
|
||||||
|
'django.contrib.contenttypes',
|
||||||
|
'django.contrib.sessions',
|
||||||
|
'django.contrib.messages',
|
||||||
|
'django.contrib.staticfiles'
|
||||||
|
]
|
||||||
|
|
||||||
|
MIDDLEWARE = [
|
||||||
|
'django.middleware.security.SecurityMiddleware',
|
||||||
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||||
|
'django.middleware.common.CommonMiddleware',
|
||||||
|
'django.middleware.csrf.CsrfViewMiddleware',
|
||||||
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||||
|
'django.contrib.messages.middleware.MessageMiddleware',
|
||||||
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||||
|
]
|
||||||
|
|
||||||
|
ROOT_URLCONF = 'hotel.urls'
|
||||||
|
|
||||||
|
TEMPLATES = [
|
||||||
|
{
|
||||||
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||||
|
'DIRS': [],
|
||||||
|
'APP_DIRS': True,
|
||||||
|
'OPTIONS': {
|
||||||
|
'context_processors': [
|
||||||
|
'django.template.context_processors.debug',
|
||||||
|
'django.template.context_processors.request',
|
||||||
|
'django.contrib.auth.context_processors.auth',
|
||||||
|
'django.contrib.messages.context_processors.messages',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
WSGI_APPLICATION = 'hotel.wsgi.application'
|
||||||
|
|
||||||
|
|
||||||
|
# Database
|
||||||
|
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
|
||||||
|
|
||||||
|
DATABASES = {
|
||||||
|
'default': {
|
||||||
|
'ENGINE': 'django.db.backends.sqlite3',
|
||||||
|
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Password validation
|
||||||
|
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
|
||||||
|
|
||||||
|
AUTH_PASSWORD_VALIDATORS = [
|
||||||
|
{
|
||||||
|
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
# Internationalization
|
||||||
|
# https://docs.djangoproject.com/en/2.1/topics/i18n/
|
||||||
|
|
||||||
|
LANGUAGE_CODE = 'en-us'
|
||||||
|
|
||||||
|
TIME_ZONE = 'UTC'
|
||||||
|
|
||||||
|
USE_I18N = True
|
||||||
|
|
||||||
|
USE_L10N = True
|
||||||
|
|
||||||
|
USE_TZ = True
|
||||||
|
|
||||||
|
|
||||||
|
# Static files (CSS, JavaScript, Images)
|
||||||
|
# https://docs.djangoproject.com/en/2.1/howto/static-files/
|
||||||
|
|
||||||
|
STATIC_URL = '/static/'
|
||||||
|
|
||||||
|
# Activate Django-Heroku.
|
||||||
|
django_heroku.settings(locals())
|