changeset 29:891ee029a899

Offer to download the rendered document.
author Benoît Allard <benoit.allard@greenbone.net>
date Thu, 02 Oct 2014 12:37:49 +0200
parents 6c65b16f2680
children 762cb7b3b422
files farol/main.py farol/templates/render.j2
diffstat 2 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/farol/main.py	Thu Oct 02 12:09:28 2014 +0200
+++ b/farol/main.py	Thu Oct 02 12:37:49 2014 +0200
@@ -37,7 +37,8 @@
 from farolluz.utils import utcnow
 
 import flask
-from flask import Flask, request, render_template, redirect, url_for, flash
+from flask import (Flask, request, render_template, redirect, url_for, flash,
+     make_response)
 from werkzeug import secure_filename
 
 from . import __version__, cache
@@ -180,7 +181,13 @@
 def render(format_):
     cvrf = get_current()
     doc = render_cvrf(cvrf, format_ + '.j2')
-    return render_template('render.j2', format_=format_, title=cvrf._title, type_=cvrf._type, doc=doc )
+    if 'raw' not in request.args:
+        return render_template('render.j2', format_=format_, title=cvrf._title, type_=cvrf._type, doc=doc)
+    response = make_response(doc)
+    filename = secure_filename(cvrf._tracking._identification._id) + "." + format_
+    response.headers["content-disposition"] = 'attachement; filename=' + filename
+    response.headers["content-type"] = 'text/plain'
+    return response
 
 @app.route('/about')
 def about():
--- a/farol/templates/render.j2	Thu Oct 02 12:09:28 2014 +0200
+++ b/farol/templates/render.j2	Thu Oct 02 12:37:49 2014 +0200
@@ -33,5 +33,7 @@
 <div class='clearfix page-header'>
   <h1>{{ title }} <small>({{ type_ }})</small></h1>
 </div>
+<p><a class="btn btn-success" href="{{ url_for('render', format_=format_, raw=1) }}">Download</a></p>
 <pre>{{ doc | escape }}</pre>
+<p><a class="btn btn-success" href="{{ url_for('render', format_=format_, raw=1) }}">Download</a></p>
 {% endblock %}

http://farol.wald.intevation.org