def removeOrCancel(self, uService): if uService.isUsable() or State.isRemovable(uService.state): return self.remove(uService) elif uService.isPreparing(): return self.cancel(uService) else: raise OperationException(_('Can\'t remove nor cancel {0} cause its states don\'t allow it'))
def remove(self, uService): """ Removes a uService element @return: the uService removed (marked for removal) """ with transaction.atomic(): uService = UserService.objects.select_for_update().get( id=uService.id) logger.debug('Removing uService {0}'.format(uService)) if uService.isUsable() is False and State.isRemovable( uService.state) is False: raise OperationException( _('Can\'t remove a non active element')) uService.setState(State.REMOVING) logger.debug("***** The state now is {}".format( State.toString(uService.state))) uService.setInUse( False ) # For accounting, ensure that it is not in use right now uService.save() ci = uService.getInstance() state = ci.destroy() UserServiceOpChecker.makeUnique(uService, ci, state)
def remove(self, uService): ''' Removes a uService element @return: the uService removed (marked for removal) ''' uService = UserService.objects.get(id=uService.id) logger.debug('Removing uService {0}'.format(uService)) if uService.isUsable() is False and State.isRemovable( uService.state) is False: raise OperationException(_('Can\'t remove a non active element')) ci = uService.getInstance() state = ci.destroy() uService.setState(State.REMOVING) UserServiceOpChecker.makeUnique(uService, ci, state)