mirror of
https://github.com/rjNemo/villafleurie
synced 2026-06-06 02:16: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
|
||||
- [ ] Calendar API: [docs](https://github.com/googleapis/google-api-python-client/blob/master/docs/start.md)
|
||||
- [ ] Blog
|
||||
- [ ] Call update_calendar from BookingManager. SOlve circular dependencies
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ from datetime import datetime
|
|||
from django.db import models
|
||||
from rental.models.guest import Guest
|
||||
from rental.models.place import Place
|
||||
# from rental.services.calendar import update_calendar
|
||||
|
||||
|
||||
class BookingManager(models.Manager):
|
||||
|
|
@ -10,10 +11,11 @@ class BookingManager(models.Manager):
|
|||
"""
|
||||
|
||||
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.price = booking.get_price()
|
||||
|
||||
# update_calendar(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
|
||||
from google.auth.transport.requests import Request
|
||||
from google_auth_oauthlib.flow import InstalledAppFlow
|
||||
from googleapiclient.discovery import build
|
||||
import os.path
|
||||
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():
|
||||
|
|
@ -151,4 +151,20 @@ def update_calendar(reservation):
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
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.place import Place
|
||||
from rental.models.testimonial import Testimonial
|
||||
|
||||
from rental.bookings import check_availability, synchronize_calendars, update_calendar
|
||||
from rental.services.calendar import check_availability, synchronize_calendars, update_calendar
|
||||
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)
|
||||
available = check_availability(place, start, end)
|
||||
price = get_reservation_price(place, start, end)
|
||||
|
||||
if available:
|
||||
reservation = Booking.objects.create_booking(
|
||||
guest=guest,
|
||||
place=place,
|
||||
message=message,
|
||||
start=start,
|
||||
end=end,
|
||||
price=price
|
||||
end=end
|
||||
)
|
||||
send_quotation.delay(name, email)
|
||||
update_calendar(reservation)
|
||||
|
|
|
|||
Loading…
Reference in a new issue