def export_results(short_name): """Export project results as an XML or CSV file. :param short_name: The short name of the project. """ project = project_repo.get_by_shortname(short_name) if project is None: # pragma: no cover abort(404) fmt = request.args.get('format') export_formats = ["xml", "csv"] if not fmt: if len(request.args) >= 1: abort(404) return redirect(url_for('.index')) results = result_repo.filter_by(project_id=project.id) if fmt not in export_formats: abort(415) elif fmt == "xml": resp = get_xml_response(results) elif fmt == "csv": resp = get_csv_response(results) exporter = Exporter() name = exporter._project_name_latin_encoded(project) secure_name = secure_filename('{0}_results.{1}'.format(name, fmt)) fn = "filename={0}".format(secure_name) resp.headers["Content-Disposition"] = "attachment; {0}".format(fn) resp.headers["Content-type"] = "text/{0}".format(fmt) resp.headers['Cache-Control'] = "no-store, no-cache, must-revalidate, \ post-check=0, pre-check=0, max-age=0" return resp