示例#1
0
def results(key, expired=None):
    my_votes = {}
    my_comments = {}
    user_comments = {}
    category = Category.get(key)
    items = Item.all().ancestor(category).order("-wins").order("losses")
    count = 0
    for i in items:
        item = (
            UserVote.all().ancestor(i).order("-wins").order("losses").filter("voter =", users.get_current_user()).get()
        )
        if not item:
            my_votes[count] = [i.title, "-", "-"]
        else:
            my_votes[count] = [i.title, item.wins, item.losses]  # the count helps maintain the order -wins and losses
        count += 1

    for c in items:
        user_comments[c.title] = UserComment.all().ancestor(c)
        my_comment = UserComment.all().ancestor(c).filter("commenter =", users.get_current_user()).get()
        if my_comment:
            my_comments[c.title] = my_comment.comment
    return render_template(
        "results.html",
        items=items,
        key=key,
        title=category.title,
        owner=category.owner.email(),
        my_votes=my_votes,
        my_comments=my_comments,
        user_comments=user_comments,
        expired=expired,
    )
示例#2
0
def post_comment():
	key = request.form.get('key')
	item_name = request.form.get('item')
	user_comment = request.form.get('comment')
	category = Category.get(key)
	item = Item.all().ancestor(category).filter('title =',item_name).get()
	comment = UserComment.all().ancestor(item.key()).filter('commenter =',users.get_current_user()).get()
	if comment:
		return Response(status=400)
	else:
		comment = UserComment(parent=item.key(),comment=user_comment,commenter=users.get_current_user())
		comment.put()
		return Response(status=200)
示例#3
0
def post_comment():
    key = request.form.get("key")
    item_name = request.form.get("item")
    user_comment = request.form.get("comment")
    category = Category.get(key)
    item = Item.all().ancestor(category).filter("title =", item_name).get()
    comment = UserComment.all().ancestor(item.key()).filter("commenter =", users.get_current_user()).get()
    if comment:
        return Response(status=400)
    else:
        comment = UserComment(parent=item.key(), comment=user_comment, commenter=users.get_current_user())
        comment.put()
        return Response(status=200)
示例#4
0
def results(key,expired=None):
	my_votes = {}
	my_comments = {}
	user_comments = {}
	category = Category.get(key)
	items = Item.all().ancestor(category).order('-wins').order('losses')
	count = 0
	for i in items:
		item = UserVote.all().ancestor(i).order('-wins').order('losses').filter('voter =', users.get_current_user()).get()
		if not item:
			my_votes[count] = [i.title, "-", "-"]
		else:
			my_votes[count] = [i.title, item.wins, item.losses] # the count helps maintain the order -wins and losses
		count += 1

	for c in items:
		user_comments[c.title] = UserComment.all().ancestor(c)
		my_comment = UserComment.all().ancestor(c).filter('commenter =',users.get_current_user()).get()
		if my_comment:
			my_comments[c.title] = my_comment.comment
	return render_template('results.html',items=items, key=key, title=category.title, owner=category.owner.email(), my_votes=my_votes, my_comments=my_comments, user_comments=user_comments,expired=expired)