Add template tag to fetch the value of a smart setting.
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -64,6 +64,8 @@ class Namespace(object):
|
||||
|
||||
|
||||
class Setting(object):
|
||||
_registry = {}
|
||||
|
||||
@staticmethod
|
||||
def deserialize_value(value):
|
||||
return yaml.safe_load(value)
|
||||
@@ -75,12 +77,17 @@ class Setting(object):
|
||||
|
||||
return yaml.safe_dump(value, allow_unicode=True)
|
||||
|
||||
@classmethod
|
||||
def get(cls, global_name):
|
||||
return cls._registry[global_name].value
|
||||
|
||||
def __init__(self, namespace, global_name, default, help_text=None, is_path=False):
|
||||
self.global_name = global_name
|
||||
self.default = default
|
||||
self.help_text = help_text
|
||||
self.loaded = False
|
||||
namespace.settings.append(self)
|
||||
self.__class__._registry[global_name] = self
|
||||
|
||||
def __unicode__(self):
|
||||
return unicode(self.global_name)
|
||||
|
||||
0
mayan/apps/smart_settings/templatetags/__init__.py
Normal file
0
mayan/apps/smart_settings/templatetags/__init__.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.template import Library
|
||||
|
||||
from ..classes import Setting
|
||||
|
||||
register = Library()
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def smart_setting(global_name):
|
||||
return Setting.get(global_name=global_name)
|
||||
Reference in New Issue
Block a user