From 832236e4e6a17d6ba23f99cedeba9949c013ddd0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Olivier=20T=C3=A9tard?= Date: Thu, 19 Nov 2015 14:35:12 +0100 Subject: [PATCH] =?utf8?q?Envoi=20de=20l=E2=80=99analyse=20dans=20un=20fic?= =?utf8?q?hier=20AJAX=20plut=C3=B4t=20que=20de=20l=E2=80=99inscrire=20dire?= =?utf8?q?ctement=20dans=20le=20code=20HTML=20de=20la=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- femtoblackweb.py | 18 ++++++++++++------ templates/analyze_file.html | 18 +++++++++++++----- 2 files changed, 25 insertions(+), 11 deletions(-) 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 %} -- 2.30.2