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(RoomType)
|
||||
admin.site.register(Reservation)
|
||||
admin.site.register(Client)
|
||||
|
||||
|
@ -9,13 +9,7 @@ class ClientForm(ModelForm):
|
||||
model = Client
|
||||
fields = '__all__'
|
||||
labels = {
|
||||
<<<<<<< HEAD
|
||||
'id_number': 'Numer dowodu: ',
|
||||
'name': 'Imię: ',
|
||||
'surname': 'Nazwisko: '
|
||||
=======
|
||||
'id_number': _('Numer dowodu '),
|
||||
'name': _('Imię '),
|
||||
'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)
|
||||
reserved = models.BooleanField()
|
||||
|
||||
def __str__(self):
|
||||
return str(self.room_number)
|
||||
@ -36,7 +35,7 @@ class Client(models.Model):
|
||||
surname = models.CharField(max_length=40)
|
||||
|
||||
def __str__(self):
|
||||
return self.name, self.surname
|
||||
return self.name + self.surname
|
||||
|
||||
|
||||
class Reservation(models.Model):
|
||||
|
@ -24,6 +24,9 @@
|
||||
{{ error }}
|
||||
{% csrf_token %}
|
||||
{{ 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">
|
||||
</form>
|
||||
</center>
|
||||
|
@ -33,7 +33,7 @@
|
||||
<td>{{ room.room_type }}</td>
|
||||
<td>{{ room.price }} zł</td>
|
||||
<td>
|
||||
{% if room.reserved %}
|
||||
|
||||
<form action="{% url 'reservation' %}" method="POST">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="room" value="{{ room.room_number }}">
|
||||
@ -43,17 +43,7 @@
|
||||
<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" >
|
||||
Od: <input type="date" name="begindate">
|
||||
Do: <input type="date" name="enddate"><br>
|
||||
<button>Rezerwuj</button>
|
||||
</div>
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
@ -4,6 +4,5 @@ from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('', views.index, name='index'),
|
||||
path('reservation', views.reservation, name='reservation'),
|
||||
path('clientform', views.addclient, name='addclient')
|
||||
path('reservation', views.reservation, name='reservation')
|
||||
]
|
@ -17,31 +17,40 @@ def index(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')
|
||||
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=request.POST['room'], begin_date__gte=begin_date, end_date__lte=end_date)
|
||||
|
||||
if reservation is not None:
|
||||
status = "Pokój " + str(room_number) + " jest już zarezerwowany"
|
||||
return HttpResponse(template.render({'status': status}, request))
|
||||
|
||||
|
||||
def addclient(request):
|
||||
error = ""
|
||||
else:
|
||||
if request.method == "POST":
|
||||
client = ClientForm(request.POST)
|
||||
if client.is_valid():
|
||||
if check(client.cleaned_data["id_number"]):
|
||||
client_id = request.POST['id_number']
|
||||
if check(client_id):
|
||||
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()
|
||||
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"
|
||||
|
||||
form = ClientForm()
|
||||
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):
|
||||
|
Loading…
Reference in New Issue
Block a user