diff options
Diffstat (limited to 'apioforum/forum.py')
-rw-r--r-- | apioforum/forum.py | 88 |
1 files changed, 46 insertions, 42 deletions
diff --git a/apioforum/forum.py b/apioforum/forum.py index f88900f..93dbddb 100644 --- a/apioforum/forum.py +++ b/apioforum/forum.py @@ -86,7 +86,7 @@ def view_forum(forum,page=1): sortby_dir = {'d':'DESC','a':'ASC'}[sortby[1]] sortby_by = {'a':'threads.updated','c':'threads.created'}[sortby[0]] except KeyError: - return redirect(url_for('forum.view_forum',forum_id=forum.id)) + abort(400) avail_tags = forum.avail_tags() @@ -114,28 +114,37 @@ def view_forum(forum,page=1): abort(400) - threads = db.execute( - f"""SELECT - threads.id, threads.title, threads.creator, threads.created, - threads.updated, threads.poll, number_of_posts.num_replies, - most_recent_posts.created as mrp_created, - most_recent_posts.author as mrp_author, - most_recent_posts.id as mrp_id, - most_recent_posts.content as mrp_content, - most_recent_posts.deleted as mrp_deleted - FROM threads - INNER JOIN most_recent_posts ON most_recent_posts.thread = threads.id - INNER JOIN number_of_posts ON number_of_posts.thread = threads.id - LEFT OUTER JOIN thread_tags ON threads.id = thread_tags.thread - WHERE threads.forum = ? {tagfilter_clause} - GROUP BY threads.id - ORDER BY {sortby_by} {sortby_dir} - LIMIT ? OFFSET ?; - """,( - forum.id, - THREADS_PER_PAGE, - (page-1)*THREADS_PER_PAGE, - )).fetchall() + threads = Thread.from_row_list(db.execute( + f"""select * from threads + left outer join thread_tags on threads.id = thread_tags.thread + where threads.forum = ? {tagfilter_clause} + order by {sortby_by} {sortby_dir} + limit ? offset ?; + """,(forum.id, THREADS_PER_PAGE, (page-1)*THREADS_PER_PAGE)).fetchall()) + + # i want to preserve this + #threads = db.execute( + # f"""SELECT + # threads.id, threads.title, threads.creator, threads.created, + # threads.updated, threads.poll, number_of_posts.num_replies, + # most_recent_posts.created as mrp_created, + # most_recent_posts.author as mrp_author, + # most_recent_posts.id as mrp_id, + # most_recent_posts.content as mrp_content, + # most_recent_posts.deleted as mrp_deleted + # FROM threads + # INNER JOIN most_recent_posts ON most_recent_posts.thread = threads.id + # INNER JOIN number_of_posts ON number_of_posts.thread = threads.id + # LEFT OUTER JOIN thread_tags ON threads.id = thread_tags.thread + # WHERE threads.forum = ? {tagfilter_clause} + # GROUP BY threads.id + # ORDER BY {sortby_by} {sortby_dir} + # LIMIT ? OFFSET ?; + # """,( + # forum.id, + # THREADS_PER_PAGE, + # (page-1)*THREADS_PER_PAGE, + # )).fetchall() num_threads = db.execute(f""" SELECT count(*) AS count FROM threads @@ -145,24 +154,16 @@ def view_forum(forum,page=1): max_pageno = math.ceil(num_threads/THREADS_PER_PAGE) - thread_tags = {} thread_polls = {} for thread in threads: - thread_tags[thread['id']] = 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() - - if thread['poll'] is not None: + if thread.poll is not None: # todo: make this not be duplicated from thread.py poll_row= db.execute(""" SELECT polls.*,total_vote_counts.total_votes FROM polls LEFT OUTER JOIN total_vote_counts ON polls.id = total_vote_counts.poll WHERE polls.id = ?; - """,(thread['poll'],)).fetchone() + """,(thread.poll,)).fetchone() options = db.execute(""" SELECT poll_options.*, vote_counts.num FROM poll_options @@ -176,7 +177,7 @@ def view_forum(forum,page=1): poll.update(poll_row) poll['options'] = options poll['total_votes']=poll['total_votes'] or 0 - thread_polls[thread['id']]=poll + thread_polls[thread.id]=poll # subforums don't exist any more @@ -191,13 +192,13 @@ def view_forum(forum,page=1): # ORDER BY name ASC # """,(forum.id,)).fetchall() subforums = [] - for s in subforums_rows: - a={} - a.update(s) - if a['updated'] is not None: - a['updated'] = datetime.datetime.fromisoformat(a['updated']) - if has_permission(a['id'],g.user,"p_view_forum",login_required=False): - subforums.append(a) + #for s in subforums_rows: + # a={} + # a.update(s) + # if a['updated'] is not None: + # a['updated'] = datetime.datetime.fromisoformat(a['updated']) + # if has_permission(a['id'],g.user,"p_view_forum",login_required=False): + # subforums.append(a) bureaucrats = db.execute(""" SELECT user FROM role_assignments @@ -209,7 +210,6 @@ def view_forum(forum,page=1): forum=forum, subforums=subforums, threads=threads, - thread_tags=thread_tags, bureaucrats=bureaucrats, thread_polls=thread_polls, max_pageno=max_pageno, @@ -461,3 +461,7 @@ def search(): display_thread_id[ix] = False last_thread = result["thread"] return render_template("search_results.html", results=results, query=query, display_thread_id=display_thread_id) + + +#circular import bees +from .thread import Thread |