module documentation

Main configurations. Explanations of all options can be found in the Django docs.

Generally, the most important settings - but also as few as possible - should be fetched from environment variables. This is good practice (see 12 Factor App) and especially for security related stuff important. Although LyProX doesn't really have much security relevant stuff going on.

The settings are written such that errors are thrown when the required environment vars are not present. This is by design, to ensure the host environment is configured for the application. It is recommended that you write an .env file at the root of the project (DON'T TRACK IT WITH GIT!), from which the environment variables are loaded. The .env file should look like this:

# .env
DJANGO_ENV=debug
DJANGO_SECRET_KEY=...

The minimally required environment variables that need to be set are:

  • DJANGO_ENV can be "debug", "maintenance", or "production".
  • DJANGO_SECRET_KEY determines the value of the app's SECRET_KEY and must contain the secret key for Django's security stuff.
  • DJANGO_ALLOWED_HOSTS needs to contain the allowed host names separated by spaces. It will be stored in the ALLOWED_HOSTS setting.
  • DJANGO_LOG_LEVEL for Django's LOG_LEVEL. This only has an effect in debug mode.
  • DJANGO_BASE_DIR is the directory in which Django is based. Using BASE_DIR, this is used to determine the location of the database and static files.
  • GITHUB_TOKEN is the token for the GitHub API. This determines the value of the corresponding GITHUB_TOKEN setting. See this variable's docstring for more details. Note that if this is not set, it won't immediately throw an error, but the datasets will likely fail to be loaded initially.
Class TStages Tumor stages.
Function set_logging Return logging settings for specified log_level.
Constant ALLOWED_HOSTS From which hosts the application is allowed to be accessed.
Constant AUTH_PASSWORD_VALIDATORS Undocumented
Constant AUTH_USER_MODEL Undocumented
Constant BASE_DIR Path to the base directory of the project.
Constant CRSF_TRUSTED_ORIGINS Undocumented
Constant CSRF_COOKIE_SECURE Undocumented
Constant DATABASES Undocumented
Constant DBBACKUP_STORAGE Undocumented
Constant DBBACKUP_STORAGE_OPTIONS Undocumented
Constant DEBUG True, when in debug mode, meaning DJANGO_ENV is set to "debug".
Constant DEFAULT_AUTO_FIELD Undocumented
Constant GITHUB Undocumented
Constant GITHUB_REPO_NAME Undocumented
Constant GITHUB_REPO_OWNER Undocumented
Constant GITHUB_TOKEN Authentication token for GitHub API.
Constant INSTALLED_APPS Undocumented
Constant JOBLIB_CACHE_DIR Undocumented
Constant LANGUAGE_CODE Undocumented
Constant LNLS Undocumented
Constant LOG_LEVEL Minimum level of emitted log messages.
Constant LOGGING Undocumented
Constant LOGIN_NOT_REQUIRED_URLS List of regexes for urls that are exceptions from the LOGIN_REQUIRED_URLS.
Constant LOGIN_REDIRECT_URL Redirect to this URL after successful login.
Constant LOGIN_URL URL to redirect to when login is required.
Constant MAINTENANCE If True, all requests to are redirected to a maintenance page. DJANGO_ENV must be set to "maintenance" for this to work. Also see lyprox.views.maintenance.
Constant MEDIA_ROOT Undocumented
Constant MEDIA_URL Undocumented
Constant MIDDLEWARE Undocumented
Constant PRODUCTION The environment mode.
Constant PUBLICATIONS_PATH Undocumented
Constant ROOT_URLCONF Undocumented
Constant SECRET_KEY Secret key for cryptography read from the environment variable DJANGO_SECRET_KEY.
Constant SECURE_HSTS_INCLUDE_SUBDOMAINS Undocumented
Constant SECURE_HSTS_PRELOAD Undocumented
Constant SECURE_HSTS_SECONDS Undocumented
Constant SECURE_PROXY_SSL_HEADER Undocumented
Constant SESSION_COOKIE_SECURE Undocumented
Constant STATIC_ROOT Undocumented
Constant STATIC_URL Undocumented
Constant STATICFILES_DIRS Undocumented
Constant TEMPLATES Undocumented
Constant TIME_ZONE Undocumented
Constant USE_I18N Undocumented
Constant USE_L10N Undocumented
Constant USE_TZ Undocumented
Type Alias LogLevelType Undocumented
Variable LOGIN_REQUIRED_URLS List of regexes for urls that require login.
Variable _login_required_urls_env Undocumented
def set_logging(log_level: LogLevelType) -> dict:

Return logging settings for specified log_level.

This is used so that in a subdomain settings file the function can be called again to overwrite the logging settings easily.

ALLOWED_HOSTS =

From which hosts the application is allowed to be accessed.

This is space-separated list of hostnames from which access is allowed. Set to "localhost 127.0.0.1" for local use. For deployment this should be changed to the domain name you are using.

Value
os.environ['DJANGO_ALLOWED_HOSTS'].split(' ')
AUTH_PASSWORD_VALIDATORS: list =

Undocumented

Value
[{'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValida
tor'},
 {'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator'},
 {'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator'},
 {'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator'}]
AUTH_USER_MODEL: str =

Undocumented

Value
'accounts.User'
BASE_DIR =

Path to the base directory of the project.

The base directory of the server is ypically the root of the repository. From this directory, the web app infers the location of a couple of directories and paths it needs e.g. for loading and storing static files and media stuff. If this isn't set, one might end up with a situation where Django tries to set up everything relative to the site-packages folder inside the .venv.

Value
Path(os.environ['DJANGO_BASE_DIR'])
CRSF_TRUSTED_ORIGINS =

Undocumented

Value
[f'https://{host}' for host in ALLOWED_HOSTS]
CSRF_COOKIE_SECURE =

Undocumented

Value
not DEBUG
DATABASES =

Undocumented

Value
{'default': {'ENGINE': 'django.db.backends.sqlite3',
             'NAME': BASE_DIR / 'db.sqlite3'}}
DBBACKUP_STORAGE: str =

Undocumented

Value
'django.core.files.storage.FileSystemStorage'
DBBACKUP_STORAGE_OPTIONS: dict[str, str] =

Undocumented

Value
{'location': '/home/rmnldwg/backups/lyprox/'}
DEBUG =

True, when in debug mode, meaning DJANGO_ENV is set to "debug".

Value
os.environ['DJANGO_ENV'] == 'debug'
DEFAULT_AUTO_FIELD: str =

Undocumented

Value
'django.db.models.AutoField'
GITHUB =

Undocumented

Value
Github(auth=Auth.Token(GITHUB_TOKEN))
GITHUB_REPO_NAME: str =

Undocumented

Value
'lyprox'
GITHUB_REPO_OWNER: str =

Undocumented

Value
'rmnldwg'
GITHUB_TOKEN =

Authentication token for GitHub API.

A personal secret for accessing GitHub's official API. This is used to access the lyDATA repo and fetch the datasets. Refer to the GitHub documentation on how to create such a token.

Value
os.environ['GITHUB_TOKEN']
INSTALLED_APPS: list[str] =

Undocumented

Value
['lyprox.accounts.apps.AccountsConfig',
 'lyprox.dataexplorer.apps.DataExplorerConfig',
 'lyprox.riskpredictor.apps.RiskConfig',
 'fontawesomefree',
 'sekizai',
 'django.contrib.admin',
 'django.contrib.auth',
...
JOBLIB_CACHE_DIR =

Undocumented

Value
BASE_DIR / '.cache'
LANGUAGE_CODE: str =

Undocumented

Value
'en-us'
LNLS: list[str] =

Undocumented

Value
['I', 'Ia', 'Ib', 'II', 'IIa', 'IIb', 'III', 'IV', 'V', 'Va', 'Vb', 'VII']
LOG_LEVEL =

Minimum level of emitted log messages.

The log level only has an effect in "debug" mode. Is set to "WARNING" otherwise.

Value
os.environ['DJANGO_LOG_LEVEL'] if DEBUG else 'WARNING'
LOGGING =

Undocumented

Value
set_logging(LOG_LEVEL)
LOGIN_NOT_REQUIRED_URLS: list[str] =

List of regexes for urls that are exceptions from the LOGIN_REQUIRED_URLS.

Value
['/accounts/login/(.*)$',
 '/accounts/logout/(.*)$',
 '/admin/(.*)$',
 '/maintenance/(.*)$']
LOGIN_REDIRECT_URL: str =

Redirect to this URL after successful login.

Value
'/'
LOGIN_URL =

URL to redirect to when login is required.

Value
urls.reverse_lazy('accounts:login')
MAINTENANCE =

If True, all requests to are redirected to a maintenance page. DJANGO_ENV must be set to "maintenance" for this to work. Also see lyprox.views.maintenance.

Value
os.environ['DJANGO_ENV'] == 'maintenance'
MEDIA_ROOT =

Undocumented

Value
BASE_DIR / 'media'
MEDIA_URL: str =

Undocumented

Value
'/media/'
MIDDLEWARE: list[str] =

Undocumented

Value
['lyprox.middleware.MaintenanceMiddleware',
 'lyprox.middleware.LoginRequiredMiddleware',
 'django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
...
PRODUCTION =

The environment mode.

Can be "debug", "production", or "maintenance". For running the interface locally, it should be set to "debug".

Value
os.environ['DJANGO_ENV'] == 'production'
PUBLICATIONS_PATH =

Undocumented

Value
STATIC_ROOT / 'publications' / 'data.yaml'
ROOT_URLCONF: str =

Undocumented

Value
'lyprox.urls'
SECRET_KEY =

Secret key for cryptography read from the environment variable DJANGO_SECRET_KEY.

This is the app-wide secret for authentication and security functions. It can be generated using django's built-in functions. Enter a python REPL by typing python into the terminal and then execute these two commands:

>>> from django.core.management.utils import get_random_secret_key
>>> print(get_random_secret_key())

This will output something like 6-y$g=ek4x!f3kq+=c+f%5@(f1efpdl!(sp&so(bgdli_&_8+n. Note that this is the most sensitive variable for the security of the web app!

Value
os.environ['DJANGO_SECRET_KEY']
SECURE_HSTS_INCLUDE_SUBDOMAINS =

Undocumented

Value
not DEBUG
SECURE_HSTS_PRELOAD =

Undocumented

Value
not DEBUG
SECURE_HSTS_SECONDS =

Undocumented

Value
30 if DEBUG else 2592000
SECURE_PROXY_SSL_HEADER: tuple[str, ...] =

Undocumented

Value
('HTTP_X_FORWARDED_PROTO', 'https')
SESSION_COOKIE_SECURE =

Undocumented

Value
not DEBUG
STATIC_ROOT =

Undocumented

Value
BASE_DIR / 'static'
STATIC_URL: str =

Undocumented

Value
'/static/'
STATICFILES_DIRS =

Undocumented

Value
[(BASE_DIR / 'lyprox' / 'static')]
TEMPLATES =

Undocumented

Value
[{'BACKEND': 'django.template.backends.django.DjangoTemplates',
  'DIRS': [(BASE_DIR / 'lyprox' / 'templates')],
  'APP_DIRS': True,
  'OPTIONS': {'context_processors': ['django.template.context_processors.debug',
                                     'django.template.context_processors.request'
,
                                     'django.contrib.auth.context_processors.aut
...
TIME_ZONE: str =

Undocumented

Value
'Europe/Zurich'
USE_I18N: bool =

Undocumented

Value
True
USE_L10N: bool =

Undocumented

Value
True
USE_TZ: bool =

Undocumented

Value
True
LogLevelType =

Undocumented

Value
Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']
LOGIN_REQUIRED_URLS =

List of regexes for urls that require login.

Note that this may simply be left empty, since the critical views are protected by default. But if you want to protect e.g. the entire website, you can add "(.*)$" to the list.

_login_required_urls_env =

Undocumented