From 6ae24493ebf3281ee9469874d4d145410c132b52 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Fri, 19 Oct 2018 02:49:25 -0400 Subject: [PATCH] Add new showsettings management command This command displays the current configuration settings. Default the YAML flow format to False which never uses inline. Signed-off-by: Roberto Rosario --- HISTORY.rst | 3 ++ mayan/apps/smart_settings/classes.py | 14 +++++---- .../management/commands/showsettings.py | 31 +++++++++++++++++++ 3 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 mayan/apps/smart_settings/management/commands/showsettings.py diff --git a/HISTORY.rst b/HISTORY.rst index bbb1c4f358..69938654a2 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -15,6 +15,9 @@ * Add configuration option to change the project/installation URL. This is used in the password reset emails and in the default document mailing templates. +* 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') + ) + )