podpiecie formularza do strony glownej + rezerwacje

This commit is contained in:
Hokan 2019-01-22 21:24:46 +01:00
parent f8a6127c11
commit 50b7135472
16 changed files with 56 additions and 43 deletions

Binary file not shown.

0
hotel/manage.py Normal file → Executable file
View File

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

View File

@ -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
} }

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

@ -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):

View File

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

View File

@ -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 %}

View File

@ -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')
] ]

View File

@ -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:
room.reserved = True
room.save()
status = "Pokój " + str(room) + " zarezerwowany pomyślnie"
else:
status = "Pokój " + str(room) + " jest już zarezerwowany"
return HttpResponse(template.render({'status': status}, request))
def addclient(request):
error = "" error = ""
if request.method == "POST": reservation = Reservation.objects.filter(room_number=request.POST['room'], begin_date__gte=begin_date, end_date__lte=end_date)
client = ClientForm(request.POST)
if client.is_valid(): if reservation is not None:
if check(client.cleaned_data["id_number"]): status = "Pokój " + str(room_number) + " jest już zarezerwowany"
client.save() return HttpResponse(template.render({'status': status}, request))
return HttpResponse()
else:
if request.method == "POST":
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()
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):