Force browser to ask to save an Export, and provide a filename extension.
See: http://code.google.com/p/soc/issues/detail?id=192
Patch by: Todd Larsen
Review by: to-be-reviewed
--- a/app/soc/views/helper/responses.py Thu Feb 19 20:13:41 2009 +0000
+++ b/app/soc/views/helper/responses.py Thu Feb 19 20:24:17 2009 +0000
@@ -43,7 +43,8 @@
import soc.views.helper.requests
-def respond(request, template, context=None, response_args=None):
+def respond(request, template, context=None, response_args=None,
+ response_headers=None):
"""Helper to render a response, passing standard stuff to the response.
Args:
@@ -53,6 +54,9 @@
response_args: keyword arguments passed to http.HttpResponse()
(response_args['content'] is created with
render_to_string(template, dictionary=context) if it is not present)
+ response_headers: optional dict containing HTTP response header names
+ and corresponding values to set in the HttpResponse object before it
+ is returned; default is None
Returns:
django.shortcuts.render_to_response(template, context) results
@@ -70,7 +74,13 @@
response_args['content'] = response_args.get(
'content', loader.render_to_string(template, dictionary=context))
- return http.HttpResponse(**response_args)
+ http_response = http.HttpResponse(**response_args)
+
+ if response_headers:
+ for key, value in response_headers.iteritems():
+ http_response[key] = value
+
+ return http_response
def getUniversalContext(request):
--- a/app/soc/views/models/base.py Thu Feb 19 20:13:41 2009 +0000
+++ b/app/soc/views/models/base.py Thu Feb 19 20:24:17 2009 +0000
@@ -223,9 +223,13 @@
template = params['export_template']
response_args = {'mimetype': params['export_content_type']}
+ response_headers = {
+ 'Content-Disposition': 'attachment; filename=%s.txt' % entity.link_id,
+ }
return helper.responses.respond(request, template, context=context,
- response_args=response_args)
+ response_args=response_args,
+ response_headers=response_headers)
@decorators.check_access
def create(self, request, access_type,