From 49828a93ff3e2983f58b0490251fc0d571442f3c Mon Sep 17 00:00:00 2001 From: cube Date: Fri, 20 Mar 2026 20:53:53 +0000 Subject: [PATCH] blog posts can be edited from the main feed or individual member pages --- README.md | 2 + myriad/blog.py | 25 ++++++++++- myriad/templates/blog/blog.html | 2 +- myriad/templates/blog/edit.html | 27 ++++++++++++ myriad/templates/page.html | 78 ++++++++++++++++----------------- 5 files changed, 91 insertions(+), 43 deletions(-) create mode 100644 myriad/templates/blog/edit.html diff --git a/README.md b/README.md index 68f4e6c..b12e271 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ logged in users are presumed to all be admins with distinction only between bein in the blog view, member privacy outweighs individual post privacy. if a private member makes a public post, it will not show up in the public feed. however, if that member switches to public, their public posts will all become publicly viewable (but private posts will remain private). +some html files (notably full.html and index.html) will show lots of errors in vscode, because of the use of jinja variables in the inline style. this is fine just ignore it. it doesn't do that in the page.html because simply using quotation marks around the colours is enough to make everything correct, but the use of member specific identifiers as jinja variables renders the entire css 'invalid' in the other html files. + # assorted todo - edit blog posts diff --git a/myriad/blog.py b/myriad/blog.py index 0c2c021..ee0220f 100644 --- a/myriad/blog.py +++ b/myriad/blog.py @@ -72,4 +72,27 @@ def toggle(pid, location): if location == "blog": return redirect(url_for("blog.blog")) else: - return redirect(url_for("home.page", mid=location)) \ No newline at end of file + return redirect(url_for("home.page", mid=location)) + +@bp.route("/edit//", methods=('GET', 'POST')) +@login_required +def edit(pid,location): + db = get_db() + post = db.execute("SELECT * FROM blog WHERE id=(?)",(pid,)).fetchone() + members = db.execute("SELECT id,member_name FROM member").fetchall() + + if request.method == 'POST': + title = request.form['title'] + content = request.form['content'] + mid = request.form["mid"] + privacy = request.form["privacy"] + + db.execute("UPDATE blog SET title=(?), content=(?), member_id=(?), public=(?) WHERE id=(?)",(title, content, mid, privacy, pid)) + db.commit() + + if location == "blog": + return redirect(url_for("blog.blog")) + else: + return redirect(url_for("home.page", mid=location)) + + return render_template('blog/edit.html', post=post, members=members) \ No newline at end of file diff --git a/myriad/templates/blog/blog.html b/myriad/templates/blog/blog.html index b242d8e..e3fbbae 100644 --- a/myriad/templates/blog/blog.html +++ b/myriad/templates/blog/blog.html @@ -24,7 +24,7 @@
{% if g.user %} - {% if post[5]==0 %}Private{% else %}Public{% endif %} | Toggle privacy | Delete post + {% if post[5]==0 %}Private{% else %}Public{% endif %} | Toggle privacy | Edit Post | Delete post {% endif %} {% endif %} diff --git a/myriad/templates/blog/edit.html b/myriad/templates/blog/edit.html new file mode 100644 index 0000000..4c56cd5 --- /dev/null +++ b/myriad/templates/blog/edit.html @@ -0,0 +1,27 @@ +{% extends 'base.html' %} + +{% block header %} +
{% block title %}Edit Blog Post{% endblock %}
+{% endblock %} + +{% block content %} +
+ +
+ +
+ + +
+ +
+ +
+ +
+ +{% endblock %} \ No newline at end of file diff --git a/myriad/templates/page.html b/myriad/templates/page.html index d8ddf2f..b28e8aa 100644 --- a/myriad/templates/page.html +++ b/myriad/templates/page.html @@ -7,46 +7,42 @@ @@ -82,7 +78,7 @@ a:hover{
{{post[4]|safe}}
- {% if g.user %}Toggle privacy | Delete post{% endif %} + {% if g.user %}Toggle privacy | Edit Post | Delete post{% endif %} {% endif %} {% endfor %}