JourneyJoker/urlaubsauktion/settings.py

230 lines
6.1 KiB
Python
Raw Permalink Normal View History

2021-02-05 07:01:45 +00:00
from pathlib import Path
2022-10-28 14:35:26 +00:00
import json
from autosecretkey import AutoSecretKey
2021-03-01 09:56:10 +00:00
2021-02-05 07:01:45 +00:00
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
2022-10-28 14:35:26 +00:00
CONFIG_FILE = AutoSecretKey(BASE_DIR / "config.ini", template=BASE_DIR / "config.dist.ini")
SECRET_KEY = CONFIG_FILE.secret_key
CONFIG = CONFIG_FILE.config
DEBUG = CONFIG["JOURNEYJOKER"]["Debug"]
# Domain configuration
ALLOWED_HOSTS = [host := CONFIG["JOURNEYJOKER"]["Host"]]
if host.startswith("www."):
ALLOWED_HOSTS.append(host[4:])
else:
ALLOWED_HOSTS.append(f"www.{host}")
CSRF_TRUSTED_ORIGINS = [f"https://{host}" for host in ALLOWED_HOSTS]
# Countries the app can be used in (currently no more than 5 due to Google Maps restrictions)
JOKER_COUNTRIES = json.loads(CONFIG["JOURNEYJOKER"]["Countries"])
# Currency to use
CURRENCY_SYMBOL = CONFIG["JOURNEYJOKER"]["CurrencySymbol"]
CURRENCY_CODE = CONFIG["JOURNEYJOKER"]["CurrencyCode"]
CURRENCY_NAME = CONFIG["JOURNEYJOKER"]["CurrencyName"]
2021-02-05 07:01:45 +00:00
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.gis',
'phonenumber_field',
2021-03-01 09:56:10 +00:00
'localauth',
'frontend',
'partners',
'payment',
'clients',
'dbsettings',
'auction',
'bootstrap4',
'django_countries',
'mathfilters',
2021-05-29 03:01:25 +00:00
'mail',
2021-05-30 06:03:05 +00:00
'gallery',
'django_starfield',
2021-02-05 07:01:45 +00:00
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
2021-02-05 07:01:45 +00:00
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'frontend.middleware.DemoMiddleware',
2021-02-05 07:01:45 +00:00
]
ROOT_URLCONF = 'urlaubsauktion.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR / "templates"],
2021-02-05 07:01:45 +00:00
'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',
'frontend.context_processors.demo',
2021-02-05 07:01:45 +00:00
],
},
},
]
WSGI_APPLICATION = 'urlaubsauktion.wsgi.application'
# Database
2022-10-28 14:35:26 +00:00
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
if "MySQL" in CONFIG_FILE.config:
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.mysql',
'NAME': CONFIG_FILE.config.get("MySQL", "Database"),
'USER': CONFIG_FILE.config.get("MySQL", "Username"),
'PASSWORD': CONFIG_FILE.config.get("MySQL", "Password"),
'HOST': CONFIG_FILE.config.get("MySQL", "Host", fallback="localhost"),
'PORT': CONFIG_FILE.config.getint("MySQL", "Port", fallback=3306),
'OPTIONS': {
'charset': 'utf8mb4',
'sql_mode': 'traditional',
}
}
}
else:
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.spatialite',
'NAME': BASE_DIR / 'db.sqlite3',
}
2021-02-05 07:01:45 +00:00
}
# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
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',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/
2021-03-23 18:23:04 +00:00
LANGUAGE_CODE = 'de'
2021-02-05 07:01:45 +00:00
2021-03-23 18:23:04 +00:00
TIME_ZONE = 'Europe/Vienna'
2021-02-05 07:01:45 +00:00
USE_I18N = True
USE_L10N = True
USE_TZ = True
LOCALE_PATHS = [
BASE_DIR / "locale",
]
LANGUAGES = [
('de', 'German'),
('en', 'English')
]
2021-02-05 07:01:45 +00:00
# Static files (CSS, JavaScript, Images)
2022-10-28 14:35:26 +00:00
# https://docs.djangoproject.com/en/4.0/howto/static-files/
STATIC_ROOT = None if DEBUG else CONFIG_FILE.config.get("JOURNEYJOKER", "StaticRoot", fallback=BASE_DIR / "webroot" / "static")
if "S3" in CONFIG_FILE.config:
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3StaticStorage'
AWS_ACCESS_KEY_ID = CONFIG_FILE.config.get("S3", "AccessKey")
AWS_SECRET_ACCESS_KEY = CONFIG_FILE.config.get("S3", "SecretKey")
AWS_STORAGE_BUCKET_NAME = CONFIG_FILE.config.get("S3", "Bucket")
AWS_S3_ENDPOINT_URL = CONFIG_FILE.config.get("S3", "Endpoint")
2021-02-05 07:01:45 +00:00
STATIC_URL = '/static/'
2021-03-01 09:56:10 +00:00
STATICFILES_DIRS = [
BASE_DIR / "static",
]
AUTH_USER_MODEL = "localauth.User"
REGISTER_REDIRECT_URL = "/"
LOGIN_REDIRECT_URL = "/"
2022-10-28 14:35:26 +00:00
LOGOUT_REDIRECT_URL = "/"
LOGIN_URL = "localauth:login"
LOGOUT_URL = "localauth:logout"
2022-10-28 14:35:26 +00:00
# Mail server settings
EMAIL_ENABLED = False
if "SMTP" in CONFIG:
EMAIL_ENABLED = True
EMAIL_HOST = CONFIG["SMTP"]["Host"]
EMAIL_PORT = CONFIG.get("SMTP", "Port", fallback=587)
EMAIL_HOST_USER = CONFIG.get("SMTP", "Username")
EMAIL_HOST_PASSWORD = CONFIG.get("SMTP", "Password")
EMAIL_USE_TLS = CONFIG.getboolean("SMTP", "TLS", fallback=True)
EMAIL_USE_SSL = CONFIG.getboolean("SMTP", "SSL", fallback=False)
EMAIL_FROM = CONFIG.get("SMTP", "From", fallback=EMAIL_HOST_USER)
EMAIL_BCC = json.loads(CONFIG.get("SMTP", "BCC", fallback=[]))
# Email addresses of system administrators and managers
ADMINS = [
(v,k) for k,v in CONFIG["ADMINS"].items()
]
MANAGERS = ADMINS + [
(v,k) for k,v in CONFIG["MANAGERS"].items()
]
# Misc settings
2021-04-18 10:46:05 +00:00
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
PHONENUMBER_DEFAULT_REGION = JOKER_COUNTRIES[0]
GALLERY_UPLOAD_PATH = "/userfiles/"