django-fritzconnection_ynh/conf/settings.py

183 lines
5.8 KiB
Python
Raw Normal View History

2022-04-02 17:44:57 +02:00
################################################################################
################################################################################
# Please do not modify this file, it will be reset at the next update.
2024-08-27 20:51:05 +02:00
# You can edit the file __DATA_DIR__/local_settings.py and add/modify the settings you need.
2022-04-02 17:44:57 +02:00
# The parameters you add in local_settings.py will overwrite these,
# but you can use the options and documentation in this file to find out what can be done.
################################################################################
################################################################################
from pathlib import Path as __Path
from django_yunohost_integration.base_settings import * # noqa:F401,F403
2022-04-02 17:44:57 +02:00
from django_yunohost_integration.secret_key import get_or_create_secret as __get_or_create_secret
2024-08-27 20:51:05 +02:00
# https://github.com/jedie/django-fritzconnection
from djfritz_project.settings.prod import * # noqa:F401,F403 isort:skip
from django_yunohost_integration.base_settings import LOGGING # noqa:F401 isort:skip
2022-04-02 17:44:57 +02:00
2024-08-27 20:51:05 +02:00
DATA_DIR_PATH = __Path('__DATA_DIR__') # /home/yunohost.app/$app/
assert DATA_DIR_PATH.is_dir(), f'Directory not exists: {DATA_DIR_PATH}'
INSTALL_DIR_PATH = __Path('__INSTALL_DIR__') # /var/www/$app/
assert INSTALL_DIR_PATH.is_dir(), f'Directory not exists: {INSTALL_DIR_PATH}'
2022-04-02 17:44:57 +02:00
2024-08-27 20:51:05 +02:00
LOG_FILE_PATH = __Path('__LOG_FILE__') # /var/log/$app/djfritz_ynh.log
assert LOG_FILE_PATH.is_file(), f'File not exists: {LOG_FILE_PATH}'
2022-04-02 17:44:57 +02:00
2024-08-27 20:51:05 +02:00
PATH_URL = '__PATH__'
PATH_URL = PATH_URL.strip('/')
2022-04-02 17:44:57 +02:00
2024-08-27 20:51:05 +02:00
YNH_CURRENT_HOST = '__YNH_CURRENT_HOST__' # YunoHost main domain from: /etc/yunohost/current_host
2022-04-02 17:44:57 +02:00
# -----------------------------------------------------------------------------
2022-08-16 09:47:54 +02:00
# config_panel.toml settings:
DEBUG_ENABLED = '__DEBUG_ENABLED__'
2024-08-27 20:51:05 +02:00
DEBUG = DEBUG_ENABLED == '1'
2022-08-16 09:47:54 +02:00
LOG_LEVEL = '__LOG_LEVEL__'
ADMIN_EMAIL = '__ADMIN_EMAIL__'
DEFAULT_FROM_EMAIL = '__DEFAULT_FROM_EMAIL__'
2022-04-02 17:44:57 +02:00
2022-08-16 09:47:54 +02:00
# -----------------------------------------------------------------------------
2022-04-02 17:44:57 +02:00
# Function that will be called to finalize a user profile:
YNH_SETUP_USER = 'setup_user.setup_project_user'
2024-08-27 20:51:05 +02:00
if 'axes' not in INSTALLED_APPS:
INSTALLED_APPS.append('axes') # https://github.com/jazzband/django-axes
INSTALLED_APPS.append('django_yunohost_integration.apps.YunohostIntegrationConfig')
SECRET_KEY = __get_or_create_secret(
DATA_DIR_PATH / 'secret.txt'
) # /home/yunohost.app/$app/secret.txt
2022-04-02 17:44:57 +02:00
MIDDLEWARE.insert(
MIDDLEWARE.index('django.contrib.auth.middleware.AuthenticationMiddleware') + 1,
# login a user via HTTP_REMOTE_USER header from SSOwat:
'django_yunohost_integration.sso_auth.auth_middleware.SSOwatRemoteUserMiddleware',
)
2024-08-27 20:51:05 +02:00
if 'axes.middleware.AxesMiddleware' not in MIDDLEWARE:
# AxesMiddleware should be the last middleware:
MIDDLEWARE.append('axes.middleware.AxesMiddleware')
2022-08-16 09:47:54 +02:00
2022-04-02 17:44:57 +02:00
# Keep ModelBackend around for per-user permissions and superuser
AUTHENTICATION_BACKENDS = (
2022-08-16 09:47:54 +02:00
'axes.backends.AxesBackend', # AxesBackend should be the first backend!
#
2022-04-02 17:44:57 +02:00
# Authenticate via SSO and nginx 'HTTP_REMOTE_USER' header:
'django_yunohost_integration.sso_auth.auth_backend.SSOwatUserBackend',
#
# Fallback to normal Django model backend:
'django.contrib.auth.backends.ModelBackend',
)
LOGIN_REDIRECT_URL = None
LOGIN_URL = '/yunohost/sso/'
LOGOUT_REDIRECT_URL = '/yunohost/sso/'
# /yunohost/sso/?action=logout
2022-08-16 09:47:54 +02:00
ROOT_URLCONF = 'urls' # .../conf/urls.py
2022-04-02 17:44:57 +02:00
# -----------------------------------------------------------------------------
2022-08-16 09:47:54 +02:00
ADMINS = (('__ADMIN__', ADMIN_EMAIL),)
2022-04-02 17:44:57 +02:00
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': '__DB_NAME__',
'USER': '__DB_USER__',
2022-04-02 17:44:57 +02:00
'PASSWORD': '__DB_PWD__',
'HOST': '127.0.0.1',
'PORT': '5432', # Default Postgres Port
'CONN_MAX_AGE': 600,
}
}
# Title of site to use
SITE_TITLE = '__APP__'
# Site domain
SITE_DOMAIN = '__DOMAIN__'
# Subject of emails includes site title
EMAIL_SUBJECT_PREFIX = f'[{SITE_TITLE}] '
# E-mail address that error messages come from.
SERVER_EMAIL = ADMIN_EMAIL
2022-04-02 17:44:57 +02:00
# Default email address to use for various automated correspondence from
# the site managers. Used for registration emails.
# List of URLs your site is supposed to serve
ALLOWED_HOSTS = ['__DOMAIN__']
# _____________________________________________________________________________
# Configuration for caching
CACHES = {
'default': {
'BACKEND': 'django_redis.cache.RedisCache',
'LOCATION': 'redis://127.0.0.1:6379/__REDIS_DB__',
2024-08-27 20:51:05 +02:00
# If redis is running on same host as django-fritzconnection, you might
# want to use unix sockets instead:
# 'LOCATION': 'unix:///var/run/redis/redis.sock?db=1',
2022-04-02 17:44:57 +02:00
'OPTIONS': {
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
},
'KEY_PREFIX': '__APP__',
},
}
# _____________________________________________________________________________
# Static files (CSS, JavaScript, Images)
2024-08-27 20:51:05 +02:00
if PATH_URL:
STATIC_URL = f'/{PATH_URL}/static/'
MEDIA_URL = f'/{PATH_URL}/media/'
2022-04-02 17:44:57 +02:00
else:
# Installed to domain root, without a path prefix?
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
2024-08-27 20:51:05 +02:00
STATIC_ROOT = str(INSTALL_DIR_PATH / 'static')
MEDIA_ROOT = str(INSTALL_DIR_PATH / 'media')
2022-08-16 09:47:54 +02:00
2022-04-02 17:44:57 +02:00
# -----------------------------------------------------------------------------
# Set log file to e.g.: /var/log/$app/$app.log
2024-08-27 20:51:05 +02:00
LOGGING['handlers']['log_file']['filename'] = str(LOG_FILE_PATH)
# Example how to add logging to own app:
LOGGING['loggers']['djfritz'] = {
'handlers': ['syslog', 'log_file', 'mail_admins'],
'propagate': False,
2022-04-02 17:44:57 +02:00
}
2024-08-27 20:51:05 +02:00
for __logger_name in LOGGING['loggers'].keys():
LOGGING['loggers'][__logger_name]['level'] = 'DEBUG' if DEBUG else LOG_LEVEL
2022-04-02 17:44:57 +02:00
# -----------------------------------------------------------------------------
try:
from local_settings import * # noqa:F401,F403
2022-04-02 17:44:57 +02:00
except ImportError:
pass