diff --git a/HISTORY.rst b/HISTORY.rst index 2c5d89e12d..012e5fa7fd 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -18,7 +18,9 @@ * Increase the size of the workflow preview image. * Center the workflow preview image. * Move the noop OCR backend to the right place. - +* Add new management command to display the current configuration + settings. +* Default the YAML flow format to False which never uses inline. 3.1.7 (2018-10-14) ================== diff --git a/mayan/apps/smart_settings/classes.py b/mayan/apps/smart_settings/classes.py index a18445211e..32d1973b4c 100644 --- a/mayan/apps/smart_settings/classes.py +++ b/mayan/apps/smart_settings/classes.py @@ -92,16 +92,18 @@ class Setting(object): return result @classmethod - def dump_data(cls): + def dump_data(cls, filter_term=None, namespace=None): dictionary = {} for setting in cls.get_all(): - if isinstance(setting.value, Promise): - dictionary[setting.global_name] = force_text(setting.value) - else: - dictionary[setting.global_name] = setting.value + if (namespace and setting.namespace.name == namespace) or not namespace: + if (filter_term and filter_term.lower() in setting.global_name.lower()) or not filter_term: + if isinstance(setting.value, Promise): + dictionary[setting.global_name] = force_text(setting.value) + else: + dictionary[setting.global_name] = setting.value - return yaml.safe_dump(dictionary) + return yaml.safe_dump(dictionary, default_flow_style=False) @classmethod def get(cls, global_name): diff --git a/mayan/apps/smart_settings/management/commands/showsettings.py b/mayan/apps/smart_settings/management/commands/showsettings.py new file mode 100644 index 0000000000..c26825ff68 --- /dev/null +++ b/mayan/apps/smart_settings/management/commands/showsettings.py @@ -0,0 +1,31 @@ +from __future__ import unicode_literals + +from django.core import management + +from ...classes import Setting + + +class Command(management.BaseCommand): + help = 'Display the current settings.' + + def add_arguments(self, parser): + + parser.add_argument( + dest='filter_term', nargs='?', help='Use this term to filter the ' + 'list of settings.' + ) + + parser.add_argument( + '--namespace', action='store', dest='namespace', + help='Name (not label) of the namespace for which to filter the ' + 'list of settings. Names are lowercase with words separated by ' + 'underscore.' + ) + + def handle(self, *args, **options): + self.stdout.write( + Setting.dump_data( + namespace=options.get('namespace'), + filter_term=options.get('filter_term') + ) + )