def _handleComplementingCartsNearEnclosure(self, user, cart_ids): """ Updates state of all carts other than given list, assuming given list is of carts within range of Enclosure. i.e. carts to be treated are ones not in Enclosure sight. """ complementing_carts = self._fetchComplementingCarts(cart_ids) for cart in complementing_carts: if cart.rental_state == cart.RentalState.ASSIGNED_IN_ENCLOSURE: cart.rental_state = cart.RentalState.RENTED cart.enclosed = False renting_user = cart.last_seen_by renting_user.cart = cart renting_user.save() cart.renting_user = renting_user cart.renting_time = datetime.datetime.now() res_dict = { "msg": ("Cart '%s' has been rented to user '%s'" % (cart.cart_id, cart.renting_user)), "code": 3, } elif cart.rental_state == cart.RentalState.WAITING: cart.rental_state = cart.RentalState.STOLEN cart.enclosed = False res_dict = {"msg": ("Cart '%s' has been stolen! Thief's identity unknown :(" % cart.cart_id), "code": 4} elif cart.rental_state == cart.RentalState.RENTED: if cart.max_renting_time and cart.renting_time > cart.max_renting_time: cart.rental_state.STOLEN # TODO differentiate between message with little time left to time past if self.fine_amount > 0: fine_user(user.username(), self.fine_amount) res_dict = { "msg": ( "Cart '%s' has been stolen! User '%s' - you BASTARD!" % (cart.cart_id, cart.renting_user) ), "code": 4, } cart.state_last_updated = datetime.datetime.now() cart.last_seen_by = user cart.save() print res_dict # TODO - push notification user.notifications.append(res_dict) user.save()
def _handleComplementingCartsNearEnclosure(self, user, cart_ids): """ Updates state of all carts other than given list, assuming given list is of carts within range of Enclosure. i.e. carts to be treated are ones not in Enclosure sight. """ complementing_carts = self._fetchComplementingCarts(cart_ids) for cart in complementing_carts: if cart.rental_state == cart.RentalState.ASSIGNED_IN_ENCLOSURE: cart.rental_state = cart.RentalState.RENTED cart.enclosed = False renting_user = cart.last_seen_by renting_user.cart = cart renting_user.save() cart.renting_user = renting_user cart.renting_time = datetime.datetime.now() res_dict = {"msg": ("Cart '%s' has been rented to user '%s'" % (cart.cart_id, cart.renting_user)), "code": 3} elif cart.rental_state == cart.RentalState.WAITING: cart.rental_state = cart.RentalState.STOLEN cart.enclosed = False res_dict = {"msg": ("Cart '%s' has been stolen! Thief's identity unknown :(" % cart.cart_id), "code": 4} elif cart.rental_state == cart.RentalState.RENTED: if cart.max_renting_time and cart.renting_time > cart.max_renting_time: cart.rental_state.STOLEN # TODO differentiate between message with little time left to time past if self.fine_amount > 0: fine_user(user.username(), self.fine_amount) res_dict = {"msg": ("Cart '%s' has been stolen! User '%s' - you BASTARD!" % (cart.cart_id, cart.renting_user)), "code": 4} cart.state_last_updated = datetime.datetime.now() cart.last_seen_by = user cart.save() print res_dict # TODO - push notification user.notifications.append(res_dict) user.save()
def fine(): fine_user(request.args.get('who'), 10) return "Fined"