Refactor (#7)

* crete setting module to split prod and dev configs

* fix calendar midmatch

* lint imports using isort

* doc: add doctrings
This commit is contained in:
Ruidy 2020-07-31 08:02:10 +02:00 committed by GitHub
parent a91914a640
commit 780188e7d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
38 changed files with 328 additions and 270 deletions

View file

@ -1,3 +1,5 @@
""" Register models and configure admin dashboard """
from django.contrib import admin
from rental.models.booking import Booking
@ -7,7 +9,6 @@ from rental.models.picture import Picture
from rental.models.place import Place
from rental.models.testimonial import Testimonial
admin.site.register(Booking)
admin.site.register(Guest)
admin.site.register(Place)

View file

@ -3,5 +3,8 @@ from django.utils.translation import gettext_lazy as _
class PlaceNames(models.TextChoices):
""" PlaceNames enums serve to list places and prepare
for internationalisation
"""
T2 = "T2", _("T2")
T3 = "T3", _("T3")

View file

@ -1,11 +1,13 @@
from django import forms
from rental.models.booking import Booking
from rental.models.place import Place
from rental.enums import PlaceNames
class BookingForm(forms.Form):
"""
BookingForm serve to validate input and create a new booking.
doc: https://docs.djangoproject.com/fr/2.2/topics/forms/modelforms/
"""
name = forms.CharField(
label="",

View file

@ -1,9 +1,11 @@
from django import forms
from rental.models.contact import Contact
from rental.models.place import Place
class ContactForm(forms.Form):
"""
ContactForm serve to validate input and create a new contact.
doc: https://docs.djangoproject.com/fr/2.2/topics/forms/modelforms/
"""
name = forms.CharField(
label='',

View file

@ -1,7 +1,7 @@
# Generated by Django 2.2.6 on 2019-11-06 11:50
from django.db import migrations, models
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):

View file

@ -1,7 +1,7 @@
# Generated by Django 2.2.6 on 2019-11-07 21:14
from django.db import migrations, models
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):

View file

@ -1,7 +1,7 @@
# Generated by Django 2.2.6 on 2019-11-07 21:16
from django.db import migrations, models
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):

View file

@ -1,7 +1,7 @@
# Generated by Django 2.2.6 on 2019-11-10 18:14
from django.db import migrations, models
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):

View file

@ -1,7 +1,7 @@
# Generated by Django 2.2.6 on 2019-11-10 18:17
from django.db import migrations, models
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):

View file

@ -1,7 +1,7 @@
# Generated by Django 2.2.6 on 2019-11-11 08:55
from django.db import migrations, models
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):

View file

@ -1,7 +1,7 @@
# Generated by Django 2.2.6 on 2019-11-11 10:20
from django.db import migrations, models
import django.utils.timezone
from django.db import migrations, models
class Migration(migrations.Migration):

View file

@ -1,7 +1,7 @@
# Generated by Django 2.2.6 on 2019-11-11 11:12
from django.db import migrations, models
import django.utils.timezone
from django.db import migrations, models
class Migration(migrations.Migration):

View file

@ -1,7 +1,7 @@
# Generated by Django 2.2.6 on 2019-11-11 12:11
from django.db import migrations, models
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):

View file

