Configuration adapted

This commit is contained in:
Dirk Alders 2020-01-31 10:49:15 +01:00
parent 07fb1cb577
commit 5cea6d1589
3 changed files with 71 additions and 20 deletions

32
config_example/config.py Normal file
View File

@ -0,0 +1,32 @@
import os
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
#
# General settings
#
# SECRET_KEY = 'define a secret key'
#
# ITEM_ROOT = os.path.join(BASE_DIR, 'data', 'example_data')
# ALLOWED_HOSTS = []
#
# Access Right settings
#
# SUSPEND_PUBLIC = True # Set this to True to ensure, that unauthenticated users have no permission
#
# Style settings
#
# DEFAULT_THEME = 'clear-red'
# THUMBNAIL_SIZES = [137, 175, 250]
# WEBNAIL_SIZES = [450, 1100, 1750]
#
# Content settings
#
# SORT_BY = False # Sorting by name if False
# SHOW_IMAGE = True
# SHOW_VIDEO = True
# SHOW_AUDIO = False
# SHOW_OTHER = False

View File

@ -10,13 +10,10 @@ For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/ https://docs.djangoproject.com/en/2.2/ref/settings/
""" """
try: import config
from config import config
# required keys: SECRET_KEY
# optional keys: ALLOWED_HOSTS, DEFAULT_THEME, ITEM_ROOT, THUMBNAIL_SIZES, WEBNAIL_SIZES
except ImportError:
config = {}
import os import os
import stat
import sys
import random import random
@ -24,25 +21,55 @@ import random
# #
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Check permission of config.py
#
if sys.platform == 'linux' or sys.platform == 'linux2':
st = os.stat(os.path.join(BASE_DIR, 'config.py'))
if st.st_mode & stat.S_IRGRP or st.st_mode & stat.S_IROTH:
raise PermissionError("conig.py is readable by group or others.")
# Default values, if not defined in config.py
#
USER_CONFIG_DEFAULTS = {
'SECRET_KEY': None,
'DEFAULT_THEME': 'clear-red',
'ALLOWED_HOSTS': [],
'ITEM_ROOT': os.path.join(BASE_DIR, 'data', 'example_data'),
'THUMBNAIL_SIZES': [137, 175, 250],
'WEBNAIL_SIZES': [450, 1100, 1750],
'SUSPEND_PUBLIC': True,
'SORT_BY_DATE': True,
'SHOW_IMAGE': True,
'SHOW_VIDEO': True,
'SHOW_AUDIO': False,
'SHOW_OTHER': False,
}
# Set configuration parameters
#
thismodule = sys.modules[__name__]
for property_name in USER_CONFIG_DEFAULTS:
try:
value = getattr(config, property_name)
except AttributeError:
value = USER_CONFIG_DEFAULTS[property_name]
setattr(thismodule, property_name, value)
# Quick-start development settings - unsuitable for production # Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ # See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret! # SECURITY WARNING: keep the secret key used in production secret!
# #
try: if SECRET_KEY is None:
SECRET_KEY = config['SECRET_KEY']
except KeyError:
chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)' chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
s_key = ''.join([random.choice(chars) for n in range(50)]) s_key = ''.join([random.choice(chars) for n in range(50)])
secret_key_warning = "You need to create a config.py file including a variable config which is a dict with at least a SECRET_KEY definition (e.g.: %s)." % repr(s_key) secret_key_warning = "You need to create a config.py file including a variable config which is a dict with at least a SECRET_KEY definition (e.g.: %s)." % repr(s_key)
raise KeyError(secret_key_warning) raise KeyError(secret_key_warning)
# SECURITY WARNING: don't run with debug turned on in production! # SECURITY WARNING: don't run with debug turned on in production!
# #
DEBUG = False DEBUG = False
ALLOWED_HOSTS = config.get('ALLOWED_HOSTS', [])
# Application definition # Application definition
# #
@ -243,11 +270,3 @@ LOGIN_URL = 'users-login'
XNAIL_ROOT = os.path.join(BASE_DIR, 'data', 'xnails') XNAIL_ROOT = os.path.join(BASE_DIR, 'data', 'xnails')
TEMP_ROOT = os.path.join(BASE_DIR, 'data', 'temp') TEMP_ROOT = os.path.join(BASE_DIR, 'data', 'temp')
# App Configuration
#
DEFAULT_THEME = config.get('DEFAULT_THEME', 'clear-red')
ITEM_ROOT = config.get('ITEM_ROOT', os.path.join(BASE_DIR, 'data', 'example_data'))
THUMBNAIL_SIZES = config.get('THUMBNAIL_SIZES', [137, 175, 250])
WEBNAIL_SIZES = config.get('WEBNAIL_SIZES', [450, 1100, 1750])

2
pygal

@ -1 +1 @@
Subproject commit 983fa59231403732d08716c1d7677fa3b090bd44 Subproject commit 9da7e60a131d94fe30ecb3d3ae7ec733fa173dd3