podpiecie formularza do strony glownej + rezerwacje
This commit is contained in:
parent
f8a6127c11
commit
50b7135472
BIN
hotel/db.sqlite3
BIN
hotel/db.sqlite3
Binary file not shown.
0
hotel/manage.py
Normal file → Executable file
0
hotel/manage.py
Normal file → Executable file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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)
|
||||||
|
|
||||||
|
@ -9,13 +9,7 @@ class ClientForm(ModelForm):
|
|||||||
model = Client
|
model = Client
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
labels = {
|
labels = {
|
||||||
<<<<<<< HEAD
|
|
||||||
'id_number': 'Numer dowodu: ',
|
|
||||||
'name': 'Imię: ',
|
|
||||||
'surname': 'Nazwisko: '
|
|
||||||
=======
|
|
||||||
'id_number': _('Numer dowodu '),
|
'id_number': _('Numer dowodu '),
|
||||||
'name': _('Imię '),
|
'name': _('Imię '),
|
||||||
'surname': _('Nazwisko ')
|
'surname': _('Nazwisko ')
|
||||||
>>>>>>> 79787db1a58d1e3a363982eba9f484be10a87aaf
|
|
||||||
}
|
}
|
||||||
|
17
hotel/rooms/migrations/0006_remove_room_reserved.py
Normal file
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',
|
||||||
|
),
|
||||||
|
]
|
Binary file not shown.
@ -24,7 +24,6 @@ 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)
|
||||||
@ -36,7 +35,7 @@ class Client(models.Model):
|
|||||||
surname = models.CharField(max_length=40)
|
surname = models.CharField(max_length=40)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name, self.surname
|
return self.name + self.surname
|
||||||
|
|
||||||
|
|
||||||
class Reservation(models.Model):
|
class Reservation(models.Model):
|
||||||
|
@ -24,6 +24,9 @@
|
|||||||
{{ error }}
|
{{ error }}
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ form.as_p }}
|
{{ form.as_p }}
|
||||||
|
<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">
|
<input type="submit" value="Rezerwuj">
|
||||||
</form>
|
</form>
|
||||||
</center>
|
</center>
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
<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' %}" method="POST">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<input type="hidden" name="room" value="{{ room.room_number }}">
|
<input type="hidden" name="room" value="{{ room.room_number }}">
|
||||||
@ -43,17 +43,7 @@
|
|||||||
<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" >
|
|
||||||
Od: <input type="date" name="begindate">
|
|
||||||
Do: <input type="date" name="enddate"><br>
|
|
||||||
<button>Rezerwuj</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -4,6 +4,5 @@ from . import views
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', views.index, name='index'),
|
path('', views.index, name='index'),
|
||||||
path('reservation', views.reservation, name='reservation'),
|
path('reservation', views.reservation, name='reservation')
|
||||||
path('clientform', views.addclient, name='addclient')
|
|
||||||
]
|
]
|
@ -17,31 +17,40 @@ def index(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']
|
||||||
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=request.POST['room'], begin_date__gte=begin_date, end_date__lte=end_date)
|
||||||
room.save()
|
|
||||||
status = "Pokój " + str(room) + " zarezerwowany pomyślnie"
|
|
||||||
else:
|
|
||||||
status = "Pokój " + str(room) + " jest już zarezerwowany"
|
|
||||||
|
|
||||||
|
if reservation is not None:
|
||||||
|
status = "Pokój " + str(room_number) + " jest już zarezerwowany"
|
||||||
return HttpResponse(template.render({'status': status}, request))
|
return HttpResponse(template.render({'status': status}, request))
|
||||||
|
|
||||||
|
else:
|
||||||
def addclient(request):
|
|
||||||
error = ""
|
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
client = ClientForm(request.POST)
|
client_id = request.POST['id_number']
|
||||||
if client.is_valid():
|
if check(client_id):
|
||||||
if check(client.cleaned_data["id_number"]):
|
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()
|
client.save()
|
||||||
return HttpResponse()
|
|
||||||
|
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"
|
error = "Numer dowodu nieprawidłowy"
|
||||||
|
|
||||||
form = ClientForm()
|
form = ClientForm()
|
||||||
template = loader.get_template('form.html')
|
template = loader.get_template('form.html')
|
||||||
return HttpResponse(template.render({'form': form, 'error': error}, request))
|
return HttpResponse(template.render({'form': form, 'error': error, 'room_number': room_number, 'begin_date': begin_date, 'end_date': end_date}, request))
|
||||||
|
|
||||||
|
|
||||||
def check(numer):
|
def check(numer):
|
||||||
|
Loading…
Reference in New Issue
Block a user