def iterSections(self, user=None): """ Yields: section, metadata, values """ user = primary_uid(user) values = self.db.loadConfigsForUser(user) # Every section needs to be json decoded for section, data in values.items(): try: values[section] = json.loads(data) if data else {} except ValueError: values[section] = {} self.core.print_exc() for name, config in self.config.iteritems(): yield name, config, values[name] if name in values else {}
def set(self, section, option, value, sync=True, user=None): """ set config value """ changed = False if section in self.parser and (not user or (user and user.isAdmin())): changed = self.parser.set(section, option, value, sync) else: # associated id user = primary_uid(user) data = self.config[section].config[option] value = from_string(value, data.type) old_value = self.get(section, option) # Values will always be saved to db, sync is ignored if value != old_value: changed = True self.values[user, section][option] = value self.saveValues(user, section) if changed: self.core.evm.dispatchEvent("configChanged", section, option, value) return changed
def get(self, section, option, user=None): """get config value, core config only available for admins. if user is not valid default value will be returned""" # Core config loaded from parser, when no user is given or he is admin if section in self.parser and (not user or(user and user.isAdmin())): return self.parser.get(section, option) else: # We need the id and not the instance # Will be None for admin user and so the same as internal access user = primary_uid(user) try: # Check if this config exists # Configs without meta data can not be loaded! data = self.config[section].config[option] self.loadValues(user, section) return self.values[user, section][option] except KeyError: pass # Returns default value later return self.config[section].config[option].default
def user(self): return primary_uid(self.owner)