# HG changeset patch # User BenoƮt Allard # Date 1412246269 -7200 # Node ID 891ee029a89929c36762c2d323b4e073637adbce # Parent 6c65b16f26803e11647f0f101616fcd73d96cc4e Offer to download the rendered document. diff -r 6c65b16f2680 -r 891ee029a899 farol/main.py --- 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(): diff -r 6c65b16f2680 -r 891ee029a899 farol/templates/render.j2 --- 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 @@ +

Download

{{ doc | escape }}
+

Download

{% endblock %}