Skip to content

Commit

Permalink
Merge branch 'feature/settings-get-object' into develop
Browse files Browse the repository at this point in the history
 Closes: #336
  • Loading branch information
felliott committed May 1, 2018
2 parents f4a5cd2 + 0eac963 commit 681a0ce
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion mfr/extensions/pdb/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

config = settings.child('PDB_EXTENSION_CONFIG')

OPTIONS = config.get('OPTIONS', {
OPTIONS = config.get_object('OPTIONS', {
'width': 'auto',
'height': '400',
'antialias': True,
Expand Down
6 changes: 3 additions & 3 deletions mfr/extensions/tabular/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
TABLE_WIDTH = int(config.get('TABLE_WIDTH', 700))
TABLE_HEIGHT = int(config.get('TABLE_HEIGHT', 600))

LIBS = config.get('LIBS', {
LIBS = config.get_object('LIBS', {
'.csv': [libs.csv_stdlib],
'.tsv': [libs.csv_stdlib],
'.gsheet': [libs.xlsx_xlrd],
Expand All @@ -21,15 +21,15 @@
# '.ods': [libs.ods_ezodf],
})

SMALL_TABLE = config.get('SMALL_TABLE', {
SMALL_TABLE = config.get_object('SMALL_TABLE', {
'enableCellNavigation': True,
'enableColumnReorder': False,
'forceFitColumns': True,
'syncColumnCellResize': True,
'multiColumnSort': True,
})

BIG_TABLE = config.get('BIG_TABLE', {
BIG_TABLE = config.get_object('BIG_TABLE', {
'enableCellNavigation': True,
'enableColumnReorder': False,
'syncColumnCellResize': True,
Expand Down
2 changes: 1 addition & 1 deletion mfr/extensions/unoconv/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

DEFAULT_RENDER = {'renderer': '.pdf', 'format': 'pdf'}

RENDER_MAP = config.get('RENDER_MAP', {
RENDER_MAP = config.get_object('RENDER_MAP', {
# 'csv': {'renderer': '.xlsx', 'format': 'xlsx'},
# 'ppt': {'renderer': '.pdf', 'format': 'pdf'},
# 'pptx': {'renderer': '.pdf', 'format': 'pdf'},
Expand Down
6 changes: 3 additions & 3 deletions mfr/server/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@

CACHE_ENABLED = config.get_bool('CACHE_ENABLED', False)
CACHE_PROVIDER_NAME = config.get('CACHE_PROVIDER_NAME', 'filesystem')
CACHE_PROVIDER_SETTINGS = config.get('CACHE_PROVIDER_SETTINGS', {'folder': '/tmp/mfr/'})
CACHE_PROVIDER_CREDENTIALS = config.get('CACHE_PROVIDER_CREDENTIALS', {})
CACHE_PROVIDER_SETTINGS = config.get_object('CACHE_PROVIDER_SETTINGS', {'folder': '/tmp/mfr/'})
CACHE_PROVIDER_CREDENTIALS = config.get_object('CACHE_PROVIDER_CREDENTIALS', {})

LOCAL_CACHE_PROVIDER_SETTINGS = config.get('LOCAL_CACHE_PROVIDER_SETTINGS', {'folder': '/tmp/mfrlocalcache/'})
LOCAL_CACHE_PROVIDER_SETTINGS = config.get_object('LOCAL_CACHE_PROVIDER_SETTINGS', {'folder': '/tmp/mfrlocalcache/'})

ALLOWED_PROVIDER_DOMAINS = config.get('ALLOWED_PROVIDER_DOMAINS', 'http://localhost:5000/ http://localhost:7777/').split(' ')
ALLOWED_PROVIDER_NETLOCS = []
Expand Down
9 changes: 9 additions & 0 deletions mfr/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ def get_nullable(self, key, default=None):
value = self.get(key, default)
return None if value == '' else value

def get_object(self, key, default=None):
"""Fetch a config value and interpret as a Python object or list. Since envvars are
always strings, interpret values of type `str` as JSON object or array. Otherwise assume
the type is already a python object."""
value = self.get(key, default)
if isinstance(value, str):
value = json.loads(value)
return value

def full_key(self, key):
"""The name of the envvar which corresponds to this key."""
return '{}_{}'.format(self.parent, key) if self.parent else key
Expand Down

0 comments on commit 681a0ce

Please sign in to comment.