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 edit_handler(response, list_id): user_id = util.get_current_user_id(response) list = List.find(list_id) if not list.author == user_id: raise Exception response.write(templater.render("templates/edit.html", mist = list, page_title = "Edit", site_title = "M'lists", fail=response.get_field('fail', '')))
def view_handler(response, list_id): list = List.find(list_id) try: user_id = util.get_current_user_id(response) except Exception as e: user_id = None response.write(templater.render("templates/view_list.html", mist = list, page_title = list.name, site_title = "M'lists", user_id=user_id, image_fetcher=IMDB.fetch_image))
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')