def get_list(self, filters=None):
     try:
         query = self.get_query()
         return self.apply_filters(query, filters).all()
     except exc.SQLAlchemyError as error:
         logger.exception(error)
         raise ForbiddenError(detail='Error while getting {} list.'.format(
             self.instance_name))
 def delete(self, id):
     obj = self.get_detail(id)
     try:
         self.session.delete(obj)
         self.session.flush()
     except exc.SQLAlchemyError as error:
         logger.exception(error)
         raise ForbiddenError(detail='Error while deleting {}.'.format(self.instance_name))
 def get_detail(self, id):
     try:
         return self.get_query().filter(self.model.id == id).one()
     except orm_exc.NoResultFound:
         raise exceptions.ObjectNotFound(source={'parameter': 'id'},
                                         detail='{} {} not found.'.format(self.instance_name.capitalize(), id))
     except exc.SQLAlchemyError as error:
         logger.exception(error)
         raise ForbiddenError(detail='Error while getting {} details.'.format(self.instance_name))
 def create(self, data, **kwargs):
     obj = self.build(data)
     self.session.add(obj)
     try:
         self.session.flush()
         return obj
     except exc.SQLAlchemyError as error:
         logger.exception(error)
         raise ForbiddenError(detail='{} could not be created.'.format(self.instance_name.capitalize()))
 def update(self, data, **kwargs):
     id = data['id']
     obj = self.get_detail(id)
     for key, value in data.items():
         self.update_attribute(obj, key, value)
     try:
         self.session.flush()
         return obj
     except exc.SQLAlchemyError as error:
         logger.exception(error)
         raise ForbiddenError(detail='Error while updating {}.'.format(self.instance_name))