Compare commits

..

27 Commits

Author SHA1 Message Date
Hokan
bc2db30129 fix formularza klienta 2019-01-30 23:41:40 +01:00
Hokan
570463a30b fix formularza klienta 2019-01-30 22:41:22 +01:00
3d4a87e629 fix dzisiejszej daty + fix wygladu pickera 2019-01-30 22:20:56 +01:00
56eeed0f98 wyrownanie formularza 2019-01-30 22:05:23 +01:00
ebff9c20c6 zmiana tla + fixy 2019-01-30 21:46:01 +01:00
Hokan
a8e670c996 fix sprawdzania dat 2019-01-30 20:58:03 +01:00
bce5c78d35 Zaktualizuj 'hotel/rooms/views.py' 2019-01-27 13:37:59 +00:00
Łukasz Jędyk
6affb9915b styl przycisków zmiany strony 2019-01-27 13:01:04 +01:00
Hokan
e3bb9dd669 paginacja, popup przy dacie, zachowanie danych przy zlym formularzu 2019-01-27 00:49:14 +01:00
Łukasz Jędyk
7f0efb044e format daty + sortowanie + wyglad w tabeli 2019-01-26 19:39:48 +01:00
Łukasz Jędyk
ffd81453b7 fix 2019-01-23 12:22:27 +01:00
Hokan
646e675910 fix fixa rezerwacji 2019-01-23 00:04:23 +01:00
Hokan
037ab2737a fix formularza i rezerwacji 2019-01-22 22:20:06 +01:00
Hokan
50b7135472 podpiecie formularza do strony glownej + rezerwacje 2019-01-22 21:24:46 +01:00
Hokan
f8a6127c11 merge 2019-01-22 20:35:28 +01:00
Łukasz Jędyk
71595d5af2 fast date picker fix 2019-01-22 20:34:02 +01:00
Hokan
57520b10fa walidacja formularza 2019-01-22 20:28:51 +01:00
Hokan
6eb98b1b22 walidacja formularza 2019-01-22 20:28:25 +01:00
Łukasz Jędyk
79787db1a5 fix wybor tla + form style + date picker 2019-01-22 20:26:44 +01:00
4257fd0567 zmiana szerokości kolumn 2019-01-22 18:07:08 +00:00
f48b8d7158 Zaktualizuj 'hotel/rooms/templates/index.html'
zmiana szerokości kolumn
2019-01-22 18:04:19 +00:00
Hokan
e36992bc3f walidacja formularza 2019-01-22 18:39:08 +01:00
Hokan
531adcee2e modyfikacja bazy + formularz dodawania klienta 2019-01-20 12:06:40 +01:00
Hokan
316043e17f modyfikacja bazy + formularz dodawania klienta 2019-01-20 12:03:21 +01:00
Hokan
4a7996a075 modyfikacja bazy + formularz dodawania klienta 2019-01-20 12:01:23 +01:00
Hokan
8f2563c734 modyfikacja bazy + formularz dodawania klienta 2019-01-20 11:57:24 +01:00
Łukasz Jędyk
8ae157c04b wybor tla + sortowanie tabeli 2019-01-20 11:51:10 +01:00
65 changed files with 1692 additions and 178 deletions

View File

@ -1 +0,0 @@
web: gunicorn myproject.wsgi

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -12,6 +12,8 @@ https://docs.djangoproject.com/en/2.1/ref/settings/
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@ -104,13 +106,13 @@ AUTH_PASSWORD_VALIDATORS = [
# Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = 'pl'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_I18N = False
USE_L10N = True
USE_L10N = False
USE_TZ = True
@ -119,3 +121,5 @@ USE_TZ = True
# https://docs.djangoproject.com/en/2.1/howto/static-files/
STATIC_URL = '/static/'

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -3,4 +3,6 @@ from .models import *
admin.site.register(Room)
admin.site.register(RoomType)
admin.site.register(Reservation)
admin.site.register(Client)

23
hotel/rooms/forms.py Normal file
View 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'}

View 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')),
],
),
]

View 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',
),
]

View File

@ -1,5 +1,5 @@
from django.db import models
from django.core.validators import MinValueValidator
from django.core.validators import MinValueValidator, RegexValidator
class RoomType(models.Model):
@ -24,7 +24,24 @@ class Room(models.Model):
)
room_type = models.ForeignKey(RoomType, on_delete=models.CASCADE)
reserved = models.BooleanField()
def __str__(self):
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()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 559 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 451 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 676 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 633 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 939 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

1311
hotel/rooms/static/jquery-ui.css vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -22,11 +22,19 @@
color: white;
}
html {
background: url(images/background.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
#images {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
border-collapse: collapse;
background-color: white;
}
#images th {
border: 1px solid #ddd;
padding: 12px;
}
body {
background: url(images/background5.jpg) no-repeat center center fixed;
background-size: cover;
}
@ -48,3 +56,25 @@ a {
padding: 30px;
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;
}

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 = '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>

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

View File

@ -3,13 +3,65 @@
<html lang="en">
<head>
<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">
<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>
<body>
<body onLoad="changeBackground(imageUrl = 'static/images/background5.jpg')">
<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%">
<col style="width:15%">
<col style="width:45%">
<th>Numer pokoju</th>
<th>Typ pokoju</th>
<th>Cena</th>
@ -20,27 +72,35 @@
<td>{{ room.room_type }}</td>
<td>{{ room.price }} zł</td>
<td>
{% if room.reserved %}
<form action="{% url 'reservation' %}" method="POST">
<form action="{% url 'reservation' %}" class="dateform" method="POST">
{% csrf_token %}
<input type="hidden" name="room" value="{{ room.room_number }}">
<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>
</div>
</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>
</tr>
{% endfor %}
</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>
</html>

View File

@ -4,9 +4,18 @@
<head>
<link rel="stylesheet" type="text/css" href="{% static 'style.css' %}">
<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>
<body>
<body onLoad="changeBackground(imageUrl = 'static/images/background5.jpg')">
<br>
<center>
<div id="reservationbox">

View File

@ -4,5 +4,6 @@ from . import views
urlpatterns = [
path('', views.index, name='index'),
path('<int:page>', views.index, name='indexpage'),
path('reservation', views.reservation, name='reservation')
]

View File

@ -2,25 +2,102 @@ from django.http import HttpResponse
from django.template import loader
from django.shortcuts import get_object_or_404, render
from .models import *
from .forms import *
from django.db.models import Q
import datetime
import math
import re
# Create your views here.
def index(request):
rooms = Room.objects.all()
template = loader.get_template('index.html')
def index(request, page=1):
first_page, last_page = False, False
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):
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')
if not room.reserved:
room.reserved = True
room.save()
status = "Pokój " + str(room) + " zarezerwowany pomyślnie"
else:
status = "Pokój " + str(room) + " jest już zarezerwowany"
error = ""
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()
if not reservation is None:
status = "Pokój " + str(room_number) + " jest zajęty"
return HttpResponse(template.render({'status': status}, request))
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))

View File

@ -1,15 +0,0 @@
#!/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)

Binary file not shown.

View File

@ -1,126 +0,0 @@
"""
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())