toggle blog post privacy

This commit is contained in:
cube
2026-03-20 19:27:01 +00:00
parent 869588ef13
commit e74ea6ca69
4 changed files with 20 additions and 5 deletions

View File

@@ -57,3 +57,19 @@ def delete(pid, location):
else:
return redirect(url_for("home.page", mid=location))
@bp.route("/toggle/<pid>/<location>")
@login_required
def toggle(pid, location):
db = get_db()
post = db.execute("SELECT * FROM blog WHERE id=(?)",(pid,)).fetchone()
if post[5] == 0:
db.execute("UPDATE blog SET public=(?) WHERE id=(?)",(1, pid))
db.commit()
else:
db.execute("UPDATE blog SET public=(?) WHERE id=(?)",(0, pid))
db.commit()
if location == "blog":
return redirect(url_for("blog.blog"))
else:
return redirect(url_for("home.page", mid=location))

View File

@@ -24,7 +24,7 @@
</div>
<br class="clear" />
{% if g.user %}
{% if post[5]==0 %}<b style="color:red;">Private</b>{% else %}<b style="color:green;">Public</b>{% endif %} | <a href="{{url_for('blog.delete', pid=post[0], location='blog')}}" class="danger">Delete post</a>
{% if post[5]==0 %}<b style="color:red;">Private</b>{% else %}<b style="color:green;">Public</b>{% endif %} | <a href="{{url_for('blog.toggle',pid=post[0], location='blog')}}">Toggle privacy</a> | <a href="{{url_for('blog.delete', pid=post[0], location='blog')}}" class="danger">Delete post</a>
{% endif %}
</div>
{% endif %}

View File

@@ -30,7 +30,7 @@
<div class="content">
{{post[4]|safe}}
</div>
{% if g.user %}<a href="{{url_for('blog.delete', pid=post[0], location=member[0])}}" class="danger">Delete post</a>{% endif %}
<a href="{{url_for('blog.toggle',pid=post[0], location=member[0])}}">Toggle privacy</a> | {% if g.user %}<a href="{{url_for('blog.delete', pid=post[0], location=member[0])}}" class="danger">Delete post</a>{% endif %}
</div>
{% endif %}
{% endfor %}