@ -1,27 +1,35 @@
from datetime import datetime
from django.db import models
import rental.services.calendar as calendar
import rental.tasks.api_mailer as mailer # or g_mailer
from rental.models.guest import Guest
from rental.models.place import Place
import rental.services.calendar as calendar
import rental.tasks.apiMailer as mailer # or gMailer
class BookingManager(models.Manager):
""" BookingManager is the interface through which database query operations
are provided to Django models.
"""
BookingManager is the interface through which database query operations
are provided to Django models.
"""
def create_booking(self, **kwargs):
""" create_booking creates a Booking instance, computes the price and
updates the remote calendar. """
"""
Create_booking creates a Booking instance, computes the price and
updates the remote calendar.
"""
booking = self.create(**kwargs)
booking.price = booking.get_price()
calendar.update(booking)
return booking
class Booking(models.Model):
""" Booking encapsulate booking instance information """
class Meta:
verbose_name = 'Réservation'
@ -38,15 +46,17 @@ class Booking(models.Model):
price = models.DecimalField(max_digits=6, decimal_places=2, null=True)
def get_price(self):
""" Compute booking price as a function of place and dates """
""" Compute booking price as a function of place and dates. """
if type(self.start) == str:
if isinstance(self.start, str):
self.start = datetime.strptime(self.start, '%Y-%m-%d')
if type(self.end) == str:
if isinstance(self.end, str):
self.end = datetime.strptime(self.end, '%Y-%m-%d')
nights = (self.end - self.start).days
return self.place.price * nights
def send_quotation(self):
""" Notify user of booking details """
mailer.send_quotation.delay(self.guest.name, self.guest.email)

View file

@ -1,9 +1,12 @@
from django.db import models
import rental.tasks.apiMailer as mailer # or gMailer
import rental.tasks.api_mailer as mailer # or g_mailer
class Contact(models.Model):
"""
Contact encapsulates communication with a customer.
"""
def __str__(self):
return f"Message de {self.name}, le {self.date}"
@ -15,9 +18,13 @@ class Contact(models.Model):
date = models.DateTimeField(auto_now_add=True)
def send_confirmation(self):
""" Notify that the message has been succesfully sent. """
mailer.send_confirmation.delay(self.name, self.email)
def send_notification(self):
""" Notify admins that a message has been sent. """
mailer.send_notification.delay(
self.name,
self.email,

View file

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

View file

@ -2,6 +2,8 @@ from django.db import models
class Picture(models.Model):
""" Picture manages media and set alt tags. """
def __str__(self):
return self.alt

View file

@ -1,10 +1,12 @@
from django.db import models
from rental.models.picture import Picture
import rental.services.calendar as calendar
from rental.models.picture import Picture
class Place(models.Model):
"""Place encapsulates a loaction information."""
class Meta:
verbose_name = "Appartement"
@ -21,9 +23,12 @@ class Place(models.Model):
beds = models.IntegerField(null=True, blank=True)
max_occupation = models.IntegerField(null=True, blank=True)
thumbnail = models.ForeignKey(
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)
calendar = models.CharField(max_length=350, blank=True, null=True)
def is_available(self, start, end):
"""Check weither a location is available at a given time period."""
return calendar.check_availability(self, start, end)

View file

@ -5,6 +5,8 @@ from rental.models.guest import Guest
class Testimonial(models.Model):
"""Testimonial represent a past customer testimony."""
class Meta:
verbose_name = "Témoignage"
@ -14,9 +16,12 @@ class Testimonial(models.Model):
author = models.CharField(max_length=200)
text = models.TextField(max_length=1000)
picture = models.ImageField(
max_length=200, upload_to='img/', null=True, blank=True)
max_length=200, upload_to='img/', null=True, blank=True
)
link = models.URLField(max_length=200, null=True, blank=True)
guest = models.OneToOneField(
Guest, on_delete=models.CASCADE, blank=True, null=True)
Guest, on_delete=models.CASCADE, blank=True, null=True
)
reservation = models.OneToOneField(
Booking, on_delete=models.CASCADE, blank=True, null=True)
Booking, on_delete=models.CASCADE, blank=True, null=True
)

View file

@ -1,17 +1,17 @@
import datetime
import os
import logging
import os
import pickle
from google.auth.transport.requests import Request
from google_auth_oauthlib.flow import InstalledAppFlow, Flow
from googleapiclient.discovery import build
from django.shortcuts import get_object_or_404
from google.auth.transport.requests import Request
from google_auth_oauthlib.flow import Flow, InstalledAppFlow
from googleapiclient.discovery import build
from villafleurie.settings import BASE_DIR
from rental.models.guest import Guest
import rental.models.place as m_place
import rental.models.booking as m_booking
import rental.models.place as m_place
from rental.models.guest import Guest
from villafleurie.settings import BASE_DIR
def build_service():

View file

@ -1,32 +0,0 @@
document.addEventListener("DOMContentLoaded", () => {
const calendarEl = document.getElementById("calendar");
const calendar = new FullCalendar.Calendar(calendarEl, {
headerToolbar: {
left: "prev,next",
right: "title",
},
locale: "fr",
firstDay: 1, // week start on Monday
displayEventTime: false, // don't show the time column in list view
googleCalendarApiKey: "AIzaSyC2Wcg2Q2sq071w_L6k5JfHnPptlseU16g",
events: {
googleCalendarId:
"burik7aclvhc7vsboh06c179uo@group.calendar.google.com",
},
// eventColor: "#378006",
contentHeight: "auto",
// don't navigate in main tab
eventClick: (arg) => {
arg.jsEvent.preventDefault();
},
themeSystem: "bootstrap",
loading: (bool) => {
document.getElementById("loading").style.display = bool
? "block"
: "none";
},
});
calendar.render();
});

View file

@ -1,11 +1,3 @@
from __future__ import absolute_import, unicode_literals
from datetime import datetime
from celery import shared_task
import requests
from villafleurie.settings import EMAIL_HOST_USER, DEFAULT_FROM_EMAIL
""" Mailer Service used to send messages using API WebHooks.
All Mailers must implement the following methods:
@ -16,7 +8,18 @@ from villafleurie.settings import EMAIL_HOST_USER, DEFAULT_FROM_EMAIL
def send_quotation(name, email)->void
"""
URL = "https://hooks.zapier.com/hooks/catch/4071838/o93celz/"
from __future__ import absolute_import, unicode_literals
from datetime import datetime
import os
import requests
from celery import shared_task
from villafleurie.settings import DEFAULT_FROM_EMAIL, EMAIL_HOST_USER
# get mailing hook URL from env
URL = os.environ.get("MAIL_HOOK")
@shared_task
@ -31,8 +34,7 @@ def send_confirmation(name, email):
"body": f"Merci {name}, nous avons bien reçu votre message, nous revenons vers vous rapidement !\nCordialement,\nNilka (VillaFleurie)"
}
resp = requests.post(URL, data=payload)
requests.post(URL, data=payload)
@shared_task
@ -47,12 +49,12 @@ def send_notification(name, email, subject, message, date):
"body": f"Sujet : {subject}\nDe : {name}, {email}\nLe : {date}\nMessage : {message}\nCordialement,\nNilka (VillaFleurie)"
}
resp = requests.post(URL, data=payload)
requests.post(URL, data=payload)
@shared_task
def send_quotation(name, email):
""" Send quotation to customer """
""" Notify admins then send quotation to customer """
send_notification(
name,

View file

@ -1,11 +1,3 @@
from __future__ import absolute_import, unicode_literals
from celery import shared_task
from django.core.mail import send_mail, mail_admins
from villafleurie.settings import EMAIL_HOST_USER
""" Mailer Service used to send messages using Gmail.
All Mailers must implement the following methods:
@ -14,12 +6,20 @@ from villafleurie.settings import EMAIL_HOST_USER
def send_notification(name, email, subject, message)->void
def send_quotation(name, email)->void
"""
"""
from __future__ import absolute_import, unicode_literals
from celery import shared_task
from django.core.mail import mail_admins, send_mail
from villafleurie.settings import EMAIL_HOST_USER
@shared_task
def send_confirmation(name, email):
""" Send confirmation message to customer """
subject = "Nous avons reçu votre message"
message = f" Merci {name}, Bien reçu nous revenons vers vous rapidement !"
@ -27,7 +27,7 @@ def send_confirmation(name, email):
subject,
message,
EMAIL_HOST_USER,
[email]
[email]
)
@ -44,4 +44,5 @@ def send_notification(name, email, subject, message):
@shared_task
def send_quotation(name, email):
""" Send quotation to customer """
send_confirmation_mail(name, email)
send_confirmation(name, email)

