Beispiel #1
0
def show_post_detail(post_id):
    """show the details of the post (post description, choices available), users' votes on it and comments;
    User can also vote on the questions"""
    post = Post.get_post_by_id(post_id)
    choices = Choice.get_choices_by_post_id(post_id)
    viewer_id = session.get('loggedin', None)
    if_voted = None
    if viewer_id:
        if_voted = post.check_choice_on_post_by_user_id(viewer_id)

    vote_dict, total_votes, chart_dict = post.count_votes()
    bar_chart_gender = post.bar_chart_gender()
    geochart = post.count_votes_by_location()
    bar_chart_age = post.count_votes_by_age()

    comments = Comment.get_comments_by_post_id(post_id)
    tag_names = [tag.tag_name for tag in Tag.get_tags_by_post_id(post_id)]
    post_ids = session.get("post_ids", None)
    state = post.state  # this gives a choice_id or Null, for displaying the decision the author has made
    decision = None
    if state:
        decision = Choice.get_choice_by_id(state)

    if if_voted:
        return render_template('post_details.html', post=post, choices=choices, vote_dict=vote_dict,
                               comments=comments, total_votes=total_votes, tag_names=tag_names,
                               post_ids=post_ids, chart_dict=chart_dict, decision=decision,
                               bar_chart_gender=bar_chart_gender,
                               geochart=geochart, bar_chart_age=bar_chart_age)
    else:
        return render_template('post_details.html', post=post, choices=choices, comments=comments, post_ids=post_ids,
                               tag_names=tag_names, total_votes=total_votes)