chore: clean code

This commit is contained in:
Ruidy Nemausat 2020-06-13 18:12:10 +02:00
parent f4f353a44c
commit e6235e72cc
20 changed files with 32 additions and 35 deletions

View file

@ -1,4 +1,5 @@
from django.contrib import admin from django.contrib import admin
from rental.models.booking import Booking from rental.models.booking import Booking
from rental.models.contact import Contact from rental.models.contact import Contact
from rental.models.guest import Guest from rental.models.guest import Guest

View file

@ -3,6 +3,5 @@ from django.utils.translation import gettext_lazy as _
class PlaceNames(models.TextChoices): class PlaceNames(models.TextChoices):
T2 = "T2", _("T2") T2 = "T2", _("T2")
T3 = "T3", _("T3") T3 = "T3", _("T3")

View file

@ -1,4 +1,5 @@
from django import forms from django import forms
from rental.models.booking import Booking from rental.models.booking import Booking
from rental.models.place import Place from rental.models.place import Place
from rental.enums import PlaceNames from rental.enums import PlaceNames
@ -45,7 +46,6 @@ class BookingForm(forms.Form):
message = forms.CharField( message = forms.CharField(
label='', label='',
# max_length=100,
min_length=4, min_length=4,
widget=forms.Textarea(attrs={ widget=forms.Textarea(attrs={
'class': 'form-control', 'class': 'form-control',
@ -58,8 +58,6 @@ class BookingForm(forms.Form):
start = forms.DateField( start = forms.DateField(
label='', label='',
input_formats=['%d/%m/%Y'], input_formats=['%d/%m/%Y'],
# max_length=100,
# min_length=4,
widget=forms.DateInput(attrs={ widget=forms.DateInput(attrs={
'class': 'form-control form-control-lg form-control-a', 'class': 'form-control form-control-lg form-control-a',
'placeholder': '01/01/2020 *'}), 'placeholder': '01/01/2020 *'}),

View file

@ -34,7 +34,6 @@ class ContactForm(forms.Form):
message = forms.CharField( message = forms.CharField(
label='', label='',
# max_length=100,
min_length=4, min_length=4,
widget=forms.Textarea(attrs={ widget=forms.Textarea(attrs={
'class': 'form-control', 'class': 'form-control',

View file

@ -1,5 +1,6 @@
from datetime import datetime 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
import rental.services.calendar as calendar import rental.services.calendar as calendar

View file

@ -1,4 +1,5 @@
from django.db import models from django.db import models
import rental.tasks.apiMailer as mailer # or gMailer import rental.tasks.apiMailer as mailer # or gMailer

View file

@ -1,7 +1,6 @@
from django.db import models from django.db import models
class Guest(models.Model): class Guest(models.Model):
class Meta: class Meta:
verbose_name = "Voyageur" verbose_name = "Voyageur"

View file

@ -1,4 +1,5 @@
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 import rental.services.calendar as calendar

View file

@ -1,4 +1,5 @@
from django.db import models from django.db import models
from rental.models.booking import Booking from rental.models.booking import Booking
from rental.models.guest import Guest from rental.models.guest import Guest

View file

@ -1,11 +1,13 @@
import datetime import datetime
import os
import pickle
from google.auth.transport.requests import Request from google.auth.transport.requests import Request
from google_auth_oauthlib.flow import InstalledAppFlow, Flow from google_auth_oauthlib.flow import InstalledAppFlow, Flow
from googleapiclient.discovery import build from googleapiclient.discovery import build
import os
import pickle
from villafleurie.settings import BASE_DIR
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from villafleurie.settings import BASE_DIR
from rental.models.guest import Guest from rental.models.guest import Guest
import rental.models.place as m_place import rental.models.place as m_place
import rental.models.booking as m_booking import rental.models.booking as m_booking
@ -31,13 +33,8 @@ def build_service():
else: else:
SECRETS = os.path.join(BASE_DIR, 'rental/client_secrets.json') SECRETS = os.path.join(BASE_DIR, 'rental/client_secrets.json')
flow = InstalledAppFlow.from_client_secrets_file( flow = InstalledAppFlow.from_client_secrets_file(
# flow = Flow.from_client_secrets_file(
SECRETS, scopes=SCOPES, redirect_uri="http://localhost:8080/") SECRETS, scopes=SCOPES, redirect_uri="http://localhost:8080/")
creds = flow.run_local_server() creds = flow.run_local_server()
# creds = flow.run_console()
# auth_url, _ = flow.authorization_url(prompt='consent')
# print(auth_url)
with open('token.pickle', 'wb') as token: with open('token.pickle', 'wb') as token:
pickle.dump(creds, token) pickle.dump(creds, token)
@ -108,7 +105,7 @@ def synchronize(place):
db_booking.guest = guest, db_booking.guest = guest,
db_booking.start = start, db_booking.start = start,
db_booking.end = end db_booking.end = end
# db_booking.price = price
def get_bookings_from_db(place): def get_bookings_from_db(place):
@ -135,6 +132,7 @@ def check_availability(place, start_date, end_date):
def update(reservation): def update(reservation):
""" push new reservation to master calendar """ """ push new reservation to master calendar """
# authenticate and build service # authenticate and build service
service, calendars = build_service() service, calendars = build_service()
start = reservation.start.strftime('%Y-%m-%d') start = reservation.start.strftime('%Y-%m-%d')
end = reservation.end.strftime('%Y-%m-%d') end = reservation.end.strftime('%Y-%m-%d')

View file

@ -1,7 +1,9 @@
from __future__ import absolute_import, unicode_literals from __future__ import absolute_import, unicode_literals
from datetime import datetime from datetime import datetime
import requests
from celery import shared_task from celery import shared_task
import requests
from villafleurie.settings import EMAIL_HOST_USER, DEFAULT_FROM_EMAIL from villafleurie.settings import EMAIL_HOST_USER, DEFAULT_FROM_EMAIL
""" Mailer Service used to send messages using API WebHooks. """ Mailer Service used to send messages using API WebHooks.
@ -12,7 +14,7 @@ from villafleurie.settings import EMAIL_HOST_USER, DEFAULT_FROM_EMAIL
def send_notification(name, email, subject, message)->void def send_notification(name, email, subject, message)->void
def send_quotation(name, email)->void def send_quotation(name, email)->void
""" """
URL = "https://hooks.zapier.com/hooks/catch/4071838/o93celz/" URL = "https://hooks.zapier.com/hooks/catch/4071838/o93celz/"
@ -30,8 +32,7 @@ def send_confirmation(name, email):
} }
resp = requests.post(URL, data=payload) resp = requests.post(URL, data=payload)
print(resp.text)
print(resp.json)
@shared_task @shared_task

View file

@ -1,6 +1,8 @@
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 villafleurie.settings import EMAIL_HOST_USER from villafleurie.settings import EMAIL_HOST_USER
@ -20,34 +22,26 @@ def send_confirmation(name, email):
""" 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 !" message = f" Merci {name}, Bien reçu nous revenons vers vous rapidement !"
# html_path = os.path.join(BASE_DIR, 'rental/templates/rental/mails/')
# with open(os.path.join(html_path, f"{template}.html"), 'r') as html:
# html_message = html.read()
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
) )
@shared_task @shared_task
def send_notification(name, email, subject, message): def send_notification(name, email, subject, message):
""" Send notification to admins """ """ Send notification to admins """
# html_path = os.path.join(BASE_DIR, 'rental/templates/rental/mails/')
# with open(os.path.join(html_path, f"{template}.html"), 'r') as html:
# html_message = html.read()
mail_admins( mail_admins(
f"{name} a envoyé un message", f"{name} a envoyé un message",
f"Sujet : {subject}\nDe : {name}, {email}\nMessage : {message}" f"Sujet : {subject}\nDe : {name}, {email}\nMessage : {message}"
# html_message=html_message
) )
@shared_task @shared_task
def send_quotation(name, email): def send_quotation(name, email):
""" Send quotation to customer """ """ Send quotation to customer """
send_confirmation_mail(name, email) # : , template="welcome") send_confirmation_mail(name, email)

View file

@ -1,6 +1,8 @@
from datetime import datetime from datetime import datetime
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from django.test import TestCase from django.test import TestCase
from rental.models.place import Place from rental.models.place import Place
from rental.models.booking import Booking from rental.models.booking import Booking
from rental.models.guest import Guest from rental.models.guest import Guest
@ -23,7 +25,6 @@ class BookingTestCase(TestCase):
self.end = datetime(2019, 11, 20) self.end = datetime(2019, 11, 20)
def test_BookingPrice(self): def test_BookingPrice(self):
# place = Place.objects.get(name='TX')
booking = Booking.objects.create_booking( booking = Booking.objects.create_booking(
place=self.place, place=self.place,
start=self.start, start=self.start,

View file

@ -1,11 +1,9 @@
from django.test import TestCase from django.test import TestCase
import rental.services.calendar as calendar import rental.services.calendar as calendar
class CalendarTestCase(TestCase): class CalendarTestCase(TestCase):
def setUp(self):
pass
def test_CalendarBuild(self): def test_CalendarBuild(self):
obj = calendar.build_service() obj = calendar.build_service()
print(obj)

View file

@ -1,5 +1,6 @@
from django.contrib.staticfiles.urls import static, staticfiles_urlpatterns from django.contrib.staticfiles.urls import static, staticfiles_urlpatterns
from django.urls import path from django.urls import path
from villafleurie import settings from villafleurie import settings
from rental.views import home, booking, contact, place from rental.views import home, booking, contact, place

View file

@ -2,6 +2,7 @@ from django.core.exceptions import ValidationError
from django.db import IntegrityError from django.db import IntegrityError
from django.shortcuts import render, get_object_or_404 from django.shortcuts import render, get_object_or_404
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from rental.forms.booking import BookingForm from rental.forms.booking import BookingForm
from rental.models.booking import Booking from rental.models.booking import Booking
from rental.models.guest import Guest from rental.models.guest import Guest

View file

@ -1,4 +1,5 @@
from django.shortcuts import render from django.shortcuts import render
from rental.forms.contact import ContactForm from rental.forms.contact import ContactForm
from rental.models.contact import Contact from rental.models.contact import Contact

View file

@ -1,5 +1,6 @@
from django.shortcuts import render, get_object_or_404 from django.shortcuts import render, get_object_or_404
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
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.views.booking import handle_booking_form from rental.views.booking import handle_booking_form

View file

@ -11,4 +11,4 @@ app.autodiscover_tasks()
@app.task(bind=True) @app.task(bind=True)
def debug_task(self): def debug_task(self):
print('Request: {0!r}'.format(self.request)) print(f'Request: {self.request!r}')

View file

@ -1,5 +1,6 @@
import os import os
from django.core.wsgi import get_wsgi_application from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'villafleurie.settings') os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'villafleurie.settings')
application = get_wsgi_application() application = get_wsgi_application()