Пример #1
0
def find_setting(group, key, site=None):
    "Get a setting or longsetting by group and key, cache and return it."

    site_id = _safe_get_site_id(site)
    setting = None

    use_db, overrides = get_overrides(site_id)
    ck = cache_key_get("Setting", site_id, group, key)

    grp = overrides.get(group, None)

    if grp and (key in grp):
        val = grp[key]
        setting = ImmutableSetting(key=key, group=group, value=val)
        logger.debug("Returning overridden: %s", setting)

    elif use_db:
        try:
            setting = cache_get(ck)
        except NotCachedError:
            model_classes = (Setting, LongSetting)
            for model_cls in model_classes:
                try:
                    setting = model_cls.objects.get(site__id=site_id, key=key, group=group)
                    break
                except model_cls.DoesNotExist:
                    pass

            cache_set(ck, value=setting)
    else:
        grp = overrides.get(group, None)
        if grp and key in grp:
            val = grp[key]
            setting = ImmutableSetting(key=key, group=group, value=val)
            logger.debug("Returning overridden: %s", setting)

    if setting is None:
        raise SettingNotSet(key, cachekey=ck)

    return setting
Пример #2
0
def find_setting(group, key, site=None):
    'Get a setting or longsetting by group and key, cache and return it.'

    site_id = _safe_get_site_id(site)
    setting = None

    use_db, overrides = get_overrides(site_id)
    ck = cache_key_get('Setting', site_id, group, key)

    grp = overrides.get(group, None)

    if grp and (key in grp):
        val = grp[key]
        setting = ImmutableSetting(key=key, group=group, value=val)
        logger.debug('Returning overridden: %s', setting)

    elif use_db:
        try:
            setting = cache_get(ck)
        except NotCachedError:
            model_classes = (Setting, LongSetting)
            for model_cls in model_classes:
                try:
                    setting = model_cls.objects.get(site__id=site_id, key=key, group=group)
                    break
                except model_cls.DoesNotExist:
                    pass

            cache_set(ck, value=setting)
    else:
        grp = overrides.get(group, None)
        if grp and key in grp:
            val = grp[key]
            setting = ImmutableSetting(key=key, group=group, value=val)
            logger.debug('Returning overridden: %s', setting)

    if setting is None:
        raise SettingNotSet(key, cachekey=ck)

    return setting
Пример #3
0
 def cache_key(self, *args, **kwargs):
     return cache_key_get("OverrideSetting", self.site, self.group, self.key)
Пример #4
0
 def cache_key(self, *args, **kwargs):
     # note same cache pattern as Setting.  This is so we can look up in one check.
     # they can't overlap anyway, so this is moderately safe.  At the worst, the
     # Setting will override a LongSetting.
     return cache_key_get("Setting", self.site, self.group, self.key)
Пример #5
0
 def cache_key(self, *args, **kwargs):
     return cache_key_get('OverrideSetting', self.site, self.group, self.key)
Пример #6
0
 def cache_key(self, *args, **kwargs):
     # note same cache pattern as Setting.  This is so we can look up in one check.
     # they can't overlap anyway, so this is moderately safe.  At the worst, the
     # Setting will override a LongSetting.
     return cache_key_get('Setting', self.site, self.group, self.key)