def delete_item(user, item_id): """ Attempts to delete the item with the specified id, provided that the provided user is its owner """ item = Item.retrieve_with_write_permission(user, item_id) item.delete()
def move_item(user, item_id, location_id): """ Attempts to move an item with the specified id to a location with the specified id. """ item = Item.retrieve_with_write_permission(user, item_id) location = Location.retrieve_with_write_permission(user, location_id) item.location = location item.save()
def open_item(user, item_id, open_date): """ Attempts to open the provided item, provided that it is not already open. """ item = Item.retrieve_with_write_permission(user, item_id) #if already opened, do nothing if item.opened: return try: item.opened_date = open_date item.save() except django.core.exceptions.ValidationError: raise inventory.exceptions.InvalidDateError(open_date)