Draft new comment submitting
This commit is contained in:
parent
37920f6c97
commit
504e0347bf
3 changed files with 88 additions and 18 deletions
|
@ -2,7 +2,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from flask import request, jsonify
|
from flask import request, jsonify, abort
|
||||||
from app import app
|
from app import app
|
||||||
from app.models.site import Site
|
from app.models.site import Site
|
||||||
from app.models.comment import Comment
|
from app.models.comment import Comment
|
||||||
|
@ -56,3 +56,51 @@ def get_comments_count():
|
||||||
r = jsonify({'count': 0})
|
r = jsonify({'count': 0})
|
||||||
r.status_code = 200
|
r.status_code = 200
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/comments", methods=['POST'])
|
||||||
|
def new_comment():
|
||||||
|
|
||||||
|
logger.info("new comment !!!!")
|
||||||
|
|
||||||
|
try:
|
||||||
|
token = request.form['token']
|
||||||
|
site = Site.select().where(Site.token == token).get()
|
||||||
|
|
||||||
|
# FOR DEBUG
|
||||||
|
return "OK"
|
||||||
|
|
||||||
|
source_url = request.headers.get('referer', '')
|
||||||
|
url = app.config["pecosys"]["post"]["redirect_url"]
|
||||||
|
|
||||||
|
if app.config["pecosys"]["post"]["redirect_referer"]:
|
||||||
|
url = app.config["pecosys"]["post"]["redirect_url"] + '?referer=' + request.headers.get('referer', '')
|
||||||
|
else:
|
||||||
|
url = request.headers.get('referer', app.config["pecosys"]["post"]["redirect_url"])
|
||||||
|
|
||||||
|
# get form values and create comment file
|
||||||
|
author = request.form['author']
|
||||||
|
email = request.form['email']
|
||||||
|
site = request.form['site']
|
||||||
|
article = request.form['article']
|
||||||
|
message = request.form['message']
|
||||||
|
subscribe = False
|
||||||
|
if "subscribe" in request.form and request.form['subscribe'] == "on":
|
||||||
|
subscribe = True
|
||||||
|
# honeypot for spammers
|
||||||
|
captcha = ""
|
||||||
|
if "captcha" in request.form:
|
||||||
|
captcha = request.form['captcha']
|
||||||
|
if captcha:
|
||||||
|
logger.warn("discard spam: captcha %s author %s email %s site %s article %s message %s"
|
||||||
|
% (captcha, author, email, site, article, message))
|
||||||
|
else:
|
||||||
|
req = {'type': 'comment', 'author': author, 'email': email, 'site': site, 'article': article,
|
||||||
|
'message': message, 'url': source_url, 'subscribe': subscribe}
|
||||||
|
processor.enqueue(req)
|
||||||
|
|
||||||
|
except:
|
||||||
|
logger.exception("new comment failure")
|
||||||
|
abort(400)
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
|
|
@ -90,13 +90,14 @@ en vaut la peine. Je l'utilise dans le cadre du projet
|
||||||
<a href="https://www.framabag.org/">Framabag</a> mais je prévois d'installer ma propre
|
<a href="https://www.framabag.org/">Framabag</a> mais je prévois d'installer ma propre
|
||||||
instance d'ici peu.</p>
|
instance d'ici peu.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="comment">
|
|
||||||
|
<div class="comment">
|
||||||
<div id="submit-button">
|
<div id="submit-button">
|
||||||
<a class="button-success pure-button" href="javascript:show_hide('comment-form','submit-button');">Commenter</a>
|
<a class="button-success pure-button" href="javascript:show_hide('comment-form','submit-button');">Commenter</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="comment-form" style="display:none">
|
<div id="comment-form" style="display:none">
|
||||||
<form class="pure-form" role="form" action="" onsubmit="this.action=get_action();" method="post">
|
<form class="pure-form" role="form" action="" autocomplete="off" method="post">
|
||||||
<fieldset class="pure-group">
|
<fieldset class="pure-group">
|
||||||
<input class="pure-u-1-2" id="author" name="author" placeholder="Nom ou Surnom *" required="" type="text">
|
<input class="pure-u-1-2" id="author" name="author" placeholder="Nom ou Surnom *" required="" type="text">
|
||||||
<input class="pure-u-1-2" id="email" name="email" placeholder="Adresse email (non publié)" type="email">
|
<input class="pure-u-1-2" id="email" name="email" placeholder="Adresse email (non publié)" type="email">
|
||||||
|
@ -119,8 +120,8 @@ instance d'ici peu.</p>
|
||||||
<input name="article" id="article" value="972b3e0144e82a9496a2ab9a275e7368" type="hidden">
|
<input name="article" id="article" value="972b3e0144e82a9496a2ab9a275e7368" type="hidden">
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<button onclick="preview_markdown(); return false" class="button-warning pure-button">Prévisualiser</button>
|
<button type="button" onclick="preview_markdown(); return false;" class="button-warning pure-button">Prévisualiser</button>
|
||||||
<button type="submit" class="button-success pure-button">Envoyer</button>
|
<button type="button" onclick="new_comment(); return false;" class="button-success pure-button">Envoyer</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
// --------------------------------------------------------------------------
|
||||||
|
// Common functions
|
||||||
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
function show_hide(panel_id, button_id){
|
function show_hide(panel_id, button_id){
|
||||||
if (document.getElementById(panel_id).style.display == 'none'){
|
if (document.getElementById(panel_id).style.display == 'none'){
|
||||||
document.getElementById(panel_id).style.display = '';
|
document.getElementById(panel_id).style.display = '';
|
||||||
|
@ -7,6 +11,23 @@ function show_hide(panel_id, button_id){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------------
|
||||||
|
// Load and display page comments
|
||||||
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
function initialize_comments() {
|
||||||
|
stacosys_count(comments_initialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
function comments_initialized(count) {
|
||||||
|
if (count > 0) {
|
||||||
|
if (count > 1) {
|
||||||
|
document.getElementById('show-comment-label').innerHTML = 'Voir les ' + count + ' commentaires';
|
||||||
|
}
|
||||||
|
document.getElementById('show-comments-button').style.display = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function show_comments() {
|
function show_comments() {
|
||||||
stacosys_load(comments_loaded);
|
stacosys_load(comments_loaded);
|
||||||
}
|
}
|
||||||
|
@ -21,18 +42,20 @@ function comments_loaded(response) {
|
||||||
document.getElementById('stacosys-comments').innerHTML = rendered;
|
document.getElementById('stacosys-comments').innerHTML = rendered;
|
||||||
}
|
}
|
||||||
|
|
||||||
function initialize_comments() {
|
// --------------------------------------------------------------------------
|
||||||
stacosys_count(comments_initialized);
|
// Submit a new comment
|
||||||
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
function new_comment() {
|
||||||
|
var author = document.getElementById('author').value;
|
||||||
|
// TODO make CORS POST request
|
||||||
|
// and asynchronously redirect depending on result
|
||||||
|
console.log('SUBMIT ' + author);
|
||||||
}
|
}
|
||||||
|
|
||||||
function comments_initialized(count) {
|
// --------------------------------------------------------------------------
|
||||||
if (count > 0) {
|
// Markdown preview
|
||||||
if (count > 1) {
|
// --------------------------------------------------------------------------
|
||||||
document.getElementById('show-comment-label').innerHTML = 'Voir les ' + count + ' commentaires';
|
|
||||||
}
|
|
||||||
document.getElementById('show-comments-button').style.display = '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function preview_markdown() {
|
function preview_markdown() {
|
||||||
if (document.getElementById('preview-container').style.display == 'none'){
|
if (document.getElementById('preview-container').style.display == 'none'){
|
||||||
|
@ -50,6 +73,4 @@ function Editor(input, preview) {
|
||||||
this.update();
|
this.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_action() {
|
|
||||||
return '/post_a_new_comment';
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue