Make settings in .ini optional and add new ones

Fixes #24

New settings available :
STATIC_ROOT
STATIC_URL
LANGUAGE_CODE
TIME_ZONE
This commit is contained in:
Pierre-Alain TORET 2019-11-05 10:30:50 +01:00 committed by Tom Hacohen
parent b026643cce
commit 22198d387d
2 changed files with 27 additions and 17 deletions

View File

@ -1,6 +1,11 @@
[global] [global]
secret_file = secret.txt secret_file = secret.txt
debug = false debug = false
;Advanced options, only uncomment if you know what you're doing:
;static_root = /path/to/static
;static_url = /static/
;language_code = en-us
;time_zone = UTC
[allowed_hosts] [allowed_hosts]
allowed_host1 = example.com allowed_host1 = example.com

View File

@ -43,23 +43,6 @@ DATABASES = {
} }
# Define where to find configuration files
config_locations = ['etesync-server.ini', '/etc/etesync-server/etesync-server.ini']
# Use config file if present
if any(os.path.isfile(x) for x in config_locations):
config = configparser.ConfigParser()
config.read(config_locations)
SECRET_FILE = config['global']['secret_file']
DEBUG = config['global'].getboolean('debug')
ALLOWED_HOSTS = [y for x, y in config.items('allowed_hosts')]
DATABASES = { 'default': { x.upper(): y for x, y in config.items('database') } }
# Application definition # Application definition
INSTALLED_APPS = [ INSTALLED_APPS = [
@ -149,6 +132,28 @@ STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/') STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
# Define where to find configuration files
config_locations = ['etesync-server.ini', '/etc/etesync-server/etesync-server.ini']
# Use config file if present
if any(os.path.isfile(x) for x in config_locations):
config = configparser.ConfigParser()
config.read(config_locations)
section = config['global']
SECRET_FILE = section.get('secret_file', SECRET_FILE)
STATIC_ROOT = section.get('static_root', STATIC_ROOT)
STATIC_URL = section.get('static_url', STATIC_URL)
LANGUAGE_CODE = section.get('language_code', LANGUAGE_CODE)
TIME_ZONE = section.get('time_zone', TIME_ZONE)
DEBUG = section.getboolean('debug', DEBUG)
if 'allowed_hosts' in config:
ALLOWED_HOSTS = [y for x, y in config.items('allowed_hosts')]
if 'database' in config:
DATABASES = { 'default': { x.upper(): y for x, y in config.items('database') } }
JOURNAL_API_PERMISSIONS = ( JOURNAL_API_PERMISSIONS = (
'rest_framework.permissions.IsAuthenticated', 'rest_framework.permissions.IsAuthenticated',
) )