def itemDelete(redirect_category_id, item_id=None): """Handles two possibilities: 1) User clicks delete while on screen to create new item - reload to category list page. 2) User clicks delete while modifying an item - remove item from table and reload to parent category's page. """ if item_id is None: # User escaped from new item process return redirect('/') else: item = Item.by_id(item_id) if item: session.delete(item) session.commit() return redirect('/category/' + redirect_category_id)
def itemValuesIfPresent(item_id=None): """Returns values from item table, if item_id exists; else empty strings Arg: item_id: if present, used to filter result. Returns: item_name: value from Item table or empty string category_id: value from Item table or empty string item_description: value from Item table or empty string """ item_name = "" category_id = "" item_description = "" if item_id: item = Item.by_id(item_id) if item: item_name = item.item_name category_id = item.category_id item_description = item.item_description return item_name, category_id, item_description