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:
parent
b026643cce
commit
22198d387d
@ -1,6 +1,11 @@
|
||||
[global]
|
||||
secret_file = secret.txt
|
||||
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_host1 = example.com
|
||||
|
@ -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
|
||||
|
||||
INSTALLED_APPS = [
|
||||
@ -149,6 +132,28 @@ STATIC_URL = '/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 = (
|
||||
'rest_framework.permissions.IsAuthenticated',
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user