From 2cba6d4d88266aa3626d4606f2a17460c7437270 Mon Sep 17 00:00:00 2001 From: citrons Date: Wed, 23 Jun 2021 08:47:09 +0000 Subject: make breadcrumb work --- apioforum/__init__.py | 2 ++ apioforum/db.py | 2 +- apioforum/forum.py | 13 +++++++++++-- apioforum/templates/common.html | 27 +++++++++++++++++++++++++++ apioforum/templates/view_thread.html | 11 ++--------- 5 files changed, 43 insertions(+), 12 deletions(-) diff --git a/apioforum/__init__.py b/apioforum/__init__.py index 9d49f36..30dd813 100644 --- a/apioforum/__init__.py +++ b/apioforum/__init__.py @@ -47,6 +47,8 @@ def create_app(): p += "?" + request.query_string.decode("utf-8") return dict(path_for_next=p) + app.jinja_env.globals.update(forum_path=forum.forum_path) + from .mdrender import render @app.template_filter('md') def md_render(s): diff --git a/apioforum/db.py b/apioforum/db.py index 76aacc2..84f268d 100644 --- a/apioforum/db.py +++ b/apioforum/db.py @@ -91,7 +91,7 @@ CREATE TABLE forums ( parent INTEGER REFERENCES forums(id), description TEXT ); -INSERT INTO forums (name,parent,description) values ('root',null,'the default root forum'); +INSERT INTO forums (name,parent,description) values ('apioforum',null,'the default root forum'); PRAGMA foreign_keys = off; BEGIN TRANSACTION; diff --git a/apioforum/forum.py b/apioforum/forum.py index 09d3166..dadc8b3 100644 --- a/apioforum/forum.py +++ b/apioforum/forum.py @@ -11,14 +11,23 @@ from .mdrender import render from sqlite3 import OperationalError -from sqlite3 import OperationalError - bp = Blueprint("forum", __name__, url_prefix="/") @bp.route("/") def not_actual_index(): return redirect("/1") +def forum_path(forum_id): + db = get_db() + i = forum_id + path = [] + while i != None: + forum = db.execute("SELECT * FROM forums WHERE id = ?",(i,)).fetchone() + path.append(forum) + i = forum['parent'] + path.reverse() + return path + @bp.route("/") def view_forum(forum_id): db = get_db() diff --git a/apioforum/templates/common.html b/apioforum/templates/common.html index 9301a49..b0bf713 100644 --- a/apioforum/templates/common.html +++ b/apioforum/templates/common.html @@ -39,3 +39,30 @@ {% macro tag(the_tag) -%} {{the_tag.name}} {%- endmacro %} + +{% macro breadcrumb() %} + +{% endmacro %} + +{% macro forum_bc_entries(forum_id) -%} + {%- for f in forum_path(forum_id) -%} +
  • {{ f.name }}
  • + {%- endfor %} +{%- endmacro %} + +{% macro forum_breadcrumb(forum) %} + {%- call breadcrumb() %} + {{ forum_bc_entries(forum.id) }} + {% endcall -%} +{% endmacro %} + +{% macro thread_breadcrumb(thread) %} + {%- call breadcrumb() %} + {{ forum_bc_entries(thread.forum) }} +
  • {{ thread.title }}
  • + {% endcall -%} +{% endmacro %} diff --git a/apioforum/templates/view_thread.html b/apioforum/templates/view_thread.html index ded2d52..dd41d87 100644 --- a/apioforum/templates/view_thread.html +++ b/apioforum/templates/view_thread.html @@ -1,15 +1,8 @@ -{% from 'common.html' import disp_post,tag %} +{% from 'common.html' import disp_post,tag,thread_breadcrumb %} {% extends 'base.html' %} {% block header %}

    {%block title %}{{thread.title}}{% endblock %}

    - - +{{ thread_breadcrumb(thread) }} {% endblock %} {%block content%} -- cgit v1.2.3