View file

@ -3,7 +3,6 @@
<link rel="stylesheet" href="{% static 'rental/lib/calendar/main.min.css' %}" />
<link rel="stylesheet" href="{% static 'rental/lib/calendar/style.css' %}" />
<script src="{% static 'rental/lib/calendar/main.min.js' %}"></script>
<script src="{% static 'rental/lib/calendar/main.js' %}"></script>
<script src="{% static 'rental/lib/calendar/locales/fr.js' %}"></script>
<script>

View file

@ -3,9 +3,9 @@ from datetime import datetime
from django.shortcuts import get_object_or_404
from django.test import TestCase
from rental.models.place import Place
from rental.models.booking import Booking
from rental.models.guest import Guest
from rental.models.place import Place
class BookingTestCase(TestCase):

View file

@ -1,9 +1,10 @@
""" URLs specifi to rental application """
from django.contrib.staticfiles.urls import static, staticfiles_urlpatterns
from django.urls import path
from rental.views import booking, contact, home, place
from villafleurie import settings
from rental.views import home, booking, contact, place
app_name = 'rental'
@ -19,7 +20,7 @@ urlpatterns = [
path('', place.index, name='index'),
path('hebergements/', place.all, name='list_place'),
path('<place_name>/', place.view, name='detail_place')
path('<slug:place_name>/', place.view, name='detail_place')
]
urlpatterns += staticfiles_urlpatterns()

View file

