1
0
Fork 0

Add the ability to edit users' comments

pull/2/head
Noah 2014-09-11 22:26:45 -07:00
commit fd5f4ce57d
5 arquivos alterados com 102 adições e 1 exclusões

Ver arquivo

@ -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)

Ver arquivo

@ -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."""

Ver arquivo

@ -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 %}

Ver arquivo

@ -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>

Ver arquivo

@ -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
*********************/