- !88 pytest on existing tests - !89 reorganise settings (! see notes for deployment) Co-authored-by: bkfox <thomas bkfox net> Reviewed-on: #92
This commit is contained in:
0
instance/settings/__init__.py
Normal file
0
instance/settings/__init__.py
Normal file
256
instance/settings/base.py
Executable file
256
instance/settings/base.py
Executable file
@ -0,0 +1,256 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
import pytz
|
||||
from django.utils import timezone
|
||||
|
||||
sys.path.insert(1, os.path.dirname(os.path.realpath(__file__)))
|
||||
|
||||
# Project root directory
|
||||
PROJECT_ROOT = os.path.abspath(__file__ + "/../../../")
|
||||
|
||||
# DEBUG mode
|
||||
DEBUG = (
|
||||
(os.environ["AIRCOX_DEBUG"].lower() in ("true", 1))
|
||||
if "AIRCOX_DEBUG" in os.environ
|
||||
else False
|
||||
)
|
||||
|
||||
# Internationalization and timezones: thoses values may be set in order to
|
||||
# have correct translation and timezone.
|
||||
|
||||
# Current language code. e.g. 'fr_BE'
|
||||
LANGUAGE_CODE = "en-US"
|
||||
# Locale
|
||||
LC_LOCALE = "en_US.UTF-8"
|
||||
# Current timezone. e.g. 'Europe/Brussels'
|
||||
TIME_ZONE = os.environ.get("TZ") or "UTC"
|
||||
|
||||
|
||||
# Secret key: you MUST put a consistent secret key. You can generate one
|
||||
# at https://djecrety.ir/
|
||||
SECRET_KEY = ""
|
||||
|
||||
# Database configuration
|
||||
DATABASES = {
|
||||
"default": {
|
||||
"ENGINE": "django.db.backends.sqlite3",
|
||||
"NAME": os.path.join(PROJECT_ROOT, "db.sqlite3"),
|
||||
"TIMEZONE": TIME_ZONE,
|
||||
}
|
||||
}
|
||||
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
||||
|
||||
# Allowed host for HTTP requests
|
||||
ALLOWED_HOSTS = ("127.0.0.1",)
|
||||
|
||||
|
||||
# Assets and medias:
|
||||
# In production, user MUST configure webserver in order to serve static
|
||||
# and media files.
|
||||
|
||||
# Website's path to statics assets
|
||||
STATIC_URL = "/static/"
|
||||
# Website's path to medias (uploaded images, etc.)
|
||||
MEDIA_URL = "/media/"
|
||||
# Website URL path to medias (uploaded images, etc.)
|
||||
SITE_MEDIA_URL = "/media/"
|
||||
# Path to assets' directory (by default in project's directory)
|
||||
STATIC_ROOT = os.path.join(PROJECT_ROOT, "static")
|
||||
# Path to media directory (by default in static's directory)
|
||||
MEDIA_ROOT = os.path.join(STATIC_ROOT, "media")
|
||||
|
||||
# Enables internationalization and timezone
|
||||
USE_I18N = True
|
||||
USE_L10N = True
|
||||
USE_TZ = True
|
||||
|
||||
timezone.activate(pytz.timezone(TIME_ZONE))
|
||||
|
||||
try:
|
||||
import locale
|
||||
|
||||
locale.setlocale(locale.LC_ALL, LC_LOCALE)
|
||||
except Exception:
|
||||
print(
|
||||
"Can not set locale {LC}. Is it available on you system? Hint: "
|
||||
"Check /etc/locale.gen and rerun locale-gen as sudo if needed.".format(
|
||||
LC=LANGUAGE_CODE
|
||||
)
|
||||
)
|
||||
pass
|
||||
|
||||
# -- django-taggit
|
||||
TAGGIT_CASE_INSENSITIVE = True
|
||||
|
||||
# -- django-CKEditor
|
||||
CKEDITOR_CONFIGS = {
|
||||
"default": {
|
||||
"format_tags": "h1;h2;h3;p;pre",
|
||||
# 'skin': 'office2013',
|
||||
"toolbar_Custom": [
|
||||
{
|
||||
"name": "editing",
|
||||
"items": [
|
||||
"Undo",
|
||||
"Redo",
|
||||
"-",
|
||||
"Find",
|
||||
"Replace",
|
||||
"-",
|
||||
"Source",
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "basicstyles",
|
||||
"items": [
|
||||
"Bold",
|
||||
"Italic",
|
||||
"Underline",
|
||||
"Strike",
|
||||
"Subscript",
|
||||
"Superscript",
|
||||
"-",
|
||||
"RemoveFormat",
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "paragraph",
|
||||
"items": [
|
||||
"NumberedList",
|
||||
"BulletedList",
|
||||
"-",
|
||||
"Outdent",
|
||||
"Indent",
|
||||
"-",
|
||||
"Blockquote",
|
||||
"CreateDiv",
|
||||
"-",
|
||||
"JustifyLeft",
|
||||
"JustifyCenter",
|
||||
"JustifyRight",
|
||||
"JustifyBlock",
|
||||
"-",
|
||||
],
|
||||
},
|
||||
"/",
|
||||
{"name": "links", "items": ["Link", "Unlink", "Anchor"]},
|
||||
{
|
||||
"name": "insert",
|
||||
"items": [
|
||||
"Image",
|
||||
"Table",
|
||||
"HorizontalRule",
|
||||
"SpecialChar",
|
||||
"PageBreak",
|
||||
"Iframe",
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "styles",
|
||||
"items": ["Styles", "Format", "Font", "FontSize"],
|
||||
},
|
||||
{"name": "colors", "items": ["TextColor", "BGColor"]},
|
||||
"/", # put this to force next toolbar on new line
|
||||
],
|
||||
"toolbar": "Custom",
|
||||
"extraPlugins": ",".join(
|
||||
[
|
||||
"uploadimage",
|
||||
"div",
|
||||
"autolink",
|
||||
"autoembed",
|
||||
"embedsemantic",
|
||||
"embed",
|
||||
"iframe",
|
||||
"iframedialog",
|
||||
"autogrow",
|
||||
"widget",
|
||||
"lineutils",
|
||||
"dialog",
|
||||
"dialogui",
|
||||
"elementspath",
|
||||
]
|
||||
),
|
||||
},
|
||||
}
|
||||
CKEDITOR_UPLOAD_PATH = "uploads/"
|
||||
|
||||
|
||||
# -- easy_thumbnails
|
||||
THUMBNAIL_PROCESSORS = (
|
||||
"easy_thumbnails.processors.colorspace",
|
||||
"easy_thumbnails.processors.autocrop",
|
||||
#'easy_thumbnails.processors.scale_and_crop',
|
||||
"filer.thumbnail_processors.scale_and_crop_with_subject_location",
|
||||
"easy_thumbnails.processors.filters",
|
||||
)
|
||||
|
||||
|
||||
# Enabled applications
|
||||
INSTALLED_APPS = (
|
||||
"aircox.apps.AircoxConfig",
|
||||
"aircox.apps.AircoxAdminConfig",
|
||||
"aircox_streamer.apps.AircoxStreamerConfig",
|
||||
# Aircox dependencies
|
||||
"rest_framework",
|
||||
"django_filters",
|
||||
"content_editor",
|
||||
"ckeditor",
|
||||
"ckeditor_uploader",
|
||||
"easy_thumbnails",
|
||||
"filer",
|
||||
"taggit",
|
||||
"adminsortable2",
|
||||
"honeypot",
|
||||
# Django
|
||||
"django.contrib.contenttypes",
|
||||
"django.contrib.auth",
|
||||
"django.contrib.humanize",
|
||||
"django.contrib.sessions",
|
||||
"django.contrib.messages",
|
||||
"django.contrib.staticfiles",
|
||||
)
|
||||
|
||||
MIDDLEWARE = (
|
||||
"django.middleware.gzip.GZipMiddleware",
|
||||
"django.contrib.sessions.middleware.SessionMiddleware",
|
||||
"django.middleware.locale.LocaleMiddleware",
|
||||
"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",
|
||||
"aircox.middleware.AircoxMiddleware",
|
||||
)
|
||||
|
||||
|
||||
ROOT_URLCONF = "instance.urls"
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||
"DIRS": (os.path.join(PROJECT_ROOT, "templates"),),
|
||||
# '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",
|
||||
),
|
||||
"loaders": (
|
||||
"django.template.loaders.filesystem.Loader",
|
||||
"django.template.loaders.app_directories.Loader",
|
||||
),
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
WSGI_APPLICATION = "instance.wsgi.application"
|
42
instance/settings/dev.py
Executable file
42
instance/settings/dev.py
Executable file
@ -0,0 +1,42 @@
|
||||
import os
|
||||
|
||||
from .base import *
|
||||
|
||||
try:
|
||||
from .settings import *
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
LOCALE_PATHS = ["aircox/locale", "aircox_streamer/locale"]
|
||||
|
||||
LOGGING = {
|
||||
"version": 1,
|
||||
"disable_existing_loggers": False,
|
||||
"formatters": {
|
||||
"timestamp": {
|
||||
"format": "{asctime} {levelname} {message}",
|
||||
"style": "{",
|
||||
},
|
||||
},
|
||||
"handlers": {
|
||||
"console": {
|
||||
"class": "logging.StreamHandler",
|
||||
"formatter": "timestamp",
|
||||
},
|
||||
},
|
||||
"loggers": {
|
||||
"aircox": {
|
||||
"handlers": ["console"],
|
||||
"level": os.getenv("DJANGO_LOG_LEVEL", "DEBUG"),
|
||||
},
|
||||
"aircox.commands": {
|
||||
"handlers": ["console"],
|
||||
"level": os.getenv("DJANGO_LOG_LEVEL", "DEBUG"),
|
||||
},
|
||||
"aircox.test": {
|
||||
"handlers": ["console"],
|
||||
"level": os.getenv("DJANGO_LOG_LEVEL", "DEBUG"),
|
||||
},
|
||||
},
|
||||
}
|
46
instance/settings/prod.py
Executable file
46
instance/settings/prod.py
Executable file
@ -0,0 +1,46 @@
|
||||
import os
|
||||
|
||||
try:
|
||||
from .settings import *
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
LOGGING = {
|
||||
"version": 1,
|
||||
"disable_existing_loggers": False,
|
||||
"formatters": {
|
||||
"timestamp": {
|
||||
"format": "{asctime} {levelname} {message}",
|
||||
"style": "{",
|
||||
},
|
||||
},
|
||||
"handlers": {
|
||||
"console": {
|
||||
"class": "logging.StreamHandler",
|
||||
"formatter": "timestamp",
|
||||
},
|
||||
},
|
||||
"loggers": {
|
||||
"aircox": {
|
||||
"handlers": ["console"],
|
||||
"level": os.getenv("DJANGO_LOG_LEVEL", "INFO"),
|
||||
},
|
||||
"aircox.commands": {
|
||||
"handlers": ["console"],
|
||||
"level": os.getenv("DJANGO_LOG_LEVEL", "INFO"),
|
||||
},
|
||||
"aircox.test": {
|
||||
"handlers": ["console"],
|
||||
"level": os.getenv("DJANGO_LOG_LEVEL", "INFO"),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
# Enable caching using memcache
|
||||
CACHES = {
|
||||
"default": {
|
||||
"BACKEND": "django.core.cache.backends.memcached.MemcachedCache",
|
||||
"LOCATION": "127.0.0.1:11211",
|
||||
}
|
||||
}
|
43
instance/settings/sample.py
Normal file
43
instance/settings/sample.py
Normal file
@ -0,0 +1,43 @@
|
||||
"""Django and Aircox instance settings. This file should be saved as
|
||||
`settings.py` in the same directory as this one.
|
||||
|
||||
User MUST define the following values: `SECRET_KEY`, `ALLOWED_HOSTS`, `DATABASES`
|
||||
|
||||
The following environment variables are used in settings:
|
||||
* `AIRCOX_DEBUG` (`DEBUG`): enable/disable debugging
|
||||
|
||||
For Django settings see:
|
||||
https://docs.djangoproject.com/en/3.1/topics/settings/
|
||||
https://docs.djangoproject.com/en/3.1/ref/settings/
|
||||
"""
|
||||
|
||||
# Debug mode: set to True for dev
|
||||
# DEBUG = False
|
||||
LANGUAGE_CODE = "fr-BE"
|
||||
LC_LOCALE = "fr_BE.UTF-8"
|
||||
|
||||
# Secret key: you MUST put a consistent secret key. You can generate one
|
||||
# at https://djecrety.ir/
|
||||
SECRET_KEY = ""
|
||||
|
||||
# Database configuration: defaults to db.sqlite3
|
||||
# DATABASES
|
||||
|
||||
# Allowed host for HTTP requests
|
||||
# ALLOWED_HOSTS = ('127.0.0.1',)
|
||||
|
||||
|
||||
# When LC_LOCALE is set here, this code activates it.
|
||||
# Otherwise it can be removed
|
||||
try:
|
||||
import locale
|
||||
|
||||
locale.setlocale(locale.LC_ALL, LC_LOCALE)
|
||||
except Exception:
|
||||
print(
|
||||
"Can not set locale {LC}. Is it available on you system? Hint: "
|
||||
"Check /etc/locale.gen and rerun locale-gen as sudo if needed.".format(
|
||||
LC=LANGUAGE_CODE
|
||||
)
|
||||
)
|
||||
pass
|
Reference in New Issue
Block a user