Skip to content

Commit

Permalink
autoformat and set media_root for dev
Browse files Browse the repository at this point in the history
  • Loading branch information
martinjrobins committed Sep 25, 2024
1 parent 70c7454 commit db630ef
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 94 deletions.
35 changes: 18 additions & 17 deletions client/config/develop_settings.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import os
from dotenv import load_dotenv

load_dotenv()
load_dotenv()

from .production_settings import * # noqa
from .production_settings import BASE_DIR
from .production_settings import BASE_DIR # noqa


MEDIA_ROOT = "."


# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['*']
ALLOWED_HOSTS = ["*"]

AP_PREDICT_SQLITE = bool(int(os.environ.get("AP_PREDICT_SQLITE", "0")))
if AP_PREDICT_SQLITE:
Expand All @@ -22,27 +25,27 @@
# 'timeout': 20,
},
}
}
}

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(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',
'core.context_processors.common',
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [os.path.join(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",
"core.context_processors.common",
],
},
},
]

LOGGING = {
"version": 1,
"version": 1,
"disable_existing_loggers": False,
"handlers": {
"console": {
Expand All @@ -54,5 +57,3 @@
"level": "DEBUG",
},
}


154 changes: 79 additions & 75 deletions client/config/production_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,107 +20,112 @@
BASE_DIR = Path(__file__).resolve().parent.parent

APPREDICT_LOOKUP_TABLE_MANIFEST = os.environ.get(
'APPREDICT_LOOKUP_TABLE_MANIFEST',
'https://cardiac.nottingham.ac.uk/lookup_tables/appredict_lookup_table_manifest.txt'
"APPREDICT_LOOKUP_TABLE_MANIFEST",
"https://cardiac.nottingham.ac.uk/lookup_tables/appredict_lookup_table_manifest.txt",
)

# running in subfolder
subfolder = os.environ.get('subfolder', None)
FORCE_SCRIPT_NAME = '/%s/' % subfolder if subfolder else ''
AUTH_USER_MODEL = 'accounts.User'
subfolder = os.environ.get("subfolder", None)
FORCE_SCRIPT_NAME = "/%s/" % subfolder if subfolder else ""
AUTH_USER_MODEL = "accounts.User"
LOGIN_REDIRECT_URL = FORCE_SCRIPT_NAME
LOGOUT_REDIRECT_URL = FORCE_SCRIPT_NAME
LOGIN_URL = ('%s/accounts/login/' % FORCE_SCRIPT_NAME).replace('//', '/')
LOGIN_URL = ("%s/accounts/login/" % FORCE_SCRIPT_NAME).replace("//", "/")

# email
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = os.environ.get('smtp_server', 'localhost')
SERVER_EMAIL = os.environ.get('django_email_from_addr', os.environ['DJANGO_SUPERUSER_EMAIL'])
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = os.environ.get("smtp_server", "localhost")
SERVER_EMAIL = os.environ.get(
"django_email_from_addr", os.environ["DJANGO_SUPERUSER_EMAIL"]
)
DEFAULT_FROM_EMAIL = SERVER_EMAIL
WELCOME_SUBJECT = os.environ.get('WELCOME_SUBJECT', '[AP Portal] Welcome')
WELCOME_SUBJECT = os.environ.get("WELCOME_SUBJECT", "[AP Portal] Welcome")

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ['DJANGO_SECRET_KEY']
SECRET_KEY = os.environ["DJANGO_SECRET_KEY"]

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS', '*').split(',')
ALLOWED_HOSTS = os.environ.get("ALLOWED_HOSTS", "*").split(",")


# Application definition

DJANGO_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
]

LOCAL_APPS = [
'core',
'accounts',
'files',
'simulations',
"core",
"accounts",
"files",
"simulations",
]

INSTALLED_APPS = DJANGO_APPS + LOCAL_APPS

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'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",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]

ROOT_URLCONF = 'config.urls'
ROOT_URLCONF = "config.urls"

# Cache templates for production
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': False,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'core.context_processors.common',
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [os.path.join(BASE_DIR, "templates")],
"APP_DIRS": False,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"core.context_processors.common",
],
'loaders': [
('django.template.loaders.cached.Loader', [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
]),
"loaders": [
(
"django.template.loaders.cached.Loader",
[
"django.template.loaders.filesystem.Loader",
"django.template.loaders.app_directories.Loader",
],
),
],
},
},
]


WSGI_APPLICATION = 'config.wsgi.application'
WSGI_APPLICATION = "config.wsgi.application"


# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': os.environ['PGDATABASE'],
'USER': os.environ['PGUSER'],
'PASSWORD': os.environ['PGPASSWORD'],
'HOST': os.environ['PGHOST'],
'PORT': os.environ['PGPORT'],
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": os.environ["PGDATABASE"],
"USER": os.environ["PGUSER"],
"PASSWORD": os.environ["PGPASSWORD"],
"HOST": os.environ["PGHOST"],
"PORT": os.environ["PGPORT"],
}
}

