diff --git a/rophako/model/comment.py b/rophako/model/comment.py index 6c3fbde..fef3a39 100644 --- a/rophako/model/comment.py +++ b/rophako/model/comment.py @@ -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) diff --git a/rophako/modules/comment/__init__.py b/rophako/modules/comment/__init__.py index 12f6a50..5594ede 100644 --- a/rophako/modules/comment/__init__.py +++ b/rophako/modules/comment/__init__.py @@ -86,6 +86,45 @@ def delete(thread, cid): return redirect(url or url_for("index")) +@mod.route("/edit//", 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.""" diff --git a/rophako/modules/comment/templates/comment/edit.html b/rophako/modules/comment/templates/comment/edit.html new file mode 100644 index 0000000..9a532fa --- /dev/null +++ b/rophako/modules/comment/templates/comment/edit.html @@ -0,0 +1,30 @@ +{% extends "layout.html" %} +{% block title %}Edit Comment{% endblock %} +{% block content %} + +

Edit Comment

+ +Current preview of the comment:

+ +

+ {{ comment["formatted_message"]|safe }} +
+ +

Edit Comment

+ +
+ + + + + Message:
+
+ Comments can be formatted with Markdown, + and you can use
emoticons + in your comment.

+ + + +

+ +{% endblock %} \ No newline at end of file diff --git a/rophako/modules/comment/templates/comment/index.inc.html b/rophako/modules/comment/templates/comment/index.inc.html index 96a4bb0..ec06d45 100644 --- a/rophako/modules/comment/templates/comment/index.inc.html +++ b/rophako/modules/comment/templates/comment/index.inc.html @@ -26,7 +26,11 @@ There {% if comments|length == 1 %}is{% else %}are{% endif %}
{% if session["login"] %} - [IP: {{ comment["ip"] }} | Delete] + [IP: {{ comment["ip"] }} + | + Edit + | + Delete] {% endif %}

diff --git a/rophako/www/smoke/style.css b/rophako/www/smoke/style.css index 502306a..2f82b40 100644 --- a/rophako/www/smoke/style.css +++ b/rophako/www/smoke/style.css @@ -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 *********************/