Browse Source

Add the ability to edit users' comments

pull/2/head
Noah Petherbridge 5 years ago
parent
commit
fd5f4ce57d
5 changed files with 102 additions and 1 deletions
  1. +14
    -0
      rophako/model/comment.py
  2. +39
    -0
      rophako/modules/comment/__init__.py
  3. +30
    -0
      rophako/modules/comment/templates/comment/edit.html
  4. +5
    -1
      rophako/modules/comment/templates/comment/index.inc.html
  5. +14
    -0
      rophako/www/smoke/style.css

+ 14
- 0
rophako/model/comment.py View File

@@ -112,6 +112,20 @@ URL: {unsub}""".format(
)


def get_comment(thread, cid):
"""Look up a specific comment."""
comments = get_comments(thread)
return comments.get(cid, None)


def update_comment(thread, cid, data):
"""Update the data for a comment."""
comments = get_comments(thread)
if cid in comments:
comments[cid].update(data)
write_comments(thread, comments)


def delete_comment(thread, cid):
"""Delete a comment from a thread."""
comments = get_comments(thread)


+ 39
- 0
rophako/modules/comment/__init__.py View File

@@ -86,6 +86,45 @@ def delete(thread, cid):
return redirect(url or url_for("index"))


@mod.route("/edit/<thread>/<cid>", methods=["GET", "POST"])
@login_required
def edit(thread, cid):
"""Edit an existing comment."""
url = request.args.get("url")
comment = Comment.get_comment(thread, cid)
if not comment:
flash("The comment wasn't found!")
return redirect(url or url_for("index"))

# Submitting?
if request.method == "POST":
action = request.form.get("action")
message = request.form.get("message")
url = request.form.get("url") # Preserve the URL!
if len(message) == 0:
flash("The comment must have a message!")
return redirect(url_for(".edit", thread=thread, cid=cid, url=url))

# Update the real comment data with the submitted message (for preview),
# if they clicked Save it will then be saved back to disk.
comment["message"] = message

if action == "save":
# Saving the changes!
Comment.update_comment(thread, cid, comment)
flash("Comment updated successfully!")
return redirect(url or url_for("index"))

# Render the Markdown.
comment["formatted_message"] = Comment.format_message(comment["message"])

g.info["thread"] = thread
g.info["cid"] = cid
g.info["comment"] = comment
g.info["url"] = url or ""
return template("comment/edit.html")


@mod.route("/privacy")
def privacy():
"""The privacy policy and global unsubscribe page."""


+ 30
- 0
rophako/modules/comment/templates/comment/edit.html View File

@@ -0,0 +1,30 @@
{% extends "layout.html" %}
{% block title %}Edit Comment{% endblock %}
{% block content %}

<h1>Edit Comment</h1>

Current preview of the comment:<p>

<div class="comment">
{{ comment["formatted_message"]|safe }}
</div>

<h2>Edit Comment</h2>

<form name="editor" action="{{ url_for('comment.edit', thread=thread, cid=cid) }}" method="POST">
<input type="hidden" name="token" value="{{ csrf_token() }}">
<input type="hidden" name="url" value="{{ url }}">


<strong>Message:</strong><br>
<textarea cols="40" rows="8" name="message">{{ comment["message"] }}</textarea><br>
<small>Comments can be formatted with <a href="/markdown" target="_blank">Markdown</a>,
and you can use<br><a href="{{ url_for('emoticons.index') }}" target="_blank">emoticons</a>
in your comment.</small><p>

<button type="submit" name="action" value="preview">Preview Comment</button>
<button type="submit" name="action" value="save">Save</button>
</form>

{% endblock %}

+ 5
- 1
rophako/modules/comment/templates/comment/index.inc.html View File

@@ -26,7 +26,11 @@ There {% if comments|length == 1 %}is{% else %}are{% endif %}

<div class="clear">
{% if session["login"] %}
[IP: {{ comment["ip"] }} | <a href="{{ url_for('comment.delete', thread=thread, cid=comment['id'], url=url) }}" onclick="return window.confirm('Are you sure?')">Delete</a>]
[IP: {{ comment["ip"] }}
|
<a href="{{ url_for('comment.edit', thread=thread, cid=comment['id'], url=url) }}">Edit</a>
|
<a href="{{ url_for('comment.delete', thread=thread, cid=comment['id'], url=url) }}" onclick="return window.confirm('Are you sure?')">Delete</a>]
{% endif %}
</div>
</div><p>


+ 14
- 0
rophako/www/smoke/style.css View File

@@ -294,6 +294,20 @@ ul.blog-categories li:last-child:after {
padding: 5px
}

/* Style overrides for comments */
.comment h1 {
font-size: 14pt;
}
.comment h2 {
font-size: 12pt;
}
.comment h3 {
font-size: 10pt;
}
.comment h4 {
font-size: 9pt;
}

/*********************
* Smoke Theme UI
*********************/


Loading…
Cancel
Save