示例#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))
示例#2
0
def add_item(response, username):
	user_lists = User.find(username).get_wishlists()
	current_wishlist = user_lists[0]

	details = {
		"name": response.get_field('wish'),
		"image": response.get_field('image') or '/static/images/gift_box.png',
		"link": response.get_field('website'),
		"description": response.get_field('description'),
		"price": response.get_field('price')
	}

	encoded_string = ""
	if details['name'] != "":
		product = Product.create(**details)
		current_wishlist.add_item(product)
	else:
		encoded_string = urlencode({'error': "0"})

	response.redirect('/users/' + username + "?" + encoded_string)
示例#3
0
def search(response):
	search = response.get_field("q")
	logged_in = get_current_user(response)

	types = {
		"people": 0,
		"items": 1
	}

	tp = types.get(response.get_field("t"), 0)

	if search:
		if tp == types['people']:
			items = User.search(search)
		else:
			items = Product.search(search)

		scope = {
			"query": search,
			"results": items,
			"tp": tp,
			"types": types,
			"logged_in": get_current_user(response)
		}

		app_log.info("[%s found for '%s'] %s" % (response.get_field('t'), search, items))
		response.write(epyc.render("templates/search.html", scope))

	else:
		scope = {
			"query": "",
			"results": [],
			"tp": tp,
			"types": types,
			"logged_in": get_current_user(response)
		}

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