def update(self, value, language_code=None): use_db, overrides = get_overrides() if use_db: current_value = self.value new_value = self.to_python(value) if current_value != new_value: if self.update_callback: new_value = apply(self.update_callback, (current_value, new_value)) db_value = self.get_db_prep_save(new_value) try: s = self.get_setting(language_code) s.value = db_value except SettingNotSet: s = self.make_setting(db_value, language_code=language_code) if self.use_default and self.default == new_value: if s.id: log.info("Deleted setting %s.%s", self.group.key, self.key) s.delete() else: log.info("Updated setting %s.%s = %s", self.group.key, self.key, value) s.save() if self.localized: try: unlocalized_setting = find_setting( self.group.key, self.key) unlocalized_setting.delete() except SettingNotSet: pass signals.configuration_value_changed.send( self, old_value=current_value, new_value=new_value, setting=self, language_code=language_code) if self.clear_cache: cache.clear() return True else: log.debug( 'not updating setting %s.%s - askbot.deps.livesettings db is disabled', self.group.key, self.key) return False
def get_editor_value(self, language_code): try: setting = self.get_setting(language_code) return self.to_python(setting.value) except SettingNotSet: if language_code == django_settings.LANGUAGE_CODE: try: return self.to_python(find_setting(self.group.key, self.key).value) except SettingNotSet: pass return self.get_default_editor_value(language_code)
def update(self, value, language_code=None): use_db, overrides = get_overrides() if use_db: current_value = self.value new_value = self.to_python(value) if current_value != new_value: if self.update_callback: new_value = apply(self.update_callback, (current_value, new_value)) db_value = self.get_db_prep_save(new_value) try: s = self.get_setting(language_code) s.value = db_value except SettingNotSet: s = self.make_setting(db_value, language_code=language_code) if self.use_default and self.default == new_value: if s.id: log.info("Deleted setting %s.%s", self.group.key, self.key) s.delete() else: log.info("Updated setting %s.%s = %s", self.group.key, self.key, value) s.save() if self.localized: try: unlocalized_setting = find_setting(self.group.key, self.key) unlocalized_setting.delete() except SettingNotSet: pass signals.configuration_value_changed.send(self, old_value=current_value, new_value=new_value, setting=self, language_code=language_code) if self.clear_cache: cache.clear() return True else: log.debug('not updating setting %s.%s - askbot.deps.livesettings db is disabled',self.group.key, self.key) return False
def _value(self): use_db, overrides = get_overrides() lang = get_language() key = self.key if self.localized: key += '_' + format_setting_name(lang) if not use_db: try: val = overrides[self.group.key][key] except KeyError: if self.use_default: val = self.default else: raise SettingNotSet( '%s.%s is not in your LIVESETTINGS_OPTIONS' % (self.group.key, key)) else: try: val = self.setting.value except SettingNotSet, sns: if self.localized and lang == django_settings.LANGUAGE_CODE: try: unlocalized_setting = find_setting( self.group.key, self.key) return unlocalized_setting.value except SettingNotSet: pass if self.use_default: val = self.default if overrides: # maybe override the default grp = overrides.get(self.group.key, {}) if grp.has_key(key): val = grp[self.key] else: val = NOTSET except AttributeError, ae: log.error("Attribute error: %s", ae) log.error("%s: Could not get _value of %s", key, self.setting) raise (ae)
def get_editor_value(self, language_code): setting = None try: setting = self.get_setting(language_code) except SettingNotSet: if language_code == django_settings.LANGUAGE_CODE: try: setting = find_setting(self.group.key, self.key) except SettingNotSet: pass if setting: raw_value = setting.value else: raw_value = self.get_default_editor_value(language_code) return self.to_python(raw_value)
def _value(self): use_db, overrides = get_overrides() lang = get_language() key = self.key if self.localized: key += '_' + format_setting_name(lang) if not use_db: try: val = overrides[self.group.key][key] except KeyError: if self.use_default: val = self.default else: raise SettingNotSet('%s.%s is not in your LIVESETTINGS_OPTIONS' % (self.group.key, key)) else: try: val = self.setting.value except SettingNotSet, sns: if self.localized and lang == django_settings.LANGUAGE_CODE: try: unlocalized_setting = find_setting(self.group.key, self.key) return unlocalized_setting.value except SettingNotSet: pass if self.use_default: val = self.default if overrides: # maybe override the default grp = overrides.get(self.group.key, {}) if grp.has_key(key): val = grp[self.key] else: val = NOTSET except AttributeError, ae: log.error("Attribute error: %s", ae) log.error("%s: Could not get _value of %s", key, self.setting) raise(ae)
def get_setting(self, language_code=None): key = self.key if self.localized and language_code: key += '_' + format_setting_name(language_code) return find_setting(self.group.key, key)
def _setting(self): key = self.key if self.localized: key += '_' + format_setting_name(get_language()) return find_setting(self.group.key, key)
def _setting(self): return find_setting(self.group.key, self.key)
def _value(self): use_db, overrides = get_overrides() lang = get_language() key = self.key if self.localized: key += '_' + format_setting_name(lang) if not use_db: try: val = overrides[self.group.key][key] except KeyError: if self.use_default: val = self.default else: raise SettingNotSet('%s.%s is not in your LIVESETTINGS_OPTIONS' % (self.group.key, key)) else: try: val = self.setting.value except SettingNotSet as sns: if self.localized and lang == django_settings.LANGUAGE_CODE: try: unlocalized_setting = find_setting(self.group.key, self.key) return unlocalized_setting.value except SettingNotSet: pass if self.use_default: val = self.default if overrides: # maybe override the default grp = overrides.get(self.group.key, {}) if grp.has_key(key): val = grp[self.key] else: val = NOTSET except AttributeError as ae: log.error("Attribute error: %s", ae) log.error("%s: Could not get _value of %s", key, self.setting) raise(ae) except Exception as e: global _WARN log.error(e) if str(e).find("configuration_setting") > -1: if not _WARN.has_key('configuration_setting'): log.warn('Error loading setting %s.%s from table, OK if you are in syncdb', self.group.key, key) _WARN['configuration_setting'] = True if self.use_default: val = self.default else: raise ImproperlyConfigured("All settings used in startup must have defaults, %s.%s does not", self.group.key, key) else: import traceback traceback.print_exc() log.warn("Problem finding settings %s.%s, %s", self.group.key, key, e) raise SettingNotSet("Startup error, couldn't load %s.%s" %(self.group.key, key)) return val
def get_setting(self, language_code=None): key = self.key if self.localized and language_code: key += '_' + language_code.upper() return find_setting(self.group.key, key)
def _setting(self): key = self.key if self.localized: key += '_' + get_language().upper() return find_setting(self.group.key, key)
def _value(self): use_db, overrides = get_overrides() lang = get_language() key = self.key if self.localized: key += '_' + format_setting_name(lang) if not use_db: try: val = overrides[self.group.key][key] except KeyError: if self.use_default: val = self.default else: raise SettingNotSet( '%s.%s is not in your LIVESETTINGS_OPTIONS' % (self.group.key, key)) else: try: val = self.setting.value except SettingNotSet as sns: if self.localized and lang == django_settings.LANGUAGE_CODE: try: unlocalized_setting = find_setting( self.group.key, self.key) return unlocalized_setting.value except SettingNotSet: pass if self.use_default: val = self.default if overrides: # maybe override the default grp = overrides.get(self.group.key, {}) if grp.has_key(key): val = grp[self.key] else: val = NOTSET except AttributeError as ae: log.error("Attribute error: %s", ae) log.error("%s: Could not get _value of %s", key, self.setting) raise (ae) except Exception as e: global _WARN log.error(e) if str(e).find("configuration_setting") > -1: if not _WARN.has_key('configuration_setting'): log.warn( 'Error loading setting %s.%s from table, OK if you are in syncdb', self.group.key, key) _WARN['configuration_setting'] = True if self.use_default: val = self.default else: raise ImproperlyConfigured( "All settings used in startup must have defaults, %s.%s does not", self.group.key, key) else: import traceback traceback.print_exc() log.warn("Problem finding settings %s.%s, %s", self.group.key, key, e) raise SettingNotSet("Startup error, couldn't load %s.%s" % (self.group.key, key)) return val