def edit_post_handler(response, list_id): # Put this early otherwise all the items are removed! if response.get_field("title", "") == "": response.redirect("/list/{}/edit?fail=list_title_empty".format(list_id)) return a_list = List.find(list_id) user_id = util.get_current_user_id(response) if not a_list.author == user_id: raise Exception a_list.name = response.get_field("title", "") a_list.save() # delete the old list items before adding the new ones for old_item in ListContent.find_by_list_id(list_id): ListContent.delete(list_id, old_item.item_order) list_items = response.get_arguments("list_item") list_items = filter(None, list_items) for i, item in enumerate(list_items): list_content = ListContent.create(a_list.id, i, item) response.redirect('/dashboard')
def delete_handler(response, list_id): a_list = List.find(list_id) user_id = util.get_current_user_id(response) if not a_list.author == user_id: raise Exception # delete the old list items before adding the new ones for old_item in ListContent.find_by_list_id(list_id): ListContent.delete(list_id, old_item.item_order) a_list.delete() response.redirect('/dashboard')
def create_post_handler(response): title = response.get_field("title", "") if title.strip() == "": response.redirect("/create?fail=list_title_empty") return list_items = response.get_arguments("list_item") list_items = filter(None, list_items) a_list = List(title, util.get_current_user_id(response)) a_list.save() for i, item in enumerate(list_items): list_content = ListContent.create(a_list.id, i, item) response.redirect('/dashboard')