Esempio n. 1
0
def edit_item(response, username, item_id):
	try:
		current_user = User.find(username)
	except UserNotFound:
		handle_error(response, message="Unable to find the specified user.")
		return

	if response.request.method == "POST":
		product = Product.find(item_id)

		product.name = response.get_field('wish')
		product.image = response.get_field('image') or '/static/images/gift_box.png'
		product.link = response.get_field('website') or None
		product.description = response.get_field('description') or None
		product.price = response.get_field('price') or None

		product.save()
		response.redirect("/users/" + username)
		return

	user_lists = current_user.get_wishlists()
	if not user_lists:
		handle_error(response, message="Unable to find the given user's wishlist.")
		return

	current_wishlist = user_lists[0]

	scope = {
		"username": username,
		"listname": current_wishlist.list_name,
		"logged_in": current_user,
		"current_user_fullname": display_name(current_user),
		"is_current_users_wishlist_page": is_current_users_wishlist_page(response, username),
		"product": Product.find(item_id)
	}

	response.write(epyc.render("templates/edit_item.html", scope))