def idea_vote(request): post_data = request.POST target = post_data.get('target') session = DBSession() idea = Idea.get_by_id(target) voter_username = authenticated_userid(request) voter = User.get_by_username(voter_username) if post_data.get('form.vote_hit'): vote = 'hit' idea.hits += 1 idea.author.hits += 1 voter.delivered_hits += 1 elif post_data.get('form.vote_miss'): vote = 'miss' idea.misses += 1 idea.author.misses += 1 voter.delivered_misses += 1 idea.voted_users.append(voter) session.flush() redirect_url = route_url('idea', request, idea_id=idea.idea_id) response = HTTPMovedPermanently(location=redirect_url) return response
def idea_vote(request): post_data = request.POST target = post_data.get('target') session = DBSession() idea = Idea.get_by_id(target) voter_username = authenticated_userid(request) voter = User.get_by_username(voter_username) if post_data.get('form.vote_hit'): vote = 'hit' idea.hits += 1 idea.author.hits += 1 voter.delivered_hits += 1 elif post_data.get('form.vote_miss'): vote = 'miss' idea.misses += 1 idea.author.misses += 1 voter.delivered_misses += 1 idea.voted_users.append(voter) session.flush() redirect_url = route_url('idea', request, idea_id=idea.idea_id) response = HTTPMovedPermanently(location=redirect_url) return response
def idea_vote(request): post_data = request.POST target = post_data.get('target') session = DBSession() idea = Idea.get_by_id(target, with_joinedload=False) voter_username = authenticated_userid(request) voter = User.get_by_username(voter_username) redirect_url = route_url('idea', request, idea_id=idea.idea_id) response = HTTPMovedPermanently(location=redirect_url) if voter.user_id == idea.author_id: request.session.flash(u'You cannot vote on your own ideas.') return response if post_data.get('form.vote_hit'): idea.vote(voter, True) elif post_data.get('form.vote_miss'): idea.vote(voter, False) session.flush() return response
def idea_vote(request): post_data = request.POST target = post_data.get("target") session = DBSession() idea = Idea.get_by_id(target, with_joinedload=False) voter_username = authenticated_userid(request) voter = User.get_by_username(voter_username) redirect_url = request.route_url("idea", idea_id=idea.idea_id) response = HTTPMovedPermanently(location=redirect_url) if voter.user_id == idea.author_id: request.session.flash(u"You cannot vote on your own ideas.") return response if post_data.get("form.vote_hit"): idea.vote(voter, True) elif post_data.get("form.vote_miss"): idea.vote(voter, False) session.flush() return response