aboutsummaryrefslogtreecommitdiffstats
path: root/famille.py
diff options
context:
space:
mode:
authorThibaut Horel <thibaut.horel@gmail.com>2015-04-01 21:30:26 -0400
committerThibaut Horel <thibaut.horel@gmail.com>2015-04-01 21:30:26 -0400
commitacd73bdf5f351445b4b66c28dd0e3a8883d4face (patch)
tree79dd1e2e2e862ef35b8c9aa56ecdc2fc424e9cc6 /famille.py
parentbe0df053aff9585b838290d4d6d9bc1716f56b8a (diff)
downloadfamille-flask-acd73bdf5f351445b4b66c28dd0e3a8883d4face.tar.gz
Add edit comment feature
This is handled in javascript. When clicking the edit link: 1. a form is shown to edit the RST source of the comment. 2. on submit, an AJAX POST request is sent to the new "comment" endpoint in the flask app. 3. the endpoint compiles the RST source, update the comment in the database and sends back formatted content to the client. 4. the client then updates the comment content and hides the form.
Diffstat (limited to 'famille.py')
-rw-r--r--famille.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/famille.py b/famille.py
index c1cedd3..d958bcb 100644
--- a/famille.py
+++ b/famille.py
@@ -2,7 +2,7 @@
import sqlite3
#all the imports
from flask import Flask, request, session, g, redirect,\
- url_for, render_template, flash
+ url_for, render_template, flash, jsonify
from functools import wraps
import hashlib
from pytz import timezone
@@ -203,6 +203,22 @@ def show_news(news_id):
return redirect(url_for('show_news', news_id=news_id))
+@app.route('/comment/<int:comment_id>', methods=['POST'])
+@login_required
+def update_comment(comment_id):
+ comment = query_db("SELECT * FROM comments WHERE comments.id = ?",
+ (comment_id,), True)
+ if comment["user_id"] == session["user_id"]:
+ content = request.form['content']
+ content_cache = rstify(content)
+ db = get_db()
+ db.execute("UPDATE comments set content=?, content_cache=? "
+ "WHERE comments.id=?",
+ (content, content_cache, comment_id))
+ db.commit()
+ return jsonify(content=content, content_cache=content_cache)
+
+
@app.route('/news/<int:news_id>/edit', methods=['GET', 'POST'])
@login_required
def edit_news(news_id):