Esempio n. 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)
Esempio n. 2
0
def update_decision(post_id):
    post = Post.get_post_by_id(post_id)
    choice_id = request.form.get("choice_id")
    print choice_id, "this is choice_id"
    print type(choice_id), "this is the data type"
    post.update_decision(int(choice_id))
    if choice_id != "0":
        choice = Choice.get_choice_by_id(choice_id)
        decision_text = "The user has decided to go with: " + choice.choice_text
        decision_file = choice.file_name
    else:
        decision_text = "The author has made the decision but he/she likes to keep it secret"
        decision_file = ""

    return jsonify(decision_text=decision_text, decision_file=decision_file)