Skip to content

Commit

Permalink
Allow permalinks to individual comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sjuxax committed Dec 15, 2011
1 parent 65dced6 commit 69981d2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 6 additions & 2 deletions raggregate/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def get_endpoints_from_page_num(page_num, per_page):
end = per_page
return {'start': start, 'end': end}

def get_comments_by_story_id(id, organize_parentage = False, page_num = 1, per_page = 30, sort = 'new'):
def get_comments(id, organize_parentage = False, page_num = 1, per_page = 30, sort = 'new', target = 'story', target_id = None):
if not organize_parentage:
return dbsession.query(Comment).filter(Comment.submission_id == id).all()
else:
Expand All @@ -358,7 +358,11 @@ def get_comments_by_story_id(id, organize_parentage = False, page_num = 1, per_p
tree[id] = []
dex = {}
all_comments = dbsession.query(Comment).filter(Comment.submission_id == id).all()
roots = dbsession.query(Comment).filter(Comment.submission_id == id).filter(Comment.submission_id == Comment.parent_id)
if target == 'story':
roots = dbsession.query(Comment).filter(Comment.submission_id == id).filter(Comment.submission_id == Comment.parent_id)
else:
roots = dbsession.query(Comment).filter(Comment.submission_id == id).filter(target_id == Comment.id)

max_roots = count_sa_obj(roots)

if sort == 'new':
Expand Down
5 changes: 4 additions & 1 deletion raggregate/views/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,10 @@ def full(request):
page_num = 1

# comments returns a dict; see queries.py
comments = queries.get_comments_by_story_id(sub_id, organize_parentage=True, page_num = page_num, per_page = per_page, sort = sort)
if 'comment_perma' not in prm:
comments = queries.get_comments(sub_id, organize_parentage=True, page_num = page_num, per_page = per_page, sort = sort)
else:
comments = queries.get_comments(sub_id, organize_parentage=True, page_num = page_num, per_page = per_page, sort = sort, target = 'comment', target_id = prm['comment_perma'])

for c in comments['comments']:
#@TODO: Don't do this on every load on a real deployment
Expand Down

0 comments on commit 69981d2

Please sign in to comment.