diff farol/main.py @ 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 69e0330c4fae
children 752b8bfe0baf
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():

http://farol.wald.intevation.org