Esempio n. 1
0
 def insert_or_update_global(self, key, value, type, description,
                             can_override):
     '''
     Args:
         key -- string
         value -- mixed
         type -- instance of ConfigurationValueType
         description -- string
         can_override -- bool
     '''
     assert isinstance(type, ConfigurationValueType)
     value_str = Config.Option.serialize(value, type)
     try:
         option = Configuration.objects.get(key=key)
     except Configuration.DoesNotExist:
         # insert
         option = Configuration(key=key,
                                value=value_str,
                                description=description,
                                type=type,
                                can_override=can_override)
         option.save()
     else:
         # update
         option.value = value_str
         option.type = type
         option.description = description
         option.can_override = can_override
         option.save()
         del self._cached_data[key]
Esempio n. 2
0
 def insert_or_update_global(self, key, value, type, description, can_override):
     '''
     Args:
         key -- string
         value -- mixed
         type -- instance of ConfigurationValueType
         description -- string
         can_override -- bool
     '''
     assert isinstance(type, ConfigurationValueType)
     value_str = Config.Option.serialize(value, type)
     try:
         option = Configuration.objects.get(key=key)
     except Configuration.DoesNotExist:
         # insert
         option = Configuration(key=key, value=value_str, description=description, type=type, can_override=can_override)
         option.save()
     else:
         # update
         option.value = value_str
         option.type = type
         option.description = description
         option.can_override = can_override
         option.save()
         del self._cached_data[key]
Esempio n. 3
0
 def get_description(self, key):
     '''
     Gets description of given key.
     '''
     try:
         result = Configuration.objects.get(key=key)
     except Configuration.DoesNotExist, e:
         raise Configuration.DoesNotExist(e.args + (key, ))
Esempio n. 4
0
 def set_can_override(self, key, can_override):
     '''
     Sets whether key can be overriden.
     '''
     try:
         option = Configuration.objects.get(key=key)
     except Configuration.DoesNotExist, e:
         raise Configuration.DoesNotExist(e.args + (key, ))
Esempio n. 5
0
 def set_description(self, key, desc):
     '''
     Sets description of given key.
     Description is set in Configuration, so this option is not for normal users. Also no permissions are checked.
     '''
     try:
         result = Configuration.objects.get(key=key)
     except Configuration.DoesNotExist, e:
         raise Configuration.DoesNotExist(e.args + (key, ))
Esempio n. 6
0
    def get_type(self, key):
        '''
        Returns type of value associated with key.

        Args:
            key -- str
        '''
        try:
            result = Configuration.objects.select_related().get(key=key)
        except Configuration.DoesNotExist, e:
            raise Configuration.DoesNotExist(e.args + (key, ))
Esempio n. 7
0
 def set_type(self, key, type):
     '''
     Sets type for value for given key.
     Args:
         key -- str
         type -- instance of ConfigurationValueType
     '''
     assert isinstance(type, ConfigurationValueType)
     try:
         result = Configuration.objects.get(key=key)
     except Configuration.DoesNotExist, e:
         raise Configuration.DoesNotExist(e.args + (key, ))
Esempio n. 8
0
    def get_option(self, key):
        '''
        Returns Config.Option instance associated with key.

        Raises:
            Configuration.DoesNotExist, if key is not found.
        '''
        if key in self._cached_data:
            return self._cached_data[key]
        else:
            # look for key, if it exists at all
            try:
                Configuration.objects.get(key=key)
            except Configuration.DoesNotExist, e:
                raise Configuration.DoesNotExist(e.args + (key, ))
            # now we know that key is there
            self._fill_cache()
            assert key in self._cached_data, self._cached_data
            return self._cached_data[key]