# -*- encoding: utf-8 -*-
""" Django settings """
import os
from django.core.exceptions import ImproperlyConfigured
from django.urls import reverse_lazy
[docs]def get_env_variable(key):
"""
Get the environment variable or return exception
Copied from Django two scoops book
"""
try:
return os.environ[key]
except KeyError:
error_msg = "Set the {} env variable".format(key)
print("ImproperlyConfigured: {}".format(error_msg))
raise ImproperlyConfigured(error_msg)
DEBUG = True
TESTING = False
THUMBNAIL_DEBUG = DEBUG
SESSION_COOKIE_SECURE = False
CSRF_COOKIE_SECURE = False
ADMINS = (("admin", "code@pkimber.net"),)
MANAGERS = ADMINS
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = "Europe/London"
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = "en-gb"
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = False
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True
# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = "media"
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = "/media/"
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = "web_static/"
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = "/static/"
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
# Make this unique, and don't share it with anybody.
SECRET_KEY = "w@t8%tdwyi-n$u_s#4_+cwnq&6)1n)l3p-qe(ziala0j^vo12d"
MIDDLEWARE = (
"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",
"reversion.middleware.RevisionMiddleware",
)
ROOT_URLCONF = "example_checkout.urls"
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = "example_checkout.wsgi.application"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.contrib.auth.context_processors.auth",
"django.template.context_processors.debug",
"django.template.context_processors.i18n",
"django.template.context_processors.media",
"django.template.context_processors.request",
"django.template.context_processors.static",
"django.template.context_processors.tz",
"django.contrib.messages.context_processors.messages",
],
"string_if_invalid": "**** INVALID EXPRESSION: %s ****",
},
}
]
DJANGO_APPS = (
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
# admin after login, so we prefer login templates
"django.contrib.admin",
)
THIRD_PARTY_APPS = ("reversion", "taggit")
LOCAL_APPS = (
"base",
"checkout",
"contact",
"example_checkout",
"finance",
"login",
"mail",
"stock",
)
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"handlers": {
"file": {
"level": "DEBUG",
"class": "logging.FileHandler",
"filename": "logger.log",
}
},
"loggers": {
"": {"handlers": ["file"], "level": "DEBUG", "propagate": True}
},
}
# https://github.com/mbi/django-simple-captcha
CAPTCHA_LETTER_ROTATION = None
CAPTCHA_NOISE_FUNCTIONS = None
CAPTCHA_TEST_MODE = True
# Celery
BROKER_URL = "redis://localhost:6379/0"
CELERY_RESULT_BACKEND = "redis://localhost:6379/0"
# https://kfalck.net/2013/02/21/run-multiple-celeries-on-a-single-redis
CELERY_DEFAULT_QUEUE = "checkout"
# http://celery.readthedocs.org/en/latest/userguide/tasks.html#disable-rate-limits-if-they-re-not-used
CELERY_DISABLE_RATE_LIMITS = True
CONTACT_MODEL = "contact.Contact"
FTP_STATIC_DIR = None
FTP_STATIC_URL = None
# URL where requests are redirected after login when the contrib.auth.login
# view gets no next parameter.
LOGIN_REDIRECT_URL = reverse_lazy("project.dash")
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
# See the list of constants at the top of 'mail.models'
MAIL_TEMPLATE_TYPE = "django"
# Put in the example app for testing purposes only
MAILGUN_SERVER_NAME = get_env_variable("MAILGUN_SERVER_NAME")
# https://github.com/insttrack/django-recaptcha
# RECAPTCHA_PRIVATE_KEY = get_env_variable('RECAPTCHA_PRIVATE_KEY')
# RECAPTCHA_PUBLIC_KEY = get_env_variable('RECAPTCHA_PUBLIC_KEY')
# RECAPTCHA_USE_SSL = True
# https://github.com/johnsensible/django-sendfile
SENDFILE_BACKEND = "sendfile.backends.development"
SENDFILE_ROOT = "media-private"
# https://github.com/spookylukey/django-paypal
# PAYPAL_RECEIVER_EMAIL = get_env_variable('PAYPAL_RECEIVER_EMAIL')
# PAYPAL_TEST = True
# Stripe
STRIPE_CAPTION = "pkimber.net"
STRIPE_PUBLISH_KEY = get_env_variable("STRIPE_PUBLISH_KEY")
STRIPE_SECRET_KEY = get_env_variable("STRIPE_SECRET_KEY")