summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2011-12-17 03:53:25 +0000
committerAdrian Holovaty <adrian@holovaty.com>2011-12-17 03:53:25 +0000
commit8767439af45d94025210ea13d0d4be465553b855 (patch)
tree50be83ef34865478e183c7b1277a3c4bffc7c308
parentd3055b3382363163c3352347e69c47f58c3d49a1 (diff)
Converted some of the built-in views to use content_type instead of mimetype HttpResponse argument. Refs #16519
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17223 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/contrib/gis/shortcuts.py7
-rw-r--r--django/contrib/gis/sitemaps/views.py4
-rw-r--r--django/contrib/sitemaps/views.py13
-rw-r--r--django/contrib/syndication/views.py2
-rw-r--r--django/views/generic/simple.py2
-rw-r--r--docs/ref/request-response.txt6
6 files changed, 15 insertions, 19 deletions
diff --git a/django/contrib/gis/shortcuts.py b/django/contrib/gis/shortcuts.py
index 9a80f4df29..1ca6bbb645 100644
--- a/django/contrib/gis/shortcuts.py
+++ b/django/contrib/gis/shortcuts.py
@@ -20,7 +20,7 @@ def compress_kml(kml):
def render_to_kml(*args, **kwargs):
"Renders the response as KML (using the correct MIME type)."
return HttpResponse(loader.render_to_string(*args, **kwargs),
- mimetype='application/vnd.google-earth.kml+xml')
+ content_type='application/vnd.google-earth.kml+xml')
def render_to_kmz(*args, **kwargs):
"""
@@ -28,10 +28,9 @@ def render_to_kmz(*args, **kwargs):
MIME type).
"""
return HttpResponse(compress_kml(loader.render_to_string(*args, **kwargs)),
- mimetype='application/vnd.google-earth.kmz')
-
+ content_type='application/vnd.google-earth.kmz')
def render_to_text(*args, **kwargs):
"Renders the response using the MIME type for plain text."
return HttpResponse(loader.render_to_string(*args, **kwargs),
- mimetype='text/plain')
+ content_type='text/plain')
diff --git a/django/contrib/gis/sitemaps/views.py b/django/contrib/gis/sitemaps/views.py
index e4ac9f74a3..eb2454c389 100644
--- a/django/contrib/gis/sitemaps/views.py
+++ b/django/contrib/gis/sitemaps/views.py
@@ -30,7 +30,7 @@ def index(request, sitemaps):
for page in range(2, pages+1):
sites.append('%s://%s%s?p=%s' % (protocol, current_site.domain, sitemap_url, page))
xml = loader.render_to_string('sitemap_index.xml', {'sitemaps': sites})
- return HttpResponse(xml, mimetype='application/xml')
+ return HttpResponse(xml, content_type='application/xml')
def sitemap(request, sitemaps, section=None):
"""
@@ -58,7 +58,7 @@ def sitemap(request, sitemaps, section=None):
except PageNotAnInteger:
raise Http404("No page '%s'" % page)
xml = smart_str(loader.render_to_string('gis/sitemaps/geo_sitemap.xml', {'urlset': urls}))
- return HttpResponse(xml, mimetype='application/xml')
+ return HttpResponse(xml, content_type='application/xml')
def kml(request, label, model, field_name=None, compress=False, using=DEFAULT_DB_ALIAS):
"""
diff --git a/django/contrib/sitemaps/views.py b/django/contrib/sitemaps/views.py
index d82146c0ea..14af5f1e4c 100644
--- a/django/contrib/sitemaps/views.py
+++ b/django/contrib/sitemaps/views.py
@@ -1,12 +1,10 @@
+from django.contrib.sites.models import get_current_site
from django.core import urlresolvers
from django.core.paginator import EmptyPage, PageNotAnInteger
from django.http import Http404
from django.template.response import TemplateResponse
-from django.contrib.sites.models import get_current_site
-
-def index(request, sitemaps,
- template_name='sitemap_index.xml', mimetype='application/xml'):
+def index(request, sitemaps, template_name='sitemap_index.xml', mimetype='application/xml'):
current_site = get_current_site(request)
sites = []
protocol = request.is_secure() and 'https' or 'http'
@@ -21,10 +19,9 @@ def index(request, sitemaps,
if pages > 1:
for page in range(2, pages+1):
sites.append('%s://%s%s?p=%s' % (protocol, current_site.domain, sitemap_url, page))
- return TemplateResponse(request, template_name, {'sitemaps': sites}, mimetype=mimetype)
+ return TemplateResponse(request, template_name, {'sitemaps': sites}, content_type=mimetype)
-def sitemap(request, sitemaps, section=None,
- template_name='sitemap.xml', mimetype='application/xml'):
+def sitemap(request, sitemaps, section=None, template_name='sitemap.xml', mimetype='application/xml'):
maps, urls = [], []
if section is not None:
if section not in sitemaps:
@@ -43,4 +40,4 @@ def sitemap(request, sitemaps, section=None,
raise Http404("Page %s empty" % page)
except PageNotAnInteger:
raise Http404("No page '%s'" % page)
- return TemplateResponse(request, template_name, {'urlset': urls}, mimetype=mimetype) \ No newline at end of file
+ return TemplateResponse(request, template_name, {'urlset': urls}, content_type=mimetype)
diff --git a/django/contrib/syndication/views.py b/django/contrib/syndication/views.py
index 2480ff6caa..462b3e94cf 100644
--- a/django/contrib/syndication/views.py
+++ b/django/contrib/syndication/views.py
@@ -36,7 +36,7 @@ class Feed(object):
except ObjectDoesNotExist:
raise Http404('Feed object does not exist.')
feedgen = self.get_feed(obj, request)
- response = HttpResponse(mimetype=feedgen.mime_type)
+ response = HttpResponse(content_type=feedgen.mime_type)
feedgen.write(response, 'utf-8')
return response
diff --git a/django/views/generic/simple.py b/django/views/generic/simple.py
index c3cf407163..f7b4b1c2b1 100644
--- a/django/views/generic/simple.py
+++ b/django/views/generic/simple.py
@@ -25,7 +25,7 @@ def direct_to_template(request, template, extra_context=None, mimetype=None, **k
dictionary[key] = value
c = RequestContext(request, dictionary)
t = loader.get_template(template)
- return HttpResponse(t.render(c), mimetype=mimetype)
+ return HttpResponse(t.render(c), content_type=mimetype)
def redirect_to(request, url, permanent=True, query_string=False, **kwargs):
"""
diff --git a/docs/ref/request-response.txt b/docs/ref/request-response.txt
index 302a061089..4bbfac4b55 100644
--- a/docs/ref/request-response.txt
+++ b/docs/ref/request-response.txt
@@ -538,7 +538,7 @@ Typical usage is to pass the contents of the page, as a string, to the
>>> from django.http import HttpResponse
>>> response = HttpResponse("Here's the text of the Web page.")
- >>> response = HttpResponse("Text only, please.", mimetype="text/plain")
+ >>> response = HttpResponse("Text only, please.", content_type="text/plain")
But if you want to add content incrementally, you can use ``response`` as a
file-like object::
@@ -577,10 +577,10 @@ Telling the browser to treat the response as a file attachment
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To tell the browser to treat the response as a file attachment, use the
-``mimetype`` argument and set the ``Content-Disposition`` header. For example,
+``content_type`` argument and set the ``Content-Disposition`` header. For example,
this is how you might return a Microsoft Excel spreadsheet::
- >>> response = HttpResponse(my_data, mimetype='application/vnd.ms-excel')
+ >>> response = HttpResponse(my_data, content_type='application/vnd.ms-excel')
>>> response['Content-Disposition'] = 'attachment; filename=foo.xls'
There's nothing Django-specific about the ``Content-Disposition`` header, but