mirror of
https://github.com/rjNemo/villafleurie
synced 2026-06-12 13:26:47 +00:00
add is_available method to place and update_calendar to BookingManager
This commit is contained in:
parent
0c196ce5e5
commit
431a041db3
4 changed files with 16 additions and 15 deletions
|
|
@ -2,7 +2,7 @@ from datetime import datetime
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from rental.models.guest import Guest
|
from rental.models.guest import Guest
|
||||||
from rental.models.place import Place
|
from rental.models.place import Place
|
||||||
# from rental.services.calendar import update_calendar
|
import rental.services.calendar as calendar
|
||||||
|
|
||||||
|
|
||||||
class BookingManager(models.Manager):
|
class BookingManager(models.Manager):
|
||||||
|
|
@ -15,7 +15,7 @@ class BookingManager(models.Manager):
|
||||||
updates the remote calendar. """
|
updates the remote calendar. """
|
||||||
booking = self.create(**kwargs)
|
booking = self.create(**kwargs)
|
||||||
booking.price = booking.get_price()
|
booking.price = booking.get_price()
|
||||||
# update_calendar(booking)
|
calendar.update_calendar(booking)
|
||||||
return booking
|
return booking
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from rental.models.picture import Picture
|
from rental.models.picture import Picture
|
||||||
|
import rental.services.calendar as calendar
|
||||||
|
|
||||||
|
|
||||||
class Place(models.Model):
|
class Place(models.Model):
|
||||||
|
|
@ -22,3 +23,6 @@ class Place(models.Model):
|
||||||
Picture, on_delete=models.CASCADE, blank=True, null=True)
|
Picture, on_delete=models.CASCADE, blank=True, null=True)
|
||||||
images = models.ManyToManyField(Picture, related_name="places", blank=True)
|
images = models.ManyToManyField(Picture, related_name="places", blank=True)
|
||||||
calendar = models.CharField(max_length=350, blank=True, null=True)
|
calendar = models.CharField(max_length=350, blank=True, null=True)
|
||||||
|
|
||||||
|
def is_available(self, start, end):
|
||||||
|
return calendar.check_availability(self, start, end)
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,9 @@ import os.path
|
||||||
import pickle
|
import pickle
|
||||||
from villafleurie.settings import BASE_DIR
|
from villafleurie.settings import BASE_DIR
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from rental.models.contact import Contact
|
|
||||||
from rental.models.guest import Guest
|
from rental.models.guest import Guest
|
||||||
from rental.models.picture import Picture
|
import rental.models.place as _place
|
||||||
from rental.models.place import Place
|
import rental.models.booking as _booking
|
||||||
from rental.models.testimonial import Testimonial
|
|
||||||
from rental.models.booking import Booking
|
|
||||||
|
|
||||||
|
|
||||||
def build_calendar_api_service():
|
def build_calendar_api_service():
|
||||||
|
|
@ -76,11 +73,11 @@ def get_calendar_reservations(place):
|
||||||
|
|
||||||
def synchronize_calendars(place):
|
def synchronize_calendars(place):
|
||||||
""" Get a complete list of existing bookings in calendar
|
""" Get a complete list of existing bookings in calendar
|
||||||
Creates reservation if not in db, update if already in db
|
Creates reservation if not in db, update if already in db
|
||||||
Delete from db reservation deleted from cal """
|
Delete from db reservation deleted from cal """
|
||||||
|
|
||||||
reservation = get_calendar_reservations(place)
|
reservation = get_calendar_reservations(place)
|
||||||
place = get_object_or_404(Place, name=place.name)
|
place = get_object_or_404(_place.Place, name=place.name)
|
||||||
|
|
||||||
start = reservation['start']
|
start = reservation['start']
|
||||||
end = reservation['end']
|
end = reservation['end']
|
||||||
|
|
@ -90,11 +87,11 @@ def synchronize_calendars(place):
|
||||||
guest = Guest.objects.create(name=reservation['guest'])
|
guest = Guest.objects.create(name=reservation['guest'])
|
||||||
else:
|
else:
|
||||||
guest = guest.first()
|
guest = guest.first()
|
||||||
db_booking = Booking.objects.filter(
|
db_booking = _booking.Booking.objects.filter(
|
||||||
guest=guest
|
guest=guest
|
||||||
)
|
)
|
||||||
if not db_booking.exists():
|
if not db_booking.exists():
|
||||||
Booking.objects.create_booking(
|
_booking.Booking.objects.create_booking(
|
||||||
place=place,
|
place=place,
|
||||||
guest=guest,
|
guest=guest,
|
||||||
start=start,
|
start=start,
|
||||||
|
|
@ -112,7 +109,7 @@ def get_bookings(place):
|
||||||
Returns a list of all related place reservations """
|
Returns a list of all related place reservations """
|
||||||
|
|
||||||
synchronize_calendars(place)
|
synchronize_calendars(place)
|
||||||
booked_dates = Booking.objects.filter(place=place)
|
booked_dates = _booking.Booking.objects.filter(place=place)
|
||||||
|
|
||||||
return [booking for booking in booked_dates]
|
return [booking for booking in booked_dates]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,9 +79,9 @@ def handle_reservation_form(request, context={}, init_template='rental/reservati
|
||||||
guest = guest.first()
|
guest = guest.first()
|
||||||
|
|
||||||
place = get_object_or_404(Place, name=place_name)
|
place = get_object_or_404(Place, name=place_name)
|
||||||
available = check_availability(place, start, end)
|
# available = check_availability(place, )
|
||||||
|
|
||||||
if available:
|
if place.is_available(start, end):
|
||||||
reservation = Booking.objects.create_booking(
|
reservation = Booking.objects.create_booking(
|
||||||
guest=guest,
|
guest=guest,
|
||||||
place=place,
|
place=place,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue