From 854b1a93b65b39583e2bf845867ade9a58cb22c2 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Mon, 14 Jun 2021 18:46:09 +0000 Subject: fix search results styling and template logic slightly --- apioforum/templates/search_results.html | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/apioforum/templates/search_results.html b/apioforum/templates/search_results.html index 7035e8f..4d0be2f 100644 --- a/apioforum/templates/search_results.html +++ b/apioforum/templates/search_results.html @@ -1,18 +1,30 @@ {% from 'common.html' import disp_post %} {% extends 'base.html' %} {% block header %} -

{%block title %}Results for {{query}}{% endblock %}

+

{%block title %}results for {{query}}{% endblock %}

{% endblock %} {%block content%}
{% for result in results %} {% if display_thread_id[loop.index0] %} -

{{ result.thread_title }}

+ {% if loop.index0 != 0 %} +
+ {% endif %} +

+ {{result.thread_title}} +

+
{% endif %} - {% call disp_post(result, True) %} + {% call disp_post(result, False) %} {{ rendered_posts[loop.index0] | safe}} {% endcall %} {% endfor %} + + {% if results|length > 0 %} +
+ {% else %} +

no results were found for '{{query}}'.

+ {% endif %} {% endblock %} -- cgit v1.2.3 From 12bcd3de36d12705ec6a4177ab50889ee099442b Mon Sep 17 00:00:00 2001 From: ubq323 Date: Mon, 14 Jun 2021 19:02:48 +0000 Subject: margin should be changed on all elements in a post, not just direct children (this only affects

in a

i think) --- apioforum/static/style.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apioforum/static/style.css b/apioforum/static/style.css index 141cb2e..cc37662 100644 --- a/apioforum/static/style.css +++ b/apioforum/static/style.css @@ -21,7 +21,7 @@ body { font-family: sans-serif } font-size: smaller; } .post-heading-em { font-weight: bold; } -.post-content > * { margin-bottom: 8px; margin-top: 8px; } +.post-content * { margin-bottom: 8px; margin-top: 8px; } .post-content > *:first-child { margin-top: 2px } .post-content > *:last-child { margin-bottom: 0} .post-content { padding: 4px } @@ -152,4 +152,4 @@ blockquote { .search-form { display: inline-block; -} \ No newline at end of file +} -- cgit v1.2.3 From 9960239de2011dc286190a851a3dc035963b109a Mon Sep 17 00:00:00 2001 From: ubq323 Date: Mon, 14 Jun 2021 19:14:04 +0000 Subject: add first parts of config thread page --- apioforum/templates/view_thread.html | 1 + apioforum/thread.py | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/apioforum/templates/view_thread.html b/apioforum/templates/view_thread.html index f38cf34..ddc45b8 100644 --- a/apioforum/templates/view_thread.html +++ b/apioforum/templates/view_thread.html @@ -5,6 +5,7 @@ {% endblock %} {%block content%} +configure
{% for post in posts %} {% call disp_post(post, True) %} diff --git a/apioforum/thread.py b/apioforum/thread.py index 630cb33..f520d8e 100644 --- a/apioforum/thread.py +++ b/apioforum/thread.py @@ -105,4 +105,12 @@ def edit_post(post_id): flash(err) return render_template("edit_post.html",post=post) +@bp.route("//config",methods=["GET","POST"]) +def config_thread(thread_id): + db = get_db() + thread = db.execute("select * from threads where id = ?",(thread_id,)).fetchone() + if request.method == "POST": + abort(418) + return render_template("config_thread.html", thread=thread) + -- cgit v1.2.3 From d020dcd7e87a28d6cc06698929035850ccacb7dc Mon Sep 17 00:00:00 2001 From: ubq323 Date: Mon, 14 Jun 2021 20:06:54 +0000 Subject: use a width defined in terms of characters instead of pixels for better readingness --- apioforum/static/style.css | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/apioforum/static/style.css b/apioforum/static/style.css index cc37662..cbf878d 100644 --- a/apioforum/static/style.css +++ b/apioforum/static/style.css @@ -137,11 +137,9 @@ nav .links { display: flex; } margin-top: 5px; } -@media all and (min-width: 810px ) { - main { - width: 800px; - margin: auto; - } +main { + max-width: 60ch; + margin: auto; } blockquote { -- cgit v1.2.3 From a3b9a43a626966ec0885a0882a4d7f5ee3221803 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Mon, 14 Jun 2021 20:20:29 +0000 Subject: finish all config thread things, currently only changing thread title is supported --- apioforum/templates/config_thread.html | 15 +++++++++++++++ apioforum/thread.py | 27 ++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 apioforum/templates/config_thread.html diff --git a/apioforum/templates/config_thread.html b/apioforum/templates/config_thread.html new file mode 100644 index 0000000..b0dd5f0 --- /dev/null +++ b/apioforum/templates/config_thread.html @@ -0,0 +1,15 @@ +{% extends 'base.html' %} +{% block header %}

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

{% endblock %} +{% block content %} +
+

if you want to change the title of this thread, make sure you check the "change title?" box.

+ +
+ + +
+

confirm changes?

+ +cancel +
+{% endblock %} diff --git a/apioforum/thread.py b/apioforum/thread.py index f520d8e..12ced72 100644 --- a/apioforum/thread.py +++ b/apioforum/thread.py @@ -109,8 +109,33 @@ def edit_post(post_id): def config_thread(thread_id): db = get_db() thread = db.execute("select * from threads where id = ?",(thread_id,)).fetchone() + err = None + if g.user is None: + err = "you need to be logged in to do that" + elif g.user != thread['creator']: + err = "you can only configure threads that you own" + + if err is not None: + flash(err) + return redirect(url_for("thread.view_thread",thread_id=thread_id)) + if request.method == "POST": - abort(418) + err = [] + if 'do_title' in request.form: + title = request.form['title'] + if len(title.strip()) == 0: + err.append("title can't be empty") + else: + db.execute("update threads set title = ? where id = ?;",(title,thread_id)) + flash("title updated successfully") + db.commit() + + if len(err) > 0: + for e in err: + flash(e) + else: + return redirect(url_for("thread.view_thread",thread_id=thread_id)) + return render_template("config_thread.html", thread=thread) -- cgit v1.2.3 From 93d9da49abfb980951265aeaee9a2cf251bc1044 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Mon, 14 Jun 2021 20:22:50 +0000 Subject: hide config thread button if you wouldn't be able to access it anyway --- apioforum/templates/view_thread.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apioforum/templates/view_thread.html b/apioforum/templates/view_thread.html index ddc45b8..eaaf581 100644 --- a/apioforum/templates/view_thread.html +++ b/apioforum/templates/view_thread.html @@ -5,7 +5,9 @@ {% endblock %} {%block content%} -configure +{% if g.user == thread.creator %} +configure thread +{% endif %}
{% for post in posts %} {% call disp_post(post, True) %} -- cgit v1.2.3 From 56490990049a13af7ec0db6bdb1c40d07e69ee88 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Mon, 14 Jun 2021 20:34:26 +0000 Subject: change 'replies' to 'posts' since that's more accurate --- apioforum/templates/view_forum.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apioforum/templates/view_forum.html b/apioforum/templates/view_forum.html index aef01d6..a4a1ee1 100644 --- a/apioforum/templates/view_forum.html +++ b/apioforum/templates/view_forum.html @@ -27,7 +27,7 @@ last activity by
- replies + posts
{%for thread in threads%} -- cgit v1.2.3 From 4bdf927a717fb3c4a4d21991072d4b3d3a639ed7 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Mon, 14 Jun 2021 20:36:58 +0000 Subject: change column widths slightly, now that timestamps have a different fomat --- apioforum/static/style.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apioforum/static/style.css b/apioforum/static/style.css index cbf878d..df8ce7e 100644 --- a/apioforum/static/style.css +++ b/apioforum/static/style.css @@ -69,7 +69,7 @@ nav .links { display: flex; } .threadlisting { display: contents } .threadlistings { display: grid; - grid-template-columns: 2fr 0.8fr 1.2fr 1.2fr 0.8fr 0.4fr; + grid-template-columns: 2fr repeat(4,1fr) 0.4fr; } .threadlisting-part { -- cgit v1.2.3 From 1b9ac4113239d2e963787ba5048a473394ee0a7c Mon Sep 17 00:00:00 2001 From: ubq323 Date: Tue, 15 Jun 2021 00:28:08 +0000 Subject: add stylings for tags, and change styles of view forum page to give us more space too --- apioforum/db.py | 12 ++++++++++++ apioforum/static/style.css | 14 ++++++++++++-- apioforum/templates/base.html | 2 ++ apioforum/templates/common.html | 4 ++++ apioforum/templates/view_forum.html | 10 ++++++++-- 5 files changed, 38 insertions(+), 4 deletions(-) diff --git a/apioforum/db.py b/apioforum/db.py index c24aa0e..1d7bd2b 100644 --- a/apioforum/db.py +++ b/apioforum/db.py @@ -65,7 +65,19 @@ CREATE TRIGGER posts_au AFTER UPDATE ON posts BEGIN INSERT INTO posts_fts(posts_fts, rowid, content) VALUES('delete', old.id, old.content); INSERT INTO posts_fts(rowid, content) VALUES (new.id, new.content); END; +""", """ +CREATE TABLE tags ( + id INTEGER PRIMARY KEY, + name TEXT NOT NULL, + text_colour TEXT NOT NULL, + bg_colour TEXT NOT NULL +); +CREATE TABLE thread_tags ( + thread INTEGER NOT NULL REFERENCES threads(id), + tag INTEGER NOT NULL REFERENCES tags(id) +); +""", ] def init_db(): diff --git a/apioforum/static/style.css b/apioforum/static/style.css index df8ce7e..0672548 100644 --- a/apioforum/static/style.css +++ b/apioforum/static/style.css @@ -69,7 +69,7 @@ nav .links { display: flex; } .threadlisting { display: contents } .threadlistings { display: grid; - grid-template-columns: 2fr repeat(4,1fr) 0.4fr; + grid-template-columns: 2fr repeat(5,1fr) 0.4fr; } .threadlisting-part { @@ -81,13 +81,14 @@ nav .links { display: flex; } border-bottom: 1px solid black; } + } /* small screens */ @media not all and (min-width: 800px) { .threadlisting { display: grid; - grid-template-columns: repeat(5,1fr); + grid-template-columns: repeat(6,1fr); margin-bottom: 5px; } .threadlisting-part-title { @@ -141,6 +142,9 @@ main { max-width: 60ch; margin: auto; } +main.widemain { + max-width: 120ch; +} blockquote { margin-left: 10px; @@ -151,3 +155,9 @@ blockquote { .search-form { display: inline-block; } + +.tag { + font-size: .75rem; + padding: 1px 3px; + border: 1px solid black; +} diff --git a/apioforum/templates/base.html b/apioforum/templates/base.html index ba96c91..1802ee5 100644 --- a/apioforum/templates/base.html +++ b/apioforum/templates/base.html @@ -49,9 +49,11 @@
{{ msg }}
{% endfor %} + {% block nmcontent %}
{%block content %}{% endblock %}
+ {% endblock %} diff --git a/apioforum/templates/common.html b/apioforum/templates/common.html index 33aee0b..042f8bd 100644 --- a/apioforum/templates/common.html +++ b/apioforum/templates/common.html @@ -26,3 +26,7 @@ {% macro ts(dt) -%} {%- endmacro %} + +{% macro tag(name, fg, bg) -%} +{{name}} +{%- endmacro %} diff --git a/apioforum/templates/view_forum.html b/apioforum/templates/view_forum.html index a4a1ee1..ee0e496 100644 --- a/apioforum/templates/view_forum.html +++ b/apioforum/templates/view_forum.html @@ -1,7 +1,8 @@ {% extends 'base.html' %} -{% from 'common.html' import ts %} +{% from 'common.html' import ts, tag %} {% block header %}

{% block title %}apioforum{%endblock%}

{%endblock%} -{%block content%} +{%block nmcontent%} +

welcome to the apioforum

forum rules: do not be a bad person. do not do bad things.

{% if g.user %} @@ -14,6 +15,9 @@
name
+
+ tags +
creator
@@ -33,6 +37,7 @@ {%for thread in threads%}
+
{{tag("the","black","yellow")}} {{tag("bees","yellow","black")}} {{tag("excellent","black","lightsteelblue")}}
{{thread.creator}}
{{ts(thread.created)}}
{{ts(thread.updated)}}
@@ -41,4 +46,5 @@
{%endfor%} +
{%endblock%} -- cgit v1.2.3 From a4461d18a3a4b1a8317747242465f1c7f7caa08f Mon Sep 17 00:00:00 2001 From: ubq323 Date: Tue, 15 Jun 2021 00:35:11 +0000 Subject: apparently deleting posts was broken for some time, but now it isn't --- apioforum/thread.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apioforum/thread.py b/apioforum/thread.py index 12ced72..14450af 100644 --- a/apioforum/thread.py +++ b/apioforum/thread.py @@ -72,7 +72,7 @@ def delete_post(post_id): flash("post deleted deletedly") return redirect(url_for("thread.view_thread",thread_id=post["thread"])) else: - return render_template("delete_post.html",post=post,rendered_content=render_md(post["content"])) + return render_template("delete_post.html",post=post,rendered_content=render(post["content"])) @bp.route("/edit_post/",methods=["GET","POST"]) -- cgit v1.2.3 From 8481d0c07475aee7b9ad4a6aa899bcc9af437e64 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Tue, 15 Jun 2021 18:24:48 +0000 Subject: fetch tags from database --- apioforum/forum.py | 14 ++++++++++++-- apioforum/templates/common.html | 4 ++-- 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 @@ {%- endmacro %} -{% macro tag(name, fg, bg) -%} -{{name}} +{% macro tag(the_tag) -%} +{{the_tag.name}} {%- 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%}
-
{{tag("the","black","yellow")}} {{tag("bees","yellow","black")}} {{tag("excellent","black","lightsteelblue")}}
+
+ {% for the_tag in thread_tags[thread.id] %} + {{tag(the_tag)}} + {% endfor %} +
{{thread.creator}}
{{ts(thread.created)}}
{{ts(thread.updated)}}
-- cgit v1.2.3 From f2fb2736afac2326a8ed16d702a9a6a2d10101d0 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Tue, 15 Jun 2021 19:12:30 +0000 Subject: display tags on thread page --- apioforum/static/style.css | 14 ++++++++++++++ apioforum/templates/view_thread.html | 21 ++++++++++++++++----- apioforum/thread.py | 6 +++++- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/apioforum/static/style.css b/apioforum/static/style.css index 0672548..66f7faa 100644 --- a/apioforum/static/style.css +++ b/apioforum/static/style.css @@ -30,6 +30,20 @@ body { font-family: sans-serif } .post-anchor-link { color: hsl(0,0%,25%); } +.thread-top-bar { + margin-bottom: 4px; +} + +.thread-top-bar-b { + float: right; + margin-right: -2px; +} + +.thread-top-bar-b .tag { + font-size: .9rem; +} + + .un-col-1 { color: hsl(0, 100%, 30%) } .un-col-2 { color: hsl(22.5, 100%, 30%) } .un-col-3 { color: hsl(45.0, 100%, 30%) } diff --git a/apioforum/templates/view_thread.html b/apioforum/templates/view_thread.html index eaaf581..abd6aaa 100644 --- a/apioforum/templates/view_thread.html +++ b/apioforum/templates/view_thread.html @@ -1,13 +1,24 @@ -{% from 'common.html' import disp_post %} +{% from 'common.html' import disp_post,tag %} {% extends 'base.html' %} {% block header %}

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

{% endblock %} {%block content%} -{% if g.user == thread.creator %} -configure thread -{% endif %} +
+ + {% if g.user == thread.creator %} + configure thread + {% endif %} + +   + + {% for the_tag in tags %} + {{ tag(the_tag) }} + {% endfor %} + +
+
{% for post in posts %} {% call disp_post(post, True) %} @@ -16,7 +27,7 @@ {% endfor %}
{% if g.user %} -
+
diff --git a/apioforum/thread.py b/apioforum/thread.py index 12ced72..e881a69 100644 --- a/apioforum/thread.py +++ b/apioforum/thread.py @@ -23,8 +23,12 @@ def view_thread(thread_id): "SELECT * FROM posts WHERE thread = ? ORDER BY created ASC;", (thread_id,) ).fetchall() + tags = db.execute( + """SELECT tags.* FROM tags + INNER JOIN thread_tags ON thread_tags.tag = tags.id + WHERE thread_tags.thread = ?""",(thread_id,)).fetchall() rendered_posts = [render(q['content']) for q in posts] - return render_template("view_thread.html",posts=posts,thread=thread,thread_id=thread_id,rendered_posts=rendered_posts) + return render_template("view_thread.html",posts=posts,thread=thread,rendered_posts=rendered_posts,tags=tags) @bp.route("//create_post", methods=("POST",)) def create_post(thread_id): -- cgit v1.2.3 From b558787d8146894709c42340f85c5bea4418e081 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Tue, 15 Jun 2021 20:25:49 +0000 Subject: fix crash when logging in or out on search results page --- apioforum/__init__.py | 10 +++++++++- apioforum/templates/base.html | 6 +++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/apioforum/__init__.py b/apioforum/__init__.py index 7baa7c1..c4348a3 100644 --- a/apioforum/__init__.py +++ b/apioforum/__init__.py @@ -1,7 +1,7 @@ # boilerplate boilerplate boilerplate # yay -from flask import Flask +from flask import Flask, request from .db import get_db import os @@ -32,6 +32,14 @@ def create_app(): from .fuzzy import fuzzy app.jinja_env.filters['fuzzy']=fuzzy + @app.context_processor + def path_for_next(): + p = request.path + if len(request.query_string) > 0: + p += "?" + request.query_string.decode("utf-8") + return dict(path_for_next=p) + + app.add_url_rule("/",endpoint="index") return app diff --git a/apioforum/templates/base.html b/apioforum/templates/base.html index ba96c91..87b142f 100644 --- a/apioforum/templates/base.html +++ b/apioforum/templates/base.html @@ -21,18 +21,18 @@ {% if g.user %}

{{ g.user }}

- + logout

{% else %}

- + login

- + register

-- cgit v1.2.3 From 2ed3c6588c6463e28a1f7e58a396f2cb590327cd Mon Sep 17 00:00:00 2001 From: ubq323 Date: Tue, 15 Jun 2021 23:01:06 +0000 Subject: allow changing tags on the configure thread page --- apioforum/templates/config_thread.html | 21 +++++++++++++++++++-- apioforum/thread.py | 17 ++++++++++++++++- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/apioforum/templates/config_thread.html b/apioforum/templates/config_thread.html index b0dd5f0..973fbf5 100644 --- a/apioforum/templates/config_thread.html +++ b/apioforum/templates/config_thread.html @@ -1,13 +1,30 @@ {% extends 'base.html' %} +{% from 'common.html' import tag %} {% block header %}

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

{% endblock %} {% block content %}
+
+title

if you want to change the title of this thread, make sure you check the "change title?" box.

-
+
-
+
+
+tags +

if you want to change the tags on this thread, make sure you check the "change tags?" box.

+ +
+
    + {% for the_tag in avail_tags %} +
  • + + +
  • + {% endfor %} +
+

confirm changes?

cancel diff --git a/apioforum/thread.py b/apioforum/thread.py index e881a69..fd196c5 100644 --- a/apioforum/thread.py +++ b/apioforum/thread.py @@ -113,6 +113,8 @@ def edit_post(post_id): def config_thread(thread_id): db = get_db() thread = db.execute("select * from threads where id = ?",(thread_id,)).fetchone() + thread_tags = [r['tag'] for r in db.execute("select tag from thread_tags where thread = ?",(thread_id,)).fetchall()] + avail_tags = db.execute("select * from tags order by id").fetchall() err = None if g.user is None: err = "you need to be logged in to do that" @@ -133,6 +135,19 @@ def config_thread(thread_id): db.execute("update threads set title = ? where id = ?;",(title,thread_id)) flash("title updated successfully") db.commit() + if 'do_chtags' in request.form: + wanted_tags = [] + for tagid in range(1,len(avail_tags)+1): + current = tagid in thread_tags + wanted = f'tag_{tagid}' in request.form + print(tagid, current, wanted) + if wanted and not current: + db.execute("insert into thread_tags (thread, tag) values (?,?)",(thread_id,tagid)) + flash(f"added tag {tagid}") + elif current and not wanted: + db.execute("delete from thread_tags where thread = ? and tag = ?",(thread_id,tagid)) + flash(f"removed tag {tagid}") + db.commit() if len(err) > 0: for e in err: @@ -141,5 +156,5 @@ def config_thread(thread_id): return redirect(url_for("thread.view_thread",thread_id=thread_id)) - return render_template("config_thread.html", thread=thread) + return render_template("config_thread.html", thread=thread,thread_tags=thread_tags,avail_tags=avail_tags) -- cgit v1.2.3 From 73d601135ccd40878c4ec14036737a6702478deb Mon Sep 17 00:00:00 2001 From: ubq323 Date: Tue, 15 Jun 2021 23:24:25 +0000 Subject: change tag change messages slightly --- apioforum/thread.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/apioforum/thread.py b/apioforum/thread.py index fd196c5..30b5d84 100644 --- a/apioforum/thread.py +++ b/apioforum/thread.py @@ -136,6 +136,7 @@ def config_thread(thread_id): flash("title updated successfully") db.commit() if 'do_chtags' in request.form: + changed = False wanted_tags = [] for tagid in range(1,len(avail_tags)+1): current = tagid in thread_tags @@ -143,11 +144,13 @@ def config_thread(thread_id): print(tagid, current, wanted) if wanted and not current: db.execute("insert into thread_tags (thread, tag) values (?,?)",(thread_id,tagid)) - flash(f"added tag {tagid}") + changed = True elif current and not wanted: db.execute("delete from thread_tags where thread = ? and tag = ?",(thread_id,tagid)) - flash(f"removed tag {tagid}") - db.commit() + changed = True + if changed: + db.commit() + flash("tags updated successfully") if len(err) > 0: for e in err: -- cgit v1.2.3 From 6096acce8b922af98e6846a687fcfd19cf0370cc Mon Sep 17 00:00:00 2001 From: ubq323 Date: Tue, 15 Jun 2021 23:34:36 +0000 Subject: make tags less annoying to look at on small screens (i think) --- apioforum/static/style.css | 6 +++++- apioforum/templates/view_forum.html | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/apioforum/static/style.css b/apioforum/static/style.css index 66f7faa..935bde1 100644 --- a/apioforum/static/style.css +++ b/apioforum/static/style.css @@ -95,6 +95,8 @@ nav .links { display: flex; } border-bottom: 1px solid black; } + .only-small { display: none !important } + } @@ -102,7 +104,7 @@ nav .links { display: flex; } @media not all and (min-width: 800px) { .threadlisting { display: grid; - grid-template-columns: repeat(6,1fr); + grid-template-columns: repeat(5,1fr); margin-bottom: 5px; } .threadlisting-part-title { @@ -116,6 +118,8 @@ nav .links { display: flex; } border-right: 1px solid black; border-bottom: 1px solid black; } + + .only-big { display: none !important } } diff --git a/apioforum/templates/view_forum.html b/apioforum/templates/view_forum.html index 6958c20..22f24c1 100644 --- a/apioforum/templates/view_forum.html +++ b/apioforum/templates/view_forum.html @@ -13,9 +13,9 @@
- name + name & tags
-
+
tags
@@ -36,8 +36,16 @@
{%for thread in threads%}
- -
+
{{thread.title}} + {% if thread_tags[thread.id]|length > 0 %} + + {% for the_tag in thread_tags[thread.id] %} + {{tag(the_tag)}} + {% endfor %} + + {%endif%} +
+
{% for the_tag in thread_tags[thread.id] %} {{tag(the_tag)}} {% endfor %} -- cgit v1.2.3 From cdc3350992c11464c61782dd208d7671b56871ac Mon Sep 17 00:00:00 2001 From: ubq323 Date: Tue, 15 Jun 2021 23:36:23 +0000 Subject: change a post heading to be more accurate --- apioforum/templates/view_forum.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apioforum/templates/view_forum.html b/apioforum/templates/view_forum.html index a4a1ee1..dd3d7a8 100644 --- a/apioforum/templates/view_forum.html +++ b/apioforum/templates/view_forum.html @@ -24,7 +24,7 @@ last updated
- last activity by + last post by
posts -- cgit v1.2.3 From b55dbbe2d2996c1c9e4e026766511944e83721e5 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Fri, 18 Jun 2021 16:18:46 +0000 Subject: create admin column --- apioforum/db.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apioforum/db.py b/apioforum/db.py index 1d7bd2b..e1e8fa3 100644 --- a/apioforum/db.py +++ b/apioforum/db.py @@ -78,6 +78,8 @@ CREATE TABLE thread_tags ( tag INTEGER NOT NULL REFERENCES tags(id) ); """, +"""CREATE INDEX thread_tags_thread ON thread_tags (thread);""", +"""ALTER TABLE users ADD COLUMN admin INT NOT NULL DEFAULT 0""", ] def init_db(): -- cgit v1.2.3 From d92a07381f0226dd4aa4f5dc63c11e77853634e0 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Fri, 18 Jun 2021 16:33:25 +0000 Subject: add admin handling things --- apioforum/__init__.py | 2 ++ apioforum/auth.py | 4 ++++ apioforum/permissions.py | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 apioforum/permissions.py diff --git a/apioforum/__init__.py b/apioforum/__init__.py index c4348a3..02252de 100644 --- a/apioforum/__init__.py +++ b/apioforum/__init__.py @@ -19,6 +19,8 @@ def create_app(): from . import db db.init_app(app) + from . import permissions + permissions.init_app(app) from . import auth app.register_blueprint(auth.bp) diff --git a/apioforum/auth.py b/apioforum/auth.py index 547f15e..80407eb 100644 --- a/apioforum/auth.py +++ b/apioforum/auth.py @@ -81,14 +81,17 @@ def load_user(): username = session.get("user") if username is None: g.user = None + g.user_info = None else: row = get_db().execute( "SELECT * FROM users WHERE username = ?;", (username,) ).fetchone() if row is None: g.user = None + g.user_info = None else: g.user = row['username'] + g.user_info = row def login_required(view): @@ -112,3 +115,4 @@ def cool(): @login_required def cooler(): return "bee" + diff --git a/apioforum/permissions.py b/apioforum/permissions.py new file mode 100644 index 0000000..4a9cf97 --- /dev/null +++ b/apioforum/permissions.py @@ -0,0 +1,41 @@ +from flask import ( + g, redirect, url_for, flash +) +import functools +import click +from flask.cli import with_appcontext +from .db import get_db + +def is_admin(): + if g.user_info is None: + return False + else: + return g.user_info['admin'] > 0 + +def admin_required(view): + @functools.wraps(view) + def wrapped(**kwargs): + if is_admin(): + return view(**kwargs) + else: + flash("you must be an admin to do that") + return redirect(url_for("index")) + return wrapped + +@click.command("make_admin") +@click.argument("username") +@with_appcontext +def make_admin(username): + """makes a user an admin user""" + db = get_db() + cur = db.cursor() + cur.execute("UPDATE users SET admin = 1 WHERE username = ?",(username,)) + if cur.rowcount == 0: + click.echo("no such user found") + else: + click.echo("ok") + db.commit() + +def init_app(app): + app.cli.add_command(make_admin) + -- cgit v1.2.3 From fce0869042065365d40ebb9f3093e477cc71df91 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Fri, 18 Jun 2021 20:03:24 +0000 Subject: admin page, and link to admin page --- apioforum/__init__.py | 3 +++ apioforum/permissions.py | 2 ++ apioforum/templates/base.html | 5 +++++ 3 files changed, 10 insertions(+) diff --git a/apioforum/__init__.py b/apioforum/__init__.py index 02252de..4283796 100644 --- a/apioforum/__init__.py +++ b/apioforum/__init__.py @@ -31,6 +31,9 @@ def create_app(): from . import thread app.register_blueprint(thread.bp) + from . import admin + app.register_blueprint(admin.bp) + from .fuzzy import fuzzy app.jinja_env.filters['fuzzy']=fuzzy diff --git a/apioforum/permissions.py b/apioforum/permissions.py index 4a9cf97..816936c 100644 --- a/apioforum/permissions.py +++ b/apioforum/permissions.py @@ -38,4 +38,6 @@ def make_admin(username): def init_app(app): app.cli.add_command(make_admin) + app.context_processor(lambda: dict(is_admin=is_admin())) + diff --git a/apioforum/templates/base.html b/apioforum/templates/base.html index 5121b85..aae49e3 100644 --- a/apioforum/templates/base.html +++ b/apioforum/templates/base.html @@ -20,6 +20,11 @@ {% if g.user %}

{{ g.user }}

+ + {% if is_admin %} +

admin

+ {% endif %} +

logout -- cgit v1.2.3 From 3f0aa4cbb7e217366c55f258fa2d4fc606498951 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Fri, 18 Jun 2021 20:15:43 +0000 Subject: admin page with minimal things on. later once we have things, we can put other things on here. --- apioforum/admin.py | 14 ++++++++++++++ apioforum/templates/admin/admin_page.html | 15 +++++++++++++++ apioforum/templates/base.html | 2 +- 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 apioforum/admin.py create mode 100644 apioforum/templates/admin/admin_page.html diff --git a/apioforum/admin.py b/apioforum/admin.py new file mode 100644 index 0000000..b11b735 --- /dev/null +++ b/apioforum/admin.py @@ -0,0 +1,14 @@ +from flask import ( + Blueprint, render_template +) +from .db import get_db +from .permissions import admin_required + +bp = Blueprint("admin",__name__,url_prefix="/admin") + +@bp.route("/") +@admin_required +def admin_page(): + db = get_db() + admins = db.execute("select * from users where admin > 0;").fetchall() + return render_template("admin/admin_page.html",admins=admins) diff --git a/apioforum/templates/admin/admin_page.html b/apioforum/templates/admin/admin_page.html new file mode 100644 index 0000000..f48c6c0 --- /dev/null +++ b/apioforum/templates/admin/admin_page.html @@ -0,0 +1,15 @@ +{% extends 'base.html' %} +{% block header %} +

{% block title %}admin page{% endblock %}

+{% endblock %} + +{% block content %} +

admins

+
    + {% for admin in admins %} +
  • {{admin.username}}
  • + {% endfor %} +
+

this page will have more things on it later, probably

+{% endblock %} + diff --git a/apioforum/templates/base.html b/apioforum/templates/base.html index aae49e3..bf3748f 100644 --- a/apioforum/templates/base.html +++ b/apioforum/templates/base.html @@ -22,7 +22,7 @@

{{ g.user }}

{% if is_admin %} -

admin

+

admin

{% endif %}

-- cgit v1.2.3 From 4bd4bcbccb9e7772da337f30d9b62147877bc3d9 Mon Sep 17 00:00:00 2001 From: raven Date: Fri, 18 Jun 2021 21:10:57 +0000 Subject: view user profile at /user/ --- apioforum/__init__.py | 3 +++ apioforum/db.py | 4 ++++ apioforum/static/style.css | 11 +++++++++++ 3 files changed, 18 insertions(+) diff --git a/apioforum/__init__.py b/apioforum/__init__.py index 4283796..54d18c3 100644 --- a/apioforum/__init__.py +++ b/apioforum/__init__.py @@ -34,6 +34,9 @@ def create_app(): from . import admin app.register_blueprint(admin.bp) + from . import user + app.register_blueprint(user.bp) + from .fuzzy import fuzzy app.jinja_env.filters['fuzzy']=fuzzy diff --git a/apioforum/db.py b/apioforum/db.py index e1e8fa3..910118d 100644 --- a/apioforum/db.py +++ b/apioforum/db.py @@ -80,6 +80,10 @@ CREATE TABLE thread_tags ( """, """CREATE INDEX thread_tags_thread ON thread_tags (thread);""", """ALTER TABLE users ADD COLUMN admin INT NOT NULL DEFAULT 0""", +""" +ALTER TABLE users ADD COLUMN bio TEXT; +ALTER TABLE users ADD COLUMN joined TIMESTAMP; +""", ] def init_db(): diff --git a/apioforum/static/style.css b/apioforum/static/style.css index 935bde1..401fedb 100644 --- a/apioforum/static/style.css +++ b/apioforum/static/style.css @@ -43,6 +43,17 @@ body { font-family: sans-serif } font-size: .9rem; } +.user_info { + border: 1px solid black; + background-color: var(--alternating-colour-even); + width: 100%; + padding: 4px; +} +.user_bio_quote { width: max-content; } +.user_bio_attribution { text-align: right; } + +dt { font-weight: bold } + .un-col-1 { color: hsl(0, 100%, 30%) } .un-col-2 { color: hsl(22.5, 100%, 30%) } -- cgit v1.2.3 From a1cc107b3c65ff110124576d3609043f593a67f4 Mon Sep 17 00:00:00 2001 From: raven Date: Fri, 18 Jun 2021 21:13:56 +0000 Subject: actually add the files --- apioforum/templates/view_user.html | 22 ++++++++++++++++++++++ apioforum/user.py | 19 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 apioforum/templates/view_user.html create mode 100644 apioforum/user.py diff --git a/apioforum/templates/view_user.html b/apioforum/templates/view_user.html new file mode 100644 index 0000000..c9d9c1c --- /dev/null +++ b/apioforum/templates/view_user.html @@ -0,0 +1,22 @@ +{% from 'common.html' import disp_post,ts %} +{% extends 'base.html' %} +{% block header %} +

{%block title %}{{user.username|e}}{% endblock %}

+{% endblock %} + +{%block content%} + +{% endblock %} diff --git a/apioforum/user.py b/apioforum/user.py new file mode 100644 index 0000000..cdf38d3 --- /dev/null +++ b/apioforum/user.py @@ -0,0 +1,19 @@ +# user pages + +from flask import ( + Blueprint, render_template, abort, g +) + +from .db import get_db +from .mdrender import render + +bp = Blueprint("user", __name__, url_prefix="/user") + +@bp.route("/") +def view_user(username): + db = get_db() + user = db.execute("SELECT * FROM users WHERE username = ?;",(username,)).fetchone() + if user is None: + abort(404) + return render_template("view_user.html", + user=user, rendered_bio=render(user['bio'] or "hail GEORGE")) -- cgit v1.2.3 From 8bf3a017837dfaae0210cfd0d7a7d75ae6a1d45c Mon Sep 17 00:00:00 2001 From: raven Date: Fri, 18 Jun 2021 21:24:00 +0000 Subject: make it actually record the join date --- apioforum/auth.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apioforum/auth.py b/apioforum/auth.py index 80407eb..dae7b03 100644 --- a/apioforum/auth.py +++ b/apioforum/auth.py @@ -5,6 +5,7 @@ from flask import ( from werkzeug.security import check_password_hash, generate_password_hash from .db import get_db import functools +import datetime bp = Blueprint("auth", __name__, url_prefix="/auth") @@ -57,8 +58,8 @@ def register(): if err is None: db.execute( - "INSERT INTO users (username, password) VALUES (?,?);", - (username,generate_password_hash(password)) + "INSERT INTO users (username, password, joined) VALUES (?,?,?);", + (username,generate_password_hash(password),datetime.datetime.now()) ) db.commit() flash("successfully created account") -- cgit v1.2.3 From 4f75e30d9584566dca8f3c67a9451c22839d9da1 Mon Sep 17 00:00:00 2001 From: raven Date: Fri, 18 Jun 2021 21:38:54 +0000 Subject: recent posts --- apioforum/templates/view_user.html | 10 ++++++++++ apioforum/user.py | 8 +++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/apioforum/templates/view_user.html b/apioforum/templates/view_user.html index c9d9c1c..93618a5 100644 --- a/apioforum/templates/view_user.html +++ b/apioforum/templates/view_user.html @@ -19,4 +19,14 @@ {% endif %}
+{% if posts %} +

recent posts

+
+ {% for post in posts %} + {% call disp_post(post, False) %} + {{ rendered_posts[loop.index0] | safe}} + {% endcall %} + {% endfor %} +
+{% endif %} {% endblock %} diff --git a/apioforum/user.py b/apioforum/user.py index cdf38d3..af0539a 100644 --- a/apioforum/user.py +++ b/apioforum/user.py @@ -15,5 +15,11 @@ def view_user(username): user = db.execute("SELECT * FROM users WHERE username = ?;",(username,)).fetchone() if user is None: abort(404) + posts = db.execute( + "SELECT * FROM posts WHERE author = ? ORDER BY created DESC LIMIT 25;",(username,)).fetchall() + rendered_posts = [render(post['content']) for post in posts] return render_template("view_user.html", - user=user, rendered_bio=render(user['bio'] or "hail GEORGE")) + user=user, + rendered_bio=render(user['bio'] or "hail GEORGE"), + posts=posts, + rendered_posts=rendered_posts) -- cgit v1.2.3 From f66dfff19be67a268fc36975a995e206cf41f91b Mon Sep 17 00:00:00 2001 From: citrons Date: Sat, 19 Jun 2021 08:03:09 +0000 Subject: user settings page, usernames link to user profiles --- apioforum/static/style.css | 14 +++++------- apioforum/templates/base.html | 10 ++++---- apioforum/templates/common.html | 7 +++++- apioforum/templates/user_settings.html | 26 +++++++++++++++++++++ apioforum/templates/view_forum.html | 6 ++--- apioforum/templates/view_user.html | 7 +++++- apioforum/user.py | 42 +++++++++++++++++++++++++++++++++- 7 files changed, 94 insertions(+), 18 deletions(-) create mode 100644 apioforum/templates/user_settings.html diff --git a/apioforum/static/style.css b/apioforum/static/style.css index 401fedb..d725165 100644 --- a/apioforum/static/style.css +++ b/apioforum/static/style.css @@ -1,4 +1,4 @@ -body { font-family: sans-serif } +body { font-family: sans-serif; word-wrap: break-word; } :root { --alternating-colour-even: hsl(0,0%,96%); @@ -16,10 +16,8 @@ body { font-family: sans-serif } } .post:last-of-type { border-bottom: 1px solid black; } -.post-heading { - color: hsl(0,0%,25%); - font-size: smaller; -} +.post-heading { font-size: smaller; } +.post-heading,.post-heading .username { color: hsl(0,0%,25%); } .post-heading-em { font-weight: bold; } .post-content * { margin-bottom: 8px; margin-top: 8px; } .post-content > *:first-child { margin-top: 2px } @@ -30,7 +28,7 @@ body { font-family: sans-serif } .post-anchor-link { color: hsl(0,0%,25%); } -.thread-top-bar { +.thread-top-bar, .user-top-bar { margin-bottom: 4px; } @@ -49,8 +47,8 @@ body { font-family: sans-serif } width: 100%; padding: 4px; } -.user_bio_quote { width: max-content; } -.user_bio_attribution { text-align: right; } +.user_bio_quote { width: max-content; max-width: 100% } +.user_bio_attribution { text-align: right; font-style: italic; } dt { font-weight: bold } diff --git a/apioforum/templates/base.html b/apioforum/templates/base.html index bf3748f..3eb112e 100644 --- a/apioforum/templates/base.html +++ b/apioforum/templates/base.html @@ -19,25 +19,25 @@

home

{% if g.user %} -

{{ g.user }}

+

{{g.user}}

{% if is_admin %}

admin

{% endif %}

- + logout

{% else %}

- + login

- + register

@@ -60,6 +60,8 @@ {% endblock %} + + diff --git a/apioforum/templates/common.html b/apioforum/templates/common.html index 2e59b2c..c484a9d 100644 --- a/apioforum/templates/common.html +++ b/apioforum/templates/common.html @@ -1,8 +1,13 @@ +{% macro disp_user(username) -%} +{{username}} +{%- endmacro %} + {% macro disp_post(post, buttons=False) %}
- {{post.author}} {{ts(post.created)}} + {{disp_user(post.author)}} + {{ts(post.created)}} {% if post.edited %} (edited {{ts(post.updated)}}) {% endif %} diff --git a/apioforum/templates/user_settings.html b/apioforum/templates/user_settings.html new file mode 100644 index 0000000..fdd447f --- /dev/null +++ b/apioforum/templates/user_settings.html @@ -0,0 +1,26 @@ +{% extends 'base.html' %} +{% block header %}

{% block title %}user settings{% endblock %}

{% endblock %} +{% block content %} + +
+change password +

if you want to change your password, make sure you check the "change password?" box.

+ +
+ +
+ + +
+
+change bio +

if you want to change your bio, make sure you check the "change bio?" box.

+ +
+ +
+

confirm changes?

+ +cancel + +{% endblock %} diff --git a/apioforum/templates/view_forum.html b/apioforum/templates/view_forum.html index 3edb7f0..59c594b 100644 --- a/apioforum/templates/view_forum.html +++ b/apioforum/templates/view_forum.html @@ -1,5 +1,5 @@ {% extends 'base.html' %} -{% from 'common.html' import ts, tag %} +{% from 'common.html' import ts, tag, disp_user %} {% block header %}

{% block title %}apioforum{%endblock%}

{%endblock%} {%block nmcontent%}
@@ -50,10 +50,10 @@ {{tag(the_tag)}} {% endfor %}
-
{{thread.creator}}
+
{{disp_user(thread.creator)}}
{{ts(thread.created)}}
{{ts(thread.updated)}}
-
{{thread.last_user}}
+
{{disp_user(thread.last_user)}}
{{thread.num_replies}}
{%endfor%} diff --git a/apioforum/templates/view_user.html b/apioforum/templates/view_user.html index 93618a5..f773978 100644 --- a/apioforum/templates/view_user.html +++ b/apioforum/templates/view_user.html @@ -5,6 +5,11 @@ {% endblock %} {%block content%} +
+ {% if g.user == user.username %} + settings + {% endif %} +