mirror of
https://github.com/rjNemo/villafleurie
synced 2026-06-12 13:26:47 +00:00
created calendar service
This commit is contained in:
parent
43aa651e92
commit
0c196ce5e5
4 changed files with 32 additions and 15 deletions
1
TODO.md
1
TODO.md
|
|
@ -35,3 +35,4 @@
|
||||||
- [ ] Fuseau horaire
|
- [ ] Fuseau horaire
|
||||||
- [ ] Calendar API: [docs](https://github.com/googleapis/google-api-python-client/blob/master/docs/start.md)
|
- [ ] Calendar API: [docs](https://github.com/googleapis/google-api-python-client/blob/master/docs/start.md)
|
||||||
- [ ] Blog
|
- [ ] Blog
|
||||||
|
- [ ] Call update_calendar from BookingManager. SOlve circular dependencies
|
||||||
|
|
|
||||||
|
|
@ -2,6 +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
|
||||||
|
|
||||||
|
|
||||||
class BookingManager(models.Manager):
|
class BookingManager(models.Manager):
|
||||||
|
|
@ -10,10 +11,11 @@ class BookingManager(models.Manager):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def create_booking(self, **kwargs):
|
def create_booking(self, **kwargs):
|
||||||
""" create_booking creates a Booking instance. """
|
""" create_booking creates a Booking instance, computes the price and
|
||||||
|
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)
|
||||||
return booking
|
return booking
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,17 @@
|
||||||
from django.shortcuts import get_object_or_404
|
|
||||||
from rental.models.booking import Booking
|
|
||||||
from rental.models.contact import Contact
|
|
||||||
from rental.models.guest import Guest
|
|
||||||
from rental.models.picture import Picture
|
|
||||||
from rental.models.place import Place
|
|
||||||
from rental.models.testimonial import Testimonial
|
|
||||||
from villafleurie.settings import BASE_DIR
|
|
||||||
import datetime
|
import datetime
|
||||||
from google.auth.transport.requests import Request
|
from google.auth.transport.requests import Request
|
||||||
from google_auth_oauthlib.flow import InstalledAppFlow
|
from google_auth_oauthlib.flow import InstalledAppFlow
|
||||||
from googleapiclient.discovery import build
|
from googleapiclient.discovery import build
|
||||||
import os.path
|
import os.path
|
||||||
import pickle
|
import pickle
|
||||||
|
from villafleurie.settings import BASE_DIR
|
||||||
|
from django.shortcuts import get_object_or_404
|
||||||
|
from rental.models.contact import Contact
|
||||||
|
from rental.models.guest import Guest
|
||||||
|
from rental.models.picture import Picture
|
||||||
|
from rental.models.place import Place
|
||||||
|
from rental.models.testimonial import Testimonial
|
||||||
|
from rental.models.booking import Booking
|
||||||
|
|
||||||
|
|
||||||
def build_calendar_api_service():
|
def build_calendar_api_service():
|
||||||
|
|
@ -151,4 +151,20 @@ def update_calendar(reservation):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
s, c = build_calendar_api_service()
|
s, c = build_calendar_api_service()
|
||||||
|
|
||||||
|
from google_auth_oauthlib.flow import Flow
|
||||||
|
|
||||||
|
SCOPES = [
|
||||||
|
'https://www.googleapis.com/auth/calendar',
|
||||||
|
'https://www.googleapis.com/auth/calendar.events'
|
||||||
|
]
|
||||||
|
|
||||||
|
SECRETS = '/client_secrets.json'
|
||||||
|
|
||||||
|
flow = Flow.from_client_secrets_file(
|
||||||
|
SECRETS,
|
||||||
|
scopes=SCOPES,
|
||||||
|
redirect_uri='http://localhost:8080/'
|
||||||
|
)
|
||||||
|
|
@ -10,8 +10,7 @@ from rental.models.guest import Guest
|
||||||
from rental.models.picture import Picture
|
from rental.models.picture import Picture
|
||||||
from rental.models.place import Place
|
from rental.models.place import Place
|
||||||
from rental.models.testimonial import Testimonial
|
from rental.models.testimonial import Testimonial
|
||||||
|
from rental.services.calendar import check_availability, synchronize_calendars, update_calendar
|
||||||
from rental.bookings import check_availability, synchronize_calendars, update_calendar
|
|
||||||
from rental.tasks.apiMailer import * # or gMailer
|
from rental.tasks.apiMailer import * # or gMailer
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -81,15 +80,14 @@ def handle_reservation_form(request, context={}, init_template='rental/reservati
|
||||||
|
|
||||||
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, start, end)
|
||||||
price = get_reservation_price(place, start, end)
|
|
||||||
if available:
|
if available:
|
||||||
reservation = Booking.objects.create_booking(
|
reservation = Booking.objects.create_booking(
|
||||||
guest=guest,
|
guest=guest,
|
||||||
place=place,
|
place=place,
|
||||||
message=message,
|
message=message,
|
||||||
start=start,
|
start=start,
|
||||||
end=end,
|
end=end
|
||||||
price=price
|
|
||||||
)
|
)
|
||||||
send_quotation.delay(name, email)
|
send_quotation.delay(name, email)
|
||||||
update_calendar(reservation)
|
update_calendar(reservation)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue