This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

top yea/nay/all posts

  • Loading branch information...
amyrlam committed Aug 18, 2013
1 parent 9e7fd4c commit b71defc10191e4bff0a5d57a7dc61c10d43d4216
Showing with 27 additions and 9 deletions.
  1. +15 −6 app/templates/posts.html
  2. +12 −3 app/views.py
@@ -1,18 +1,27 @@
{% extends "base.html" %}
{% block content %}

<p><a href="{{ url_for('newpost', ailment_id=ailment.id, remedy_id=remedy.id) }}">Write New Post</a>
{% macro show_post(post) %}
<p class="upvote" id="up_{{post.id}}">Upvote</p>
<p class="downvote" id="down_{{post.id}}">Downvote</p>
<p><b>Author:</b> {{ post.author.nickname }} <b>Date:</b> {{ post.timestamp }} </p>
<p><b>Category:</b> {{ post.category_str }}</p>
<p><b>Score:</b> {{ post.score }}</p>
<p>{{ post.body }}</p>
{% endmacro %}

<p><a href="{{ url_for('newpost', ailment_id=ailment.id, remedy_id=remedy.id) }}">Write New Post</a>
<h1>{{ ailment.name }}</h1>
<h2>{{ remedy.name }}</h2>
<h3> Best Yay</h3>
{{ show_post(top_yea)}}
<h3>Best Nay</h3>
{{ show_post(top_nay)}}
<h3>All Posts</h3>
<ul>
{% for post in posts %}
<li>
<p class="upvote" id="up_{{post.id}}">Upvote</p>
<p class="downvote" id="down_{{post.id}}">Downvote</p>
<p>{{ post.author.nickname }}</p>
<p>{{ post_categories[post.category_str] }}
<p>{{ post.body }}</p>
{{ show_post(post) }}
</li>
{% endfor %}
</ul>
@@ -210,10 +210,19 @@ def posts(ailment_id, remedy_id):
# how to write strings in sqlalchemy
# SELECT nickname, timestamp, category_str, body, rank() OVER (PARTITION BY category_str ORDER BY timestamp DESC) FROM post LIMIT 5;

posts = Post.query.filter_by(ailmenttoremedy_id = ailmenttoremedy.id)

top_yea = Post.query.filter_by(ailmenttoremedy_id=ailmenttoremedy.id, category_int=0).order_by(Post.score.desc()).first()
top_nay = Post.query.filter_by(ailmenttoremedy_id=ailmenttoremedy.id, category_int=1).order_by(Post.score.desc()).first()
posts = Post.query.filter_by(ailmenttoremedy_id=ailmenttoremedy.id)
#posts = posts[:5]

# query = db.session.query(Post, db.func.rank().over(partition_by=Post.category_str, order_by=Post.score.desc()))
# query = db.session.query(Post, db.func.rank().over(partition_by=Post.category_str, order_by=Post.score.desc()))
# posts = [result.Post for result in query]
#partition_by=Post.category_str).order_by(Post.score.desc()) # most positive
#posts = posts[:5]

# .order_by("category_int") #.paginate(1, POSTS_PER_PAGE, False)
return render_template('posts.html', ailment=ailment, remedy=remedy, posts=posts, post_categories=post_categories)
return render_template('posts.html', ailment=ailment, remedy=remedy, top_yea=top_yea, top_nay=top_nay, posts=posts, post_categories=post_categories)

@app.route('/vote', methods = ['POST'])
def vote():

0 comments on commit b71defc

Please sign in to comment.