from pathlib import Path import json from autosecretkey import AutoSecretKey # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent 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"] # 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', 'localauth', 'frontend', 'partners', 'payment', 'clients', 'dbsettings', 'auction', 'bootstrap4', 'django_countries', 'mathfilters', 'mail', 'gallery', 'django_starfield', ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', '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', 'frontend.middleware.DemoMiddleware', ] ROOT_URLCONF = 'urlaubsauktion.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [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', 'frontend.context_processors.demo', ], }, }, ] WSGI_APPLICATION = 'urlaubsauktion.wsgi.application' # Database # 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', } } # 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/ LANGUAGE_CODE = 'de' TIME_ZONE = 'Europe/Vienna' USE_I18N = True USE_L10N = True USE_TZ = True LOCALE_PATHS = [ BASE_DIR / "locale", ] LANGUAGES = [ ('de', 'German'), ('en', 'English') ] # Static files (CSS, JavaScript, Images) # 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") STATIC_URL = '/static/' STATICFILES_DIRS = [ BASE_DIR / "static", ] AUTH_USER_MODEL = "localauth.User" REGISTER_REDIRECT_URL = "/" LOGIN_REDIRECT_URL = "/" LOGOUT_REDIRECT_URL = "/" LOGIN_URL = "localauth:login" LOGOUT_URL = "localauth:logout" # 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 DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' PHONENUMBER_DEFAULT_REGION = JOKER_COUNTRIES[0] GALLERY_UPLOAD_PATH = "/userfiles/"