コード例 #1
0
    def save(self, *args, **kwargs):
        """The save method is overwritten because settings are referenced
        in several different ways. This is the cental command if we
        want to incorporate a process applicable for all those ways.
        Using signals is also feasable however there is a process order
        that must be followed (e.g. caching new value if not equal to old value)
        so we can leave that for a later time.
        """
        try:
            #get the old value as reference for updating the cache
            orig = Setting.objects.get(pk=self.pk)
        except Setting.DoesNotExist:
            orig = None

        #call touch settings if this is the setting theme
        if self.name == 'theme':
            from tendenci.apps.theme.utils import theme_options
            self.input_value = theme_options()
            super(Setting, self).save(*args, **kwargs)
            call_command('clear_theme_cache')
        else:
            super(Setting, self).save(*args, **kwargs)

        #update the cache when value has changed
        if orig and self.value != orig.value:
            from tendenci.apps.site_settings.utils import (
                delete_setting_cache, cache_setting, delete_all_settings_cache)
            from tendenci.apps.site_settings.cache import SETTING_PRE_KEY

            # delete the cache for all the settings to reset the context
            delete_all_settings_cache()
            # delete and set cache for single key and save the value in the database
            delete_setting_cache(self.scope, self.scope_category, self.name)
            cache_setting(self.scope, self.scope_category, self.name, self)
コード例 #2
0
ファイル: models.py プロジェクト: goetzk/tendenci
    def save(self, *args, **kwargs):
        """The save method is overwritten because settings are referenced
        in several different ways. This is the cental command if we
        want to incorporate a process applicable for all those ways.
        Using signals is also feasable however there is a process order
        that must be followed (e.g. caching new value if not equal to old value)
        so we can leave that for a later time.
        """
        try:
            #get the old value as reference for updating the cache
            orig = Setting.objects.get(pk = self.pk)
        except Setting.DoesNotExist:
            orig = None

        #call touch settings if this is the setting theme
        if self.name == 'theme':
            from tendenci.apps.theme.utils import theme_options
            self.input_value = theme_options()
            super(Setting, self).save(*args, **kwargs)
            call_command('clear_theme_cache')
        else:
            super(Setting, self).save(*args, **kwargs)

        #update the cache when value has changed
        if orig and self.value != orig.value:
            from tendenci.apps.site_settings.utils import (delete_setting_cache,
                cache_setting, delete_all_settings_cache)
            from tendenci.apps.site_settings.cache import SETTING_PRE_KEY

            # delete the cache for all the settings to reset the context
            delete_all_settings_cache()
            # delete and set cache for single key and save the value in the database
            delete_setting_cache(self.scope, self.scope_category, self.name)
            cache_setting(self.scope, self.scope_category, self.name, self)
コード例 #3
0
    def get_value(self):
        try:
            if self.is_secure:
                return decrypt(self.value)
        except AttributeError:  #cached setting with no is_secure
            from tendenci.apps.site_settings.utils import (
                delete_setting_cache, delete_all_settings_cache)
            # delete the cache for this setting
            # print("clearing cache for setting: %s" % self.name)
            delete_all_settings_cache()
            delete_setting_cache(self.scope, self.scope_category, self.name)

        return self.value
コード例 #4
0
    def handle(self,
               scope=None,
               scope_category=None,
               name=None,
               value=None,
               **options):
        """
        Set the website theme via theme name
        """
        from tendenci.apps.site_settings.models import Setting
        from tendenci.apps.site_settings.utils import delete_all_settings_cache

        if scope and scope_category and name and value:
            try:
                setting = Setting.objects.get(
                    name=name,
                    scope=scope,
                    scope_category=scope_category,
                )
                setting.set_value(value)
                setting.save()

                setting.update_site_domain(value)

            except Setting.DoesNotExist:
                if int(options['verbosity']) > 0:
                    print("We could not update that setting.")
            delete_all_settings_cache()

            if name == "sitedisplayname":
                from tendenci.apps.user_groups.models import Group
                from tendenci.apps.entities.models import Entity
                try:
                    entity = Entity.objects.get(pk=1)
                    entity.entity_name = value
                    entity.save()
                except:
                    pass

                try:
                    group = Group.objects.get(pk=1)
                    group.name = value
                    group.label = value
                    group.slug = ''
                    group.save()
                except:
                    pass
コード例 #5
0
ファイル: models.py プロジェクト: goetzk/tendenci
    def get_value(self):
        try:
            if self.is_secure:
                try:
                    return decrypt(self.value).decode('utf-8')
                except UnicodeDecodeError:
                    return decrypt(self.value)
        except AttributeError: #cached setting with no is_secure
            from tendenci.apps.site_settings.utils import (
                delete_setting_cache,
                delete_all_settings_cache)
            # delete the cache for this setting
            # print("clearing cache for setting: %s" % self.name)
            delete_all_settings_cache()
            delete_setting_cache(self.scope, self.scope_category, self.name)

        return self.value
コード例 #6
0
    def save(self, *args, **kwargs):
        """The save method is overwritten because settings are referenced
        in several different ways. This is the central command if we
        want to incorporate a process applicable for all those ways.
        Using signals is also feasible however there is a process order
        that must be followed (e.g. caching new value if not equal to old value)
        so we can leave that for a later time.
        """
        # Django 1.10 and later no longer accept "true" or "false" strings for
        # BooleanField values.  Since these are used in many existing theme
        # settings files, we must still support them.
        if self.client_editable in ('true', 'false'):
            self.client_editable = self.client_editable == 'true'
        if self.store in ('true', 'false'):
            self.store = self.store == 'true'
        if self.is_secure in ('true', 'false'):
            self.is_secure = self.is_secure == 'true'

        try:
            #get the old value as reference for updating the cache
            orig = Setting.objects.get(pk=self.pk)
        except Setting.DoesNotExist:
            orig = None

        #call touch settings if this is the setting theme
        if self.name == 'theme':
            from tendenci.apps.theme.utils import theme_options
            self.input_value = theme_options()
            super(Setting, self).save(*args, **kwargs)
            call_command('clear_theme_cache')
        else:
            super(Setting, self).save(*args, **kwargs)

        #update the cache when value has changed
        if orig and self.value != orig.value:
            from tendenci.apps.site_settings.utils import (
                delete_setting_cache, cache_setting, delete_all_settings_cache)

            # delete the cache for all the settings to reset the context
            delete_all_settings_cache()
            # delete and set cache for single key and save the value in the database
            delete_setting_cache(self.scope, self.scope_category, self.name)
            cache_setting(self.scope, self.scope_category, self.name, self)
コード例 #7
0
ファイル: set_setting.py プロジェクト: BIGGANI/tendenci
    def handle(self, scope=None, scope_category=None, name=None, value=None, **options):
        """
        Set the website theme via theme name
        """
        from tendenci.apps.site_settings.models import Setting
        from tendenci.apps.site_settings.utils import delete_all_settings_cache

        if scope and scope_category and name and value:
            try:
                setting = Setting.objects.get(
                    name=name,
                    scope=scope,
                    scope_category=scope_category,
                )
                setting.set_value(value)
                setting.save()

            except Setting.DoesNotExist:
                if int(options['verbosity']) > 0:
                    print "We could not update that setting."
            delete_all_settings_cache()

            if name == "sitedisplayname":
                from tendenci.apps.user_groups.models import Group
                from tendenci.apps.entities.models import Entity
                try:
                    entity = Entity.objects.get(pk=1)
                    entity.entity_name = value
                    entity.save()
                except:
                    pass

                try:
                    group = Group.objects.get(pk=1)
                    group.name = value
                    group.label = value
                    group.slug = ''
                    group.save()
                except:
                    pass