示例#1
0
    def get(self, account=None):
        # Verify get() call is valid
        if self.scope == 'account':
            if account is None:
                raise ValueError(
                    'Account option requires the "account" parameter')

            if not self._validate_account(account):
                raise ValueError('Invalid value for "account" parameter: %r' %
                                 account)

        if self.scope == 'server' and account is not None:
            raise ValueError(
                "Server option can't be called with the \"account\" parameter")

        # Load option from database
        option, _ = ConfigurationOption.get_or_create(account=account or 0,
                                                      key=self.key,
                                                      defaults={
                                                          'value':
                                                          self._pack(
                                                              self.default),
                                                      })

        return self._clone(option)
示例#2
0
    def update(self, value, account=None, emit=True):
        if self.scope == 'account':
            if account is None:
                raise ValueError(
                    'Account option requires the "account" parameter')

            if not self._validate_account(account):
                raise ValueError('Invalid value for "account" parameter: %r' %
                                 account)

        if self.scope == 'server' and account is not None:
            raise ValueError(
                "Server option can't be called with the \"account\" parameter")

        ConfigurationOption.insert(
            account=account or 0, key=self.key,
            value=self._pack(value)).upsert(upsert=True).execute()

        # Emit database change to handler (if enabled)
        if emit:
            self._preferences.on_database_changed(self.key,
                                                  value,
                                                  account=account)
示例#3
0
    def update(self, value, account=None, emit=True):
        if self.scope == 'account':
            if account is None:
                raise ValueError('Account option requires the "account" parameter')

            if not self._validate_account(account):
                raise ValueError('Invalid value for "account" parameter: %r' % account)

        if self.scope == 'server' and account is not None:
            raise ValueError("Server option can't be called with the \"account\" parameter")

        ConfigurationOption.insert(
            account=account or 0,
            key=self.key,

            value=self._pack(value)
        ).upsert(
            upsert=True
        ).execute()

        # Emit database change to handler (if enabled)
        if emit:
            self._preferences.on_database_changed(self.key, value, account=account)
示例#4
0
    def get(self, account=None):
        # Verify get() call is valid
        if self.scope == 'account':
            if account is None:
                raise ValueError('Account option requires the "account" parameter')

            if not self._validate_account(account):
                raise ValueError('Invalid value for "account" parameter: %r' % account)

        if self.scope == 'server' and account is not None:
            raise ValueError("Server option can't be called with the \"account\" parameter")

        # Load option from database
        option, _ = ConfigurationOption.get_or_create(
            account=account or 0,
            key=self.key,

            defaults={
                'value': self._pack(self.default),
            }
        )

        return self._clone(option)