@ -1,6 +1,6 @@
from django.core.exceptions import ValidationError
from django.db import IntegrityError
from django.shortcuts import render, get_object_or_404
from django.shortcuts import get_object_or_404, render
from django.utils.translation import gettext_lazy as _
from rental.forms.booking import BookingForm
@ -10,12 +10,15 @@ from rental.models.place import Place
def view(request):
"""Return initial booking form."""
context, template = handle_booking_form(request)
return render(request, template, context)
def handle_booking_form(request, context={}, init_template='rental/reservation.html'):
"""Validates form and checks if place availability a given period."""
if request.method == 'POST':
form = BookingForm(request.POST)
if form.is_valid():
@ -56,17 +59,18 @@ def handle_booking_form(request, context={}, init_template='rental/reservation.h
}
template = 'rental/merci.html'
return context, template
else:
form.add_error(None, ValidationError(
_("Cet hébergement n'est pas disponible aux dates indiquées."),
code='invalid'
))
context = {'form': form}
template = 'rental/reservation.html'
return context, template
form.add_error(None, ValidationError(
_("Cet hébergement n'est pas disponible aux dates indiquées."),
code='invalid'
))
context = {'form': form}
template = 'rental/reservation.html'
return context, template
except IntegrityError:
form.errors['internal'] = "Une erreur interne est apparue. Merci de recommencer votre requête."
form.errors['internal'] = """Une erreur interne est apparue.
Merci de recommencer votre requête."""
else:
form = BookingForm()

View file

@ -5,6 +5,8 @@ from rental.models.contact import Contact
def view(request):
"""Handle contactForm."""
if request.method == 'POST':
form = ContactForm(request.POST)
if form.is_valid():

View file

@ -1,9 +1,11 @@
from django.shortcuts import render
def handler404(request, exception):
def handler404(request, _):
"""handle 404 errors. Requires a request and an exception."""
return render(request, 'rental/404.html', status=404)
def handler500(request):
"""handle 500 errors."""
return render(request, 'rental/500.html', status=500)

View file

@ -1,5 +1,4 @@
from django.shortcuts import render, get_object_or_404
from django.utils.translation import gettext_lazy as _
from django.shortcuts import get_object_or_404, render
from rental.models.place import Place
from rental.models.testimonial import Testimonial
@ -7,6 +6,7 @@ from rental.views.booking import handle_booking_form
def index(request):
"""Display homePage."""
places = Place.objects.all()
temoignages = Testimonial.objects.all()
@ -19,6 +19,7 @@ def index(request):
def all(request):
"""Handle places list page."""
places = Place.objects.all()
context = {'places': places}
@ -27,6 +28,7 @@ def all(request):
def view(request, place_name='T2'):
"""Handle a specific place."""
place = get_object_or_404(Place, name=place_name)
images = place.images.all()

View file

@ -1,4 +1,5 @@
from __future__ import absolute_import, unicode_literals
from .celery import app as celery_app
__all__ = ('celery_app',)

View file

@ -1,7 +1,12 @@
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
""" Celery is a distributed task queue used for real-time processing of
asynchronous actions
"""
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'villafleurie.settings')
app = Celery('villafleurie')
@ -11,4 +16,5 @@ app.autodiscover_tasks()
@app.task(bind=True)
def debug_task(self):
""" Print request. For debug purposes only. """
print(f'Request: {self.request!r}')

View file

@ -1,153 +0,0 @@
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
ADMINS = [
("Ruidy", "ruidy.nemausat@gmail.com"),
("VillaFleurie", "location.villafleurie@gmail.com")
]
SECRET_KEY = os.environ.get('SECRET_KEY')
if os.environ.get('ENV') == 'PRODUCTION':
DEBUG = False
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'villafleurie',
'USER': 'villafleurie',
'PASSWORD': os.environ.get("PASSWORD"),
'HOST': 'db',
'PORT': '5432',
'ATOMIC_REQUESTS': True
}
}
ALLOWED_HOSTS = [os.environ.get('ALLOWED_HOSTS')]
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
# CSRF_COOKIE_SECURE = True
# SESSION_COOKIE_SECURE = True
CONN_MAX_AGE = 500
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': os.path.join(BASE_DIR, "debug.log")
},
},
'loggers': {
'django': {
'handlers': ['file'],
'level': 'DEBUG',
'propagate': True,
},
},
}
else:
SECRET_KEY = "not_so_secret_key"
DEBUG = True
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'villafleurie',
'USER': 'nemausat',
'PASSWORD': '',
'HOST': '',
# 'NAME': 'postgres',
# 'USER': 'postgres',
# 'HOST': 'db',
# 'PORT': '5432',
'ATOMIC_REQUESTS': True
}
}
STATICFILES_DIRS = [os.path.join(BASE_DIR, "rental", "static", "rental"), ]
ALLOWED_HOSTS = [
'127.0.0.1',
'localhost'
]
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rental.apps.RentalConfig'
]
SITE_ID = 1
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware'
]
INTERNAL_IPS = ['127.0.0.1']
ROOT_URLCONF = 'villafleurie.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': False,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
'loaders': [
('django.template.loaders.cached.Loader', [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
]),
],
},
},
]
WSGI_APPLICATION = 'villafleurie.wsgi.application'
AUTH_PASSWORD_VALIDATORS = [
{'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', },
{'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', },
{'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', },
{'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', },
]
LANGUAGE_CODE = 'fr'
TIME_ZONE = 'America/Guadeloupe'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'
STATIC_ROOT = "/static_files/"
MEDIA_URL = '/media/'
MEDIA_ROOT = '/media/'
EMAIL_HOST = "smtp.gmail.com"
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_SUBJECT_PREFIX = "[VillaFleurieGuadeloupe] "
DEFAULT_FROM_EMAIL = "'Nilka, VillaFleurie' <location.villaFleurie@gmail.com>"
EMAIL_HOST_USER = os.environ.get('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD')
CELERY_BROKER_URL = "amqp://rabbitmq"

