diff options
author | ubq323 <ubq323> | 2021-06-15 18:24:48 +0000 |
---|---|---|
committer | ubq323 <ubq323> | 2021-06-15 18:24:48 +0000 |
commit | 8481d0c07475aee7b9ad4a6aa899bcc9af437e64 (patch) | |
tree | d2b65c0ffaf2b488f49ffec0cdc5bcf5d94f776a | |
parent | 1b9ac4113239d2e963787ba5048a473394ee0a7c (diff) |
fetch tags from database
-rw-r--r-- | apioforum/forum.py | 14 | ||||
-rw-r--r-- | apioforum/templates/common.html | 4 | ||||
-rw-r--r-- | apioforum/templates/view_forum.html | 6 |
3 files changed, 19 insertions, 5 deletions
diff --git a/apioforum/forum.py b/apioforum/forum.py index 81674a8..98c71f7 100644 --- a/apioforum/forum.py +++ b/apioforum/forum.py @@ -5,11 +5,13 @@ from flask import ( Blueprint, render_template, request, g, redirect, url_for, flash ) + from .db import get_db from .mdrender import render bp = Blueprint("forum", __name__, url_prefix="/") + @bp.route("/") def view_forum(): db = get_db() @@ -21,7 +23,15 @@ def view_forum(): GROUP BY threads.id ORDER BY threads.updated DESC; """).fetchall() - return render_template("view_forum.html",threads=threads) + thread_tags = {} + #todo: somehow optimise this + 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 = ?; + """,(thread['id'],)).fetchall() + return render_template("view_forum.html",threads=threads,thread_tags=thread_tags) @bp.route("/create_thread",methods=("GET","POST")) def create_thread(): @@ -77,4 +87,4 @@ def search(): display_thread_id[ix] = False last_thread = result["thread"] rendered_posts = [render(q['content']) for q in results] - return render_template("search_results.html", results=results, query=query, rendered_posts=rendered_posts, display_thread_id=display_thread_id)
\ No newline at end of file + return render_template("search_results.html", results=results, query=query, rendered_posts=rendered_posts, display_thread_id=display_thread_id) diff --git a/apioforum/templates/common.html b/apioforum/templates/common.html index 042f8bd..2e59b2c 100644 --- a/apioforum/templates/common.html +++ b/apioforum/templates/common.html @@ -27,6 +27,6 @@ <time title="{{dt.isoformat(' ')}}" datetime="{{dt.isoformat(' ')}}">{{dt | fuzzy}}</time> {%- endmacro %} -{% macro tag(name, fg, bg) -%} -<span class="tag" style="color: {{fg}}; background-color: {{bg}}">{{name}}</span> +{% macro tag(the_tag) -%} +<span class="tag" style="color: {{the_tag.text_colour}}; background-color: {{the_tag.bg_colour}}">{{the_tag.name}}</span> {%- endmacro %} diff --git a/apioforum/templates/view_forum.html b/apioforum/templates/view_forum.html index ee0e496..6958c20 100644 --- a/apioforum/templates/view_forum.html +++ b/apioforum/templates/view_forum.html @@ -37,7 +37,11 @@ {%for thread in threads%} <div class="threadlisting"> <div class="threadlisting-part threadlisting-part-title"><a href="{{url_for('thread.view_thread',thread_id=thread.id)}}">{{thread.title}}</a></div> - <div class="threadlisting-part threadlisting-part-tags">{{tag("the","black","yellow")}} {{tag("bees","yellow","black")}} {{tag("excellent","black","lightsteelblue")}}</div> + <div class="threadlisting-part threadlisting-part-tags"> + {% for the_tag in thread_tags[thread.id] %} + {{tag(the_tag)}} + {% endfor %} + </div> <div class="threadlisting-part threadlisting-part-creator">{{thread.creator}}</div> <div class="threadlisting-part threadlisting-part-created">{{ts(thread.created)}}</div> <div class="threadlisting-part threadlisting-part-updated">{{ts(thread.updated)}}</div> |