From: Olivier Tétard Date: Thu, 19 Nov 2015 13:35:12 +0000 (+0100) Subject: Envoi de l’analyse dans un fichier AJAX plutôt que de l’inscrire directement dans... X-Git-Url: http://olivier.miskin.fr/git/?a=commitdiff_plain;h=832236e4e6a17d6ba23f99cedeba9949c013ddd0;p=femtoblackweb.git Envoi de l’analyse dans un fichier AJAX plutôt que de l’inscrire directement dans le code HTML de la page --- diff --git a/femtoblackweb.py b/femtoblackweb.py index 52223b5..fca80af 100644 --- a/femtoblackweb.py +++ b/femtoblackweb.py @@ -105,16 +105,22 @@ def analyze_file(filename): json_file = os.path.join(app.config['UPLOAD_FOLDER'], "{}.json".format(filename)) if os.path.exists(f) and os.path.isfile(json_file): - try: - with open(json_file) as json_f: - json_content = json.load(json_f) - return render_template('analyze_file.html', filename=filename, json=json_content) - except ValueError as e: - abort(503) + return render_template('analyze_file.html', filename=filename) else: abort(404) +@app.route('/ajax/analysis/') +def ajax_get_analysis(): + filename = request.args.get('filename') + try: + json_file = os.path.join(app.config['UPLOAD_FOLDER'], "{}.json".format(filename)) + with open(json_file) as json_f: + json_content = json.load(json_f) + return jsonify(**json_content) + + except ValueError as e: + abort(503) if __name__ == "__main__": app.run(debug=True) diff --git a/templates/analyze_file.html b/templates/analyze_file.html index 864678a..fecf314 100644 --- a/templates/analyze_file.html +++ b/templates/analyze_file.html @@ -47,26 +47,25 @@ {% endblock %}