aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--apioforum/__init__.py2
-rw-r--r--apioforum/db.py2
-rw-r--r--apioforum/forum.py29
-rw-r--r--apioforum/static/style.css33
-rw-r--r--apioforum/templates/common.html27
-rw-r--r--apioforum/templates/view_forum.html46
-rw-r--r--apioforum/templates/view_thread.html11
7 files changed, 108 insertions, 42 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..e379350 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("/<int:forum_id>")
def view_forum(forum_id):
db = get_db()
@@ -46,8 +55,24 @@ def view_forum(forum_id):
"""SELECT * FROM posts WHERE thread = ?
ORDER BY created DESC;
""",(thread['id'],)).fetchone()
+
+ subforums = db.execute("""
+ SELECT * FROM forums WHERE parent = ? ORDER BY name ASC
+ """,(forum_id,)).fetchall()
+
+ forum_last_activity = {}
+ for subforum in subforums:
+ result = db.execute(
+ """SELECT updated FROM threads
+ WHERE forum = ?
+ ORDER BY updated DESC;
+ """,(subforum['id'],)).fetchone()
+ forum_last_activity[subforum['id']] = result[0] if result != None else None
+
return render_template("view_forum.html",
forum=forum,
+ subforums=subforums,
+ forum_last_activity=forum_last_activity,
threads=threads,
thread_tags=thread_tags,
preview_post=preview_post
diff --git a/apioforum/static/style.css b/apioforum/static/style.css
index b456e26..fcea239 100644
--- a/apioforum/static/style.css
+++ b/apioforum/static/style.css
@@ -88,26 +88,27 @@ nav#navbar .links { display: flex; }
/* todo: make the navbar less bad */
.flashmsg { border: 1px solid black; background-color: yellow; max-width: max-content; padding: 5px; clear: both;}
-.thread-listing:nth-child(even) { background-color: var(--alternating-colour-even) }
-.thread-listing:nth-child(odd) { background-color: var(--alternating-colour-odd) }
+.listing:nth-child(even) { background-color: var(--alternating-colour-even) }
+.listing:nth-child(odd) { background-color: var(--alternating-colour-odd) }
-.thread-listing {
+.listing {
border-left: 1px solid black;
border-right: 1px solid black;
border-top: 1px solid black;
padding: 10px;
}
-.thread-listing:last-of-type { border-bottom: 1px solid black; }
-.thread-listing-main {
+.listing:last-of-type { border-bottom: 1px solid black; }
+.listing-main {
display: flex;
align-items: center;
}
-.thread-listing-title {
+.listing-title {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
flex-grow: 1;
}
+
.thread-listing-tags {
display: flex;
align-items: center;
@@ -121,7 +122,7 @@ nav#navbar .links { display: flex; }
flex-wrap: nowrap;
}
.thread-listing-creator { margin-right: 5px; }
-.thread-preview {
+.listing-caption {
overflow: hidden;
font-size: smaller;
white-space: nowrap;
@@ -137,7 +138,7 @@ nav#navbar .links { display: flex; }
/* wide screens */
@media all and (min-width: 600px) {
- .thread-listing-title { font-size: larger; }
+ .listing-title { font-size: larger; }
}
/* small screens */
@@ -151,22 +152,6 @@ nav#navbar .links { display: flex; }
}
}
-
-.threadlisting-part {
- background-color: inherit;
- display: table-cell;
- vertical-align: middle;
- padding: 3px;
- text-align: center;
-}
-
-.threadlisting-part-title {
- text-overflow: ellipsis;
- overflow: hidden;
-}
-
-.threadlisting-header { font-weight: bold }
-
.actionbutton::before {
content: "[";
color: grey;
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) -%}
<span class="tag" style="color: {{the_tag.text_colour}}; background-color: {{the_tag.bg_colour}}">{{the_tag.name}}</span>
{%- endmacro %}
+
+{% macro breadcrumb() %}
+<nav aria-label="Breadcrumb">
+<ol class="breadcrumbs">
+ {{- caller() -}}
+</ol>
+</nav>
+{% endmacro %}
+
+{% macro forum_bc_entries(forum_id) -%}
+ {%- for f in forum_path(forum_id) -%}
+ <li><a href="{{url_for('forum.view_forum',forum_id=f.id)}}">{{ f.name }}</a></li>
+ {%- 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) }}
+ <li>{{ thread.title }}</li>
+ {% endcall -%}
+{% endmacro %}
diff --git a/apioforum/templates/view_forum.html b/apioforum/templates/view_forum.html
index f83503b..926980e 100644
--- a/apioforum/templates/view_forum.html
+++ b/apioforum/templates/view_forum.html
@@ -1,9 +1,42 @@
{% extends 'base.html' %}
-{% from 'common.html' import ts, tag, disp_user, post_url %}
-{% block header %}<h1>{% block title %}{{forum.name}}{%endblock%}</h1>{%endblock%}
+{% from 'common.html' import ts, tag, disp_user, post_url, forum_breadcrumb %}
+{% block header %}
+<h1>{% block title %}{{forum.name}}{%endblock%}</h1>
+{% if forum.id != 1 %}
+ {{ forum_breadcrumb(forum) }}
+{% endif %}
+{%endblock%}
+
{%block nmcontent%}
<main class="widemain">
{{forum.description|md|safe}}
+
+
+{% if subforums %}
+<h2>subforae</h2>
+<div class="forum-list">
+ {% for subforum in subforums %}
+ <div class="listing">
+ <div class="listing-main">
+ <div class="listing-title">
+ <a href="{{url_for('forum.view_forum',forum_id=subforum.id)}}">
+ {{- subforum.name -}}
+ </a>
+ </div>
+ </div>
+ <div class="listing-caption">
+ {% if forum_last_activity[subforum.id] %}
+ last activity {{ts(forum_last_activity[subforum.id])}} ago
+ {% else %}
+ no threads
+ {% endif %}
+ </div>
+ </div>
+ {% endfor %}
+</div>
+{% endif %}
+
+<h2>threads</h2>
{% if g.user %}
<p><a class="actionbutton" href="{{url_for('forum.create_thread',forum_id=forum.id)}}">create new thread</a></p>
{% else %}
@@ -11,9 +44,9 @@
{% endif %}
<div class="thread-list">
{%for thread in threads%}
- <div class="thread-listing">
- <div class="thread-listing-main">
- <div class="thread-listing-title">
+ <div class="listing">
+ <div class="listing-main">
+ <div class="listing-title">
<a href="{{url_for('thread.view_thread',thread_id=thread.id)}}">
{{- thread.title -}}
</a>
@@ -31,7 +64,7 @@
</div>
</div>
{% if preview_post[thread.id] %}
- <div class="thread-preview">
+ <div class="listing-caption">
{{ disp_user(preview_post[thread.id].author) }}
<span class="thread-preview-ts">
{{ ts(preview_post[thread.id].created) }}
@@ -46,5 +79,6 @@
</div>
{%endfor%}
</div>
+
</main>
{%endblock%}
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 %}
<h1>{%block title %}{{thread.title}}{% endblock %}</h1>
-<nav aria-label="Breadcrumb">
-<ol class="breadcrumbs">
- <li><a href="{{url_for('index')}}">apioforum</a></li>
- <li><a href="#">the</a></li>
- <li>the</li>
-</ol>
-</nav>
-
+{{ thread_breadcrumb(thread) }}
{% endblock %}
{%block content%}