View file

@ -0,0 +1,6 @@
import os
if os.environ.get('ENV') == 'PRODUCTION':
from .production import *
else:
from .development import *

View file

@ -0,0 +1,69 @@
""" Standard setting file to be imported by specific configurations """
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rental.apps.RentalConfig'
]
SITE_ID = 1
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware'
]
INTERNAL_IPS = ['127.0.0.1']
ROOT_URLCONF = 'villafleurie.urls'
WSGI_APPLICATION = 'villafleurie.wsgi.application'
AUTH_PASSWORD_VALIDATORS = [
{'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator'},
{'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator'},
{'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator'},
{'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator'}
]
# localisation, accessibility
LANGUAGE_CODE = 'fr'
TIME_ZONE = 'America/Guadeloupe'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# static files
STATIC_URL = '/static/'
STATIC_ROOT = "/static_files/"
MEDIA_URL = '/media/'
MEDIA_ROOT = '/media/'
# Email settings
ADMINS = [
("Ruidy", "ruidy.nemausat@gmail.com"),
("VillaFleurie", "location.villafleurie@gmail.com")
]
EMAIL_HOST = "smtp.gmail.com"
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_SUBJECT_PREFIX = "[VillaFleurieGuadeloupe] "
DEFAULT_FROM_EMAIL = "'Nilka, VillaFleurie' <location.villaFleurie@gmail.com>"
EMAIL_HOST_USER = os.environ.get('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD')
CELERY_BROKER_URL = "amqp://rabbitmq"

View file

@ -0,0 +1,46 @@
""" Settings to be used in development """
import os
from .base import *
SECRET_KEY = "not_so_secret_key"
DEBUG = True
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'villafleurie',
'USER': 'nemausat',
'PASSWORD': '',
'HOST': '',
# 'NAME': 'postgres',
# 'USER': 'postgres',
# 'HOST': 'db',
# 'PORT': '5432',
'ATOMIC_REQUESTS': True
}
}
STATICFILES_DIRS = [os.path.join(BASE_DIR, "rental", "static", "rental"), ]
ALLOWED_HOSTS = [
'127.0.0.1',
'localhost'
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'templates')
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

View file

@ -0,0 +1,65 @@
""" Settings to be used in production """
import os
from .base import *
DEBUG = False
SECRET_KEY = os.environ.get('SECRET_KEY')
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'villafleurie',
'USER': 'villafleurie',
'PASSWORD': os.environ.get("PASSWORD"),
'HOST': 'db',
'PORT': '5432',
'ATOMIC_REQUESTS': True
}
}
ALLOWED_HOSTS = [os.environ.get('ALLOWED_HOSTS')]
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
# CSRF_COOKIE_SECURE = True
# SESSION_COOKIE_SECURE = True
CONN_MAX_AGE = 500
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': os.path.join(BASE_DIR, "debug.log")
},
},
'loggers': {
'django': {
'handlers': ['file'],
'level': 'DEBUG',
'propagate': True,
},
},
}
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': False,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
'loaders': [
('django.template.loaders.cached.Loader', [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
]),
],
},
},
]

View file

@ -1,11 +1,10 @@
from django.conf.urls import include
from django.contrib import admin
from django.urls import path
from django.conf import settings
from django.conf.urls import include, url
urlpatterns = [
path('admin/', admin.site.urls),
# change admin path for security purposes
path('dashboard/', admin.site.urls),
path('', include('rental.urls', namespace='rental'))
]