aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorubq323 <ubq323>2021-06-09 22:07:43 +0000
committerubq323 <ubq323>2021-06-09 22:07:43 +0000
commitb85a4e185a9ca96b5b6f0f492326e556e0d63040 (patch)
treeda89ad313863e84c42fffb8de6185764ea1c2c5a
parentd4211837747e0fda14cb278c10aad9f7e05e076c (diff)
editing and deleting and things
-rw-r--r--apioforum/static/style.css28
-rw-r--r--apioforum/templates/common.html9
-rw-r--r--apioforum/templates/view_thread.html4
-rw-r--r--apioforum/thread.py36
4 files changed, 66 insertions, 11 deletions
diff --git a/apioforum/static/style.css b/apioforum/static/style.css
index 90b3b83..2ec7d20 100644
--- a/apioforum/static/style.css
+++ b/apioforum/static/style.css
@@ -7,6 +7,7 @@ body { font-family: sans-serif }
border-left: 1px solid black;
border-right: 1px solid black;
border-top: 1px solid black;
+ width: 100%
}
.post:last-of-type { border-bottom: 1px solid black; }
@@ -14,8 +15,27 @@ body { font-family: sans-serif }
color: grey;
font-size: smaller;
}
+.post-heading-em { font-weight: bold; }
.post-content > * { margin-bottom: 0 }
.post-content > *:nth-child(1) { margin-top: 2px }
+.post-content { padding: 4px }
+
+.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%) }
+.un-col-4 { color: hsl(67.5, 100%, 30%) }
+.un-col-5 { color: hsl(90.0, 100%, 30%) }
+.un-col-6 { color: hsl(112.5, 100%, 30%) }
+.un-col-7 { color: hsl(135.0, 100%, 30%) }
+.un-col-8 { color: hsl(157.5, 100%, 30%) }
+.un-col-9 { color: hsl(180.0, 100%, 30%) }
+.un-col-10 { color: hsl(202.5, 100%, 30%) }
+.un-col-11 { color: hsl(225.0, 100%, 30%) }
+.un-col-12 { color: hsl(247.5, 100%, 30%) }
+.un-col-13 { color: hsl(270.0, 100%, 30%) }
+.un-col-14 { color: hsl(292.5, 100%, 30%) }
+.un-col-15 { color: hsl(315.0, 100%, 30%) }
+.un-col-16 { color: hsl(337.5, 100%, 30%) }
img { max-width: 100% }
@@ -54,3 +74,11 @@ nav a { color: blue; text-decoration: none }
content: "]";
color: grey;
}
+
+.new-post-box {
+ height:20em;
+ resize:vertical;
+ width:100%;
+ border:1px solid black;
+ margin-top: 5px;
+}
diff --git a/apioforum/templates/common.html b/apioforum/templates/common.html
index 0baa1f5..d4178d7 100644
--- a/apioforum/templates/common.html
+++ b/apioforum/templates/common.html
@@ -1,11 +1,11 @@
-{% macro disp_post(post, thread_id, buttons=False) %}
+{% macro disp_post(post, buttons=False) %}
<div class="post">
<div class="post-heading">
<span class="post-heading-a">
- {{post.author}} @{{post.created}} #{{post.id}}
+ <span class="post-heading-em">{{post.author}}</span> {{post.created}}
</span>
- {% if buttons and post.author == g.user %}
<span class="post-heading-b">
+ {% if buttons and post.author == g.user %}
<a class="actionbutton"
href="{{url_for('thread.edit_post',post_id=post.id)}}">
edit
@@ -14,8 +14,9 @@
href="{{url_for('thread.delete_post',post_id=post.id)}}">
delete
</a>
- </span>
{% endif %}
+ #{{post.id}}
+ </span>
</div>
<div class="post-content">
{{ caller() }}
diff --git a/apioforum/templates/view_thread.html b/apioforum/templates/view_thread.html
index acd062f..f38cf34 100644
--- a/apioforum/templates/view_thread.html
+++ b/apioforum/templates/view_thread.html
@@ -7,14 +7,14 @@
{%block content%}
<div class="posts">
{% for post in posts %}
- {% call disp_post(post, thread_id, True) %}
+ {% call disp_post(post, True) %}
{{ rendered_posts[loop.index0] | safe}}
{% endcall %}
{% endfor %}
</div>
{% if g.user %}
<form class="new-post" action="{{url_for('thread.create_post',thread_id=thread_id)}}" method="POST">
- <textarea placeholder="your post here..." name="content"></textarea>
+ <textarea class="new-post-box" placeholder="your post here..." name="content"></textarea>
<input type="submit" value="yes">
</form>
{% else %}
diff --git a/apioforum/thread.py b/apioforum/thread.py
index f0cdeaf..23e3cf2 100644
--- a/apioforum/thread.py
+++ b/apioforum/thread.py
@@ -4,10 +4,13 @@ from flask import (
Blueprint, render_template, abort, request, g, redirect,
url_for, flash
)
-from markdown import markdown
-from markupsafe import escape
from .db import get_db
+def render_md(md):
+ from markdown import markdown
+ from markupsafe import escape
+ return markdown(escape(md))
+
bp = Blueprint("thread", __name__, url_prefix="/thread")
@bp.route("/<int:thread_id>")
@@ -21,7 +24,7 @@ def view_thread(thread_id):
"SELECT * FROM posts WHERE thread = ? ORDER BY created ASC;",
(thread_id,)
).fetchall()
- rendered_posts = [markdown(escape(q['content'])) for q in posts]
+ rendered_posts = [render_md(q['content']) for q in posts]
return render_template("view_thread.html",posts=posts,thread=thread,thread_id=thread_id,rendered_posts=rendered_posts)
@bp.route("/<int:thread_id>/create_post", methods=("POST",))
@@ -52,7 +55,24 @@ def create_post(thread_id):
@bp.route("/delete_post/<int:post_id>", methods=["GET","POST"])
def delete_post(post_id):
- return f"todo (p: {post_id})"
+ db = get_db()
+ post = db.execute("SELECT * FROM posts WHERE id = ?",(post_id,)).fetchone()
+ if post is None:
+ flash("that post doesn't exist")
+ return redirect("/")
+ if post['author'] != g.user:
+ flash("you can only delete posts that you created")
+ return redirect(url_for("thread.view_thread",thread_id=post["thread"]))
+ if request.method == "POST":
+ # todo: don't actually delete, just mark as deleted or something (and wipe content)
+ # so that you can have a "this post was deleted" thing
+ db.execute("DELETE FROM posts WHERE id = ?",(post_id,))
+ db.commit()
+ 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"]))
+
@bp.route("/edit_post/<int:post_id>",methods=["GET","POST"])
def edit_post(post_id):
@@ -84,4 +104,10 @@ def edit_post(post_id):
flash(err)
return render_template("edit_post.html",post=post)
-
+
+@bp.route("/test")
+def test():
+ a = "<link rel=stylesheet href=/static/style.css>"
+ for i in range(1,17):
+ a += f'<span class="post-heading-em un-col-{i}">apiobee {i}</span><br>'
+ return a