Expand All @@ -130,26 +135,26 @@

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
},
]


# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/

LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = "en-us"

TIME_ZONE = 'UTC'
TIME_ZONE = "UTC"

USE_I18N = False

Expand All @@ -159,43 +164,43 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/

STATIC_URL = ('%s/static/' % FORCE_SCRIPT_NAME).replace('//', '/')
STATIC_ROOT = '/opt/django/staticfiles'
STATIC_URL = ("%s/static/" % FORCE_SCRIPT_NAME).replace("//", "/")
STATIC_ROOT = "/opt/django/staticfiles"
STATICFILES_DIRS = [
str(BASE_DIR / 'static'),
str(BASE_DIR / "static"),
]

# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

# Use forwarded headers for anything that requires a hostname.
USE_X_FORWARDED_HOST = True


# Media files (Uploaded files)
MEDIA_URL = FORCE_SCRIPT_NAME + 'media/'
MEDIA_ROOT = '/opt/django/media/'
MEDIA_URL = FORCE_SCRIPT_NAME + "media/"
MEDIA_ROOT = "/opt/django/media/"

# Force using temporary fiile for upload
FILE_UPLOAD_HANDLERS = ['django.core.files.uploadhandler.TemporaryFileUploadHandler']
FILE_UPLOAD_HANDLERS = ["django.core.files.uploadhandler.TemporaryFileUploadHandler"]

# API location for AP manager
AP_PREDICT_ENDPOINT = os.environ.get('AP_PREDICT_ENDPOINT', 'http://path_to_ap_manager')
AP_PREDICT_STATUS_TIMEOUT = int(os.environ.get('AP_PREDICT_STATUS_TIMEOUT', 1000))
AP_PREDICT_ENDPOINT = os.environ.get("AP_PREDICT_ENDPOINT", "http://path_to_ap_manager")
AP_PREDICT_STATUS_TIMEOUT = int(os.environ.get("AP_PREDICT_STATUS_TIMEOUT", 1000))

# Hosting information for the privacy policy
HOSTING_INFO = os.environ.get('HOSTING_INFO', '')
HOSTING_INFO = os.environ.get("HOSTING_INFO", "")

# A brief statement that will be shown at the start of the privacy notice
PRIVACY_NOTICE = os.environ.get('PRIVACY_NOTICE', '').replace('\\n', '<br/>')
PRIVACY_NOTICE = os.environ.get("PRIVACY_NOTICE", "").replace("\\n", "<br/>")

# Mailto link for contacting maintiners
CONTACT_MAILTO = os.environ.get('CONTACT_MAILTO', '')
CONTACT_MAILTO = os.environ.get("CONTACT_MAILTO", "")

# Contact text for contacting maintiners
CONTACT_TEXT = os.environ.get('CONTACT_TEXT', '')
CONTACT_TEXT = os.environ.get("CONTACT_TEXT", "")

# prevent unwated HTTP access
CSRF_COOKIE_SECURE = True
Expand All @@ -213,6 +218,7 @@
AUTH_LDAP_SERVER_URI = os.environ.get(
"AUTH_LDAP_SERVER_URI", "ldap://ldap.forumsys.com:389"
)
AUTH_LDAP_USER_ATTR_MAP = {"first_name": "givenName", "last_name": "sn", "full_name": "cn"}

user_group = os.environ.get("AUTH_LDAP_USER_GROUP", None)
admin_group = os.environ.get("AUTH_LDAP_ADMIN_GROUP", None)
Expand Down Expand Up @@ -245,7 +251,5 @@
for base_index in [2, 3, 4, 5]:
search_base = os.environ.get(f"AUTH_LDAP_SEARCH_BASE{base_index}", None)
if search_base is not None:
searches.append(
LDAPSearch(search_base, ldap.SCOPE_SUBTREE, search_filter)
)
AUTH_LDAP_USER_SEARCH = LDAPSearchUnion(*searches)
searches.append(LDAPSearch(search_base, ldap.SCOPE_SUBTREE, search_filter))
AUTH_LDAP_USER_SEARCH = LDAPSearchUnion(*searches)
5 changes: 3 additions & 2 deletions client/core/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from django.contrib import messages
from django.conf import settings


def common(request):
return {
'INFO_MESSAGES': messages.get_messages(request),
'AP_PREDICT_LDAP': settings.AP_PREDICT_LDAP
"INFO_MESSAGES": messages.get_messages(request),
"AP_PREDICT_LDAP": settings.AP_PREDICT_LDAP,
}

0 comments on commit db630ef

Please sign in to comment.