Exemple #1
0
    def validate(self, doc):
        """
        This method is in charge of validating that the setting key is a valid
        key, and that for that key, the provided value is valid. It first
        allows plugins to validate the setting, but if none of them can, it
        assumes it is a core setting and does the validation here.
        """
        key = doc['key']

        funcName = 'validate' + camelcase(key)
        if callable(getattr(self, funcName, None)):
            getattr(self, funcName)(doc)
        else:
            raise ValidationException('Invalid setting key "%s".' % key, 'key')

        return doc
Exemple #2
0
    def validate(self, doc):
        """
        This method is in charge of validating that the setting key is a valid
        key, and that for that key, the provided value is valid. It first
        allows plugins to validate the setting, but if none of them can, it
        assumes it is a core setting and does the validation here.
        """
        key = doc['key']

        funcName = 'validate'+camelcase(key)
        if callable(getattr(self, funcName, None)):
            getattr(self, funcName)(doc)
        else:
            raise ValidationException(
                'Invalid setting key "%s".' % key, 'key')

        return doc
Exemple #3
0
    def getDefault(self, key):
        """
        Retrieve the system default for a value.

        :param key: The key identifying the setting.
        :type key: str
        :returns: The default value if the key is present in both SettingKey
                  and referenced in SettingDefault; otherwise None.
        """
        default = None
        if key in SettingDefault.defaults:
            default = SettingDefault.defaults[key]
        else:
            funcName = 'default'+camelcase(key)
            if callable(getattr(self, funcName, None)):
                default = getattr(self, funcName)()
        return default
Exemple #4
0
    def getDefault(self, key):
        """
        Retrieve the system default for a value.

        :param key: The key identifying the setting.
        :type key: str
        :returns: The default value if the key is present in both SettingKey
                  and referenced in SettingDefault; otherwise None.
        """
        default = None
        if key in SettingDefault.defaults:
            default = SettingDefault.defaults[key]
        else:
            funcName = 'default' + camelcase(key)
            if callable(getattr(self, funcName, None)):
                default = getattr(self, funcName)()
        return default