Merge branch 'feature/show_config' into versions/next

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2018-10-19 02:58:53 -04:00
3 changed files with 42 additions and 7 deletions
+8 -6
View File
@@ -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):
@@ -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')
)
)