diff options
Diffstat (limited to 'apioforum/thread.py')
-rw-r--r-- | apioforum/thread.py | 49 |
1 files changed, 2 insertions, 47 deletions
diff --git a/apioforum/thread.py b/apioforum/thread.py index a5862ba..6d2a6c6 100644 --- a/apioforum/thread.py +++ b/apioforum/thread.py @@ -17,23 +17,6 @@ POSTS_PER_PAGE = 28 class Thread(DBObj,table="threads"): fields = ["id","title","creator","created","updated","forum","poll"] - # maybe this should be on Post instead????? - @staticmethod - def which_page(post): - """ return what page of a thread the given post is on - - assumes post ids within a thread are monotonically increasing, which - is probably correct - """ - db = get_db() - amt_before = db.execute(""" - select count(*) as c from posts - where thread = ? and id < ?""", - (post.thread,post.id)).fetchone()['c'] - - page = 1+math.floor(amt_before/POSTS_PER_PAGE) - return page - def tags(self): db = get_db() tags = db.execute(""" @@ -83,34 +66,6 @@ def thread_route(relative_path, pagination=False, **kwargs): return decorator -def which_page(post_id,return_thread_id=False): - # on which page lieth the post in question? - # forget not that page numbers employeth a system that has a base of 1. - # the - # we need impart the knowledgf e into ourselves pertaining to the - # number of things - # before the thing - # yes - - db = get_db() - # ASSUMES THAT post ids are consecutive and things - # this is probably a reasonable assumption - - thread_id = db.execute('select thread from posts where id = ?',(post_id,)).fetchone()['thread'] - - number_of_things_before_the_thing = db.execute('select count(*) as c, thread as t from posts where thread = ? and id < ?;',(thread_id,post_id)).fetchone()['c'] - - - page = 1+math.floor(number_of_things_before_the_thing/POSTS_PER_PAGE) - if return_thread_id: - return page, thread_id - else: - return page - -def post_jump(post_id,*,external=False): - page,thread_id=which_page(post_id,True) - return url_for("thread.view_thread",thread_id=thread_id,page=page,_external=external)+"#post_"+str(post_id) - @thread_route("",pagination=True) def view_thread(thread,page=1): if page < 1: @@ -134,8 +89,8 @@ def view_thread(thread,page=1): num_posts = db.execute("SELECT count(*) as count FROM posts WHERE posts.thread = ?",(thread.id,)).fetchone()['count'] max_pageno = math.ceil(num_posts/POSTS_PER_PAGE) - tags = db.execute( - """SELECT tags.* FROM tags + tags = db.execute(""" + SELECT tags.* FROM tags INNER JOIN thread_tags ON thread_tags.tag = tags.id WHERE thread_tags.thread = ? ORDER BY tags.id""",(thread.id,)).fetchall() |