def set_global_setting(key, value, description=None): """ Set a global setting in the DbSetting table (therefore, stored at the DB level). """ from aiida.backends.djsite.db.models import DbSetting # Before storing, validate the key DbSetting.validate_key(key) # This also saves in the DB DbSetting.set_value(key, value, other_attribs={"description": description})
def delete(self, key): """Delete the setting with the given key. :param key: the key identifying the setting :raises: `~aiida.common.exceptions.NotExistent` if the settings does not exist """ from aiida.backends.djsite.db.models import DbSetting self.validate_table_existence() try: DbSetting.del_value(key=key) except KeyError: raise NotExistent(f'setting `{key}` does not exist') from KeyError
def set_global_setting(key, value, description=None): """ Set a global setting in the DbSetting table (therefore, stored at the DB level). """ from aiida.backends.djsite.db.models import DbSetting # Before storing, validate the key DbSetting.validate_key(key) # This also saves in the DB try: DbSetting.set_value(key, value, other_attribs={"description": description}) except IntegrityError as exception: raise UniquenessError(exception)
def del_global_setting(key): """ Return the value of the given setting, or raise a KeyError if the setting is not present in the DB. :raise KeyError: if the setting does not exist in the DB """ from aiida.backends.djsite.db.models import DbSetting from django.core.exceptions import ObjectDoesNotExist try: setting = DbSetting.objects.get(key=key) except ObjectDoesNotExist: raise KeyError("No global setting with key={}".format(key)) # This does not raise exceptions DbSetting.del_value(key=key)
def set(self, key, value, description=None): """Return the settings with the given key. :param key: the key identifying the setting :param value: the value for the setting :param description: optional setting description """ from aiida.backends.djsite.db.models import DbSetting self.validate_table_existence() validate_attribute_key(key) other_attribs = dict() if description is not None: other_attribs['description'] = description DbSetting.set_value(key, value, other_attribs=other_attribs)