def remove_by_id(self, identifier, commit=True): type_ = self.get_by_id(identifier) if type_.table_id: try: BrokerBase.remove_by_id(self, identifier, commit) except IntegrityException: raise IntegrityException( 'Item is still referenced cannot delete it') else: raise IntegrityException('Cannot remove the None element')
def update_by_attribute(self, attribute, commit=True): """ updates one Value instance with the information of the given attribute :param attribute: the attribute in context :type attribute: Attribute :returns : Value """ errors = not attribute.validate() if errors: raise ValidationException(u'Attribute to be updated is invalid') self.__set_class_by_attribute(attribute) value = self.__convert_attr_value_to_value(attribute, False) BrokerBase.update(self, value, commit)
def insert(self, instance, commit=True, validate=True): """ overrides BrokerBase.insert """ errors = False if validate: errors = not instance.validate() if errors: raise ValidationException(u'User to be inserted is invalid') try: BrokerBase.insert(self, instance, commit, validate=False) self.do_commit(commit) except sqlalchemy.exc.SQLAlchemyError as error: self.session.rollback() raise BrokerException(error)
def get_all(self): users = BrokerBase.get_all(self) result = list() for user in users: if user.username != 'admin': result.append(user) return result
def update(self, instance, commit=True, validate=True): """ overrides BrokerBase.insert """ errors = not instance.validate() if errors: raise ValidationException(u'User to be updated is invalid') if instance.password != 'EXTERNALAUTH': # Don't update if the password is already a hash if re.match('^[0-9a-f]{40}$', instance.password) is None: if not errors: instance.password = hashSHA1(instance.password, instance.username) try: BrokerBase.update(self, instance, commit, validate=False) self.do_commit(commit) except sqlalchemy.exc.SQLAlchemyError as error: self.session.rollback() raise BrokerException(error)
def __init__(self, session): BrokerBase.__init__(self, session)
def __init__(self, session): BrokerBase.__init__(self, session) self.__clazz = StringValue
def update(self, instance, commit=True, validate=True): type_ = self.get_by_id(instance.identifier) if type_.table_id: BrokerBase.update(self, instance, commit) else: raise IntegrityException('Cannot update the None element')