mail templates

This commit is contained in:
Ruidy Nemausat 2020-01-03 18:06:04 +01:00
parent c9ce373a4d
commit e8ea95fc87
18 changed files with 16 additions and 16 deletions

View file

@ -99,8 +99,8 @@ Le visiteur doit pouvoir :
## TO DO ## TO DO
- Ajouter un date picker dans le formulaire de réservation, changer les placeholders (j'ai pas envie de jouer avec JQuery) - Ajouter un date picker dans le formulaire de réservation
- Envoyer devis réservation par mail et notification aux hôtes (put it in a background process, personnaliser les htmails : contact, admin et réservation) - Envoyer devis réservation par mail et notification aux hôtes (personnaliser les htmails : contact, admin et réservation)
- Ajout page/module de paiement - Ajout page/module de paiement
- ajouter les témoignages depuis Booking, AirBnb, ajouter le lien - ajouter les témoignages depuis Booking, AirBnb, ajouter le lien
- changer l'adresse de l'admin, personnaliser le back-end (design et les infos displayed per model) - changer l'adresse de l'admin, personnaliser le back-end (design et les infos displayed per model)

View file

@ -13,7 +13,6 @@ from villafleurie.settings import BASE_DIR
def build_calendar_api_service(): def build_calendar_api_service():
""" Build Google Calendar API service and returns calendar list and service """ """ Build Google Calendar API service and returns calendar list and service """
creds = None creds = None
# If modifying these scopes, delete the file token.pickle. # If modifying these scopes, delete the file token.pickle.
SCOPES = [ SCOPES = [
@ -38,9 +37,7 @@ def build_calendar_api_service():
# Save the credentials for the next run # Save the credentials for the next run
with open('token.pickle', 'wb') as token: with open('token.pickle', 'wb') as token:
pickle.dump(creds, token) pickle.dump(creds, token)
service = build('calendar', 'v3', credentials=creds) service = build('calendar', 'v3', credentials=creds)
calendars = { calendars = {
'T2': "burik7aclvhc7vsboh06c179uo@group.calendar.google.com", 'T2': "burik7aclvhc7vsboh06c179uo@group.calendar.google.com",
'T3': "fu7h30p0gk4a2p4nvo7nsbgpok@group.calendar.google.com" 'T3': "fu7h30p0gk4a2p4nvo7nsbgpok@group.calendar.google.com"
@ -51,7 +48,6 @@ def build_calendar_api_service():
def get_calendar_reservations(place): def get_calendar_reservations(place):
service, calendars = build_calendar_api_service() service, calendars = build_calendar_api_service()
now = datetime.datetime.utcnow().isoformat() + 'Z' # 'Z' indicates UTC time now = datetime.datetime.utcnow().isoformat() + 'Z' # 'Z' indicates UTC time
events_result = service.events().list( events_result = service.events().list(
calendarId=calendars[place.name], calendarId=calendars[place.name],
timeMin=now, timeMin=now,
@ -76,7 +72,6 @@ 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, name=place.name)
price = get_reservation_price( price = get_reservation_price(
@ -86,17 +81,14 @@ def synchronize_calendars(place):
) )
start = reservation['start'] start = reservation['start']
end = reservation['end'] end = reservation['end']
guest = Guest.objects.filter(name=reservation['guest']) guest = Guest.objects.filter(name=reservation['guest'])
if not guest.exists(): if not guest.exists():
guest = Guest.objects.create(name=reservation['guest']) guest = Guest.objects.create(name=reservation['guest'])
else: else:
guest = guest.first() guest = guest.first()
db_booking = Reservation.objects.filter( db_booking = Reservation.objects.filter(
guest=guest guest=guest
) )
if not db_booking.exists(): if not db_booking.exists():
Reservation.objects.create( Reservation.objects.create(
place=place, place=place,
@ -116,7 +108,6 @@ def synchronize_calendars(place):
def get_bookings(place): def get_bookings(place):
""" Synchronize with Master calendar via a call to synchronize_calendar """ Synchronize with Master calendar via a call to synchronize_calendar
Returns a list of all related place reservations """ Returns a list of all related place reservations """
synchronize_calendars(place) synchronize_calendars(place)
booked_dates = Reservation.objects.filter(place=place) booked_dates = Reservation.objects.filter(place=place)
return [booking for booking in booked_dates] return [booking for booking in booked_dates]
@ -124,7 +115,6 @@ def get_bookings(place):
def check_availability(place, start_date, end_date): def check_availability(place, start_date, end_date):
""" check if the related place is available during a given period """ """ check if the related place is available during a given period """
bookings = get_bookings(place) bookings = get_bookings(place)
for booking in bookings: for booking in bookings:
if (booking.start <= start_date <= booking.end) or (booking.start <= end_date <= booking.end): if (booking.start <= start_date <= booking.end) or (booking.start <= end_date <= booking.end):

View file

@ -1,6 +1,7 @@
from __future__ import absolute_import, unicode_literals from __future__ import absolute_import, unicode_literals
from celery import shared_task from celery import shared_task
from django.core.mail import send_mail, mail_admins from django.core.mail import send_mail, mail_admins
from django.shortcuts import render
from villafleurie.settings import EMAIL_HOST_USER, BASE_DIR from villafleurie.settings import EMAIL_HOST_USER, BASE_DIR
from rental.bookings import build_calendar_api_service from rental.bookings import build_calendar_api_service
import os import os
@ -11,16 +12,24 @@ def send_confirmation_mail(name, email, template="ticket"):
""" Send confirmation message to customer """ """ Send confirmation message to customer """
subject = "Nous avons reçu votre message" subject = "Nous avons reçu votre message"
message = f" Merci {name}, Bien reçu nous revenons vers vous rapidement ! - HtmlMessage" message = f" Merci {name}, Bien reçu nous revenons vers vous rapidement ! - HtmlMessage"
html_path = os.path.join(BASE_DIR, 'rental/templates/rental/html/') html_path = os.path.join(BASE_DIR, 'rental/templates/rental/html/')
with open(os.path.join(html_path, f"{template}.html"), 'r') as html: with open(os.path.join(html_path, f"{template}.html"), 'r') as html:
html_message = html.read() html_message = html.read()
# html_path = os.path.join(
# 'rental/templates/rental/mails/', f"{template}.html")
# context = {
# "name": name,
# "email": email,
# "message": message
# }
# html_message = render(request, html_path, context)
send_mail( send_mail(
subject, subject,
message, message,
EMAIL_HOST_USER, EMAIL_HOST_USER,
[email], [email],
# html_message=html_message.content
html_message=html_message html_message=html_message
) )

View file

@ -100,7 +100,7 @@
<body style="background-color:#f8f8f8;"> <body style="background-color:#f8f8f8;">
<div style="background-color:#f8f8f8;"> <div style="background-color:#f8f8f8;">
<div style="Margin:0px auto;max-width:600px;"> <div style="Margin:0px auto;max-width:600px;">
<table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;"> <table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;">
<tbody> <tbody>
<tr> <tr>

View file

@ -8,7 +8,8 @@ ADMINS = [
] ]
SECRET_KEY = os.environ.get('SECRET_KEY') SECRET_KEY = os.environ.get('SECRET_KEY')
# SECRET_KEY = "q00_4wqdc^n=7)p2lm)!gy&fms8md_b4#1aqysllvqq==2c9!$" SECRET_KEY = "q00_4wqdc^n=7)p2lm)!gy&fms8md_b4#1aqysllvqq==2c9!$"
if os.environ.get('ENV') == 'PRODUCTION': if os.environ.get('ENV') == 'PRODUCTION':
DEBUG = False DEBUG = False
@ -148,6 +149,6 @@ EMAIL_SUBJECT_PREFIX = "[VillaFleurieGuadeloupe] "
DEFAULT_FROM_EMAIL = "'Nilka, VillaFleurie' <location.villaFleurie@gmail.com>" DEFAULT_FROM_EMAIL = "'Nilka, VillaFleurie' <location.villaFleurie@gmail.com>"
EMAIL_HOST_USER = "location.villafleurie@gmail.com" EMAIL_HOST_USER = "location.villafleurie@gmail.com"
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD') EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD')
# EMAIL_HOST_PASSWORD = "location229818" EMAIL_HOST_PASSWORD = "location229818"
CELERY_BROKER_URL = "amqp://rabbitmq" CELERY_BROKER_URL = "amqp://rabbitmq"