Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def alter_subpool_assigned_items(self, lock, quantity):
- """Choose subpool for given lock and alter it's assigned items using given quantity.
- quantity can be both positive and negative
- :param: quantity: `int` quantity to use for alteration.
- """
- session = inspect(self).session
- expression = (
- Subpool.__table__.update()
- .values(locked=Subpool.locked + quantity, id=func.last_insert_id(Subpool.id))
- .where(Subpool.pool == self)
- )
- if quantity > 0:
- expression = expression.where(Subpool.locked < Subpool.availability | Subpool.availability.is_(None))
- if (
- session.execute(
- unicode(expression.compile(compile_kwargs={"literal_binds": True}))
- + ' ORDER BY {0} LIMIT 1'.format(Subpool.locked.name), dict(param_1=self.id)).rowcount != 1
- ):
- if quantity > 0:
- raise NotEnoughSubpoolAvailabilityError()
- else:
- raise NotEnoughSubpoolLockedError()
- lock.subpool_id = session.execute(func.last_insert_id()).scalar()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement