Add delete button to comments

This commit is contained in:
David Hoppenbrouwers
2022-10-08 11:00:20 +02:00
parent 55285b82cc
commit 9f74e1a2af
6 changed files with 95 additions and 25 deletions

View File

@@ -1,13 +1,33 @@
{% macro author(name, ctime, mtime, thread_id, parent_id) %}
{% macro author(name, ctime, mtime) %}
<i>{{ name }} - {{ format_since(ctime) }}{% if ctime != mtime %} (last modified {{ format_since(mtime) }}){% endif %}</i>
{% endmacro %}
{% macro comment_author(comment, thread_id) %}
<p>
<sub>
<i>{{ name }} - {{ format_since(ctime) }}{% if ctime != mtime %} (last modified {{ format_since(mtime) }}){% endif %}</i>
{% if thread_id is not none %}
{{ author(comment.author, comment.create_time, comment.modify_time) }}
{# Suffixing a # prevents unnecessary reloads #}
<a href="{{ url_for('thread', thread_id = thread_id) }}#">thread</a>
{% if comment.parent_id is not none %}
<a href="{{ url_for('comment', comment_id = comment.parent_id) }}#">parent</a>
{% endif %}
{% if parent_id is not none %}
<a href="{{ url_for('comment', comment_id = parent_id) }}#">parent</a>
{% if comment.author_id == session.get('user_id') %}
{% endif %}
{% if comment.author_id == session.get('user_id') %}
<a href="{{ url_for('confirm_delete_comment', comment_id = comment.id) }}">delete</a>
{% endif %}
</sub>
</p>
{% endmacro %}
{% macro thread_author(author_id, name, ctime, mtime) %}
<p>
<sub>
{{ author(name, ctime, mtime) }}
{% if author_id == session.get('user_id') %}
{% endif %}
{% if author_id == session.get('user_id') %}
<a href="{{ url_for('confirm_delete_thread', thread_id = thread_id) }}">delete</a>
{% endif %}
</sub>
</p>
@@ -15,7 +35,7 @@
{% macro render_comment_pre(comment, thread_id) %}
<div class=comment>
{{ author(comment.author, comment.create_time, comment.modify_time, thread_id, comment.parent_id) }}
{{ comment_author(comment, thread_id) }}
<p>{{ minimd(comment.text) | safe }}</p>
{% endmacro %}

View File

@@ -2,10 +2,6 @@
{% from 'comment.html' import render_comment, render_comment_pre, render_comment_post, reply with context %}
{% block content %}
<sup><a href="{{ url_for('thread', thread_id = thread_id) }}">thread</a></sup>
{% if parent_id %}
<sup><a href="../{{ parent_id }}">parent</a></sup>
{% endif %}
{{ render_comment_pre(reply_comment, thread_id) }}

View File

@@ -0,0 +1,14 @@
{% extends 'base.html' %}
{% block content %}
<p>Are you sure you want to delete this comment on "{{ thread_title }}"?</p>
<div class=comment>{{ minimd(text) | safe }}</div>
<p>
<form method="post" action="../delete" style=inline>
<input type="submit" value="Yes">
</form>
<form method="get" action=".." style=inline>
<input type="submit" value="No">
</form>
</p>
{% endblock %}

View File

@@ -1,15 +1,8 @@
{% extends 'base.html' %}
{% from 'comment.html' import render_comment, reply, author as f_author with context %}
{% from 'comment.html' import render_comment, reply, thread_author with context %}
{% block content %}
{% if manage %}
<div>
<form method="get" action="confirm_delete/">
<input type="submit" value="Delete">
</form>
</div>
{% endif %}
<i>{{ f_author(author, create_time, modify_time, None, None) }}</i>
<i>{{ thread_author(author_id, author, create_time, modify_time) }}</i>
<p>{{ minimd(text) | safe }}</p>
{{ reply() }}