diff --git a/mayan/apps/smart_settings/classes.py b/mayan/apps/smart_settings/classes.py index d5cc477095..c60d43187f 100644 --- a/mayan/apps/smart_settings/classes.py +++ b/mayan/apps/smart_settings/classes.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals import errno +import hashlib from importlib import import_module import logging import os @@ -78,6 +79,7 @@ class Namespace(object): @python_2_unicode_compatible class Setting(object): _registry = {} + _cache_hash = None @staticmethod def deserialize_value(value): @@ -108,6 +110,15 @@ class Setting(object): return result + @classmethod + def check_changed(cls): + if not cls._cache_hash: + cls._cache_hash = cls.get_hash() + + print("!!!@@", cls._cache_hash, cls.get_hash()) + + return cls._cache_hash != cls.get_hash() + @classmethod def dump_data(cls, filter_term=None, namespace=None): dictionary = {} @@ -129,6 +140,12 @@ class Setting(object): def get_all(cls): return sorted(cls._registry.values(), key=lambda x: x.global_name) + @classmethod + def get_hash(cls): + return force_text( + hashlib.sha256(cls.dump_data()).hexdigest() + ) + @classmethod def save_configuration(cls, path=settings.CONFIGURATION_FILEPATH): try: diff --git a/mayan/apps/smart_settings/templatetags/smart_settings_tags.py b/mayan/apps/smart_settings/templatetags/smart_settings_tags.py index 38f7743c0a..9268bd69ba 100644 --- a/mayan/apps/smart_settings/templatetags/smart_settings_tags.py +++ b/mayan/apps/smart_settings/templatetags/smart_settings_tags.py @@ -10,3 +10,9 @@ register = Library() @register.simple_tag def smart_setting(global_name): return Setting.get(global_name=global_name).value + + +@register.simple_tag +def smart_settings_check_changes(): + return Setting.check_changed() +