Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #2000 -- Added 'mimetype' parameter to generic views. Thanks, I…

…an Holsman

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3022 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 903023665223bca3e63aa0da4ef6c16adff47950 1 parent 7098389
Adrian Holovaty authored May 31, 2006
26  django/views/generic/date_based.py
@@ -6,7 +6,8 @@
6 6
 
7 7
 def archive_index(request, queryset, date_field, num_latest=15,
8 8
         template_name=None, template_loader=loader,
9  
-        extra_context={}, allow_empty=False, context_processors=None):
  9
+        extra_context={}, allow_empty=False, context_processors=None,
  10
+        mimetype=None):
10 11
     """
11 12
     Generic top-level archive of date-based objects.
12 13
 
@@ -40,11 +41,11 @@ def archive_index(request, queryset, date_field, num_latest=15,
40 41
             c[key] = value()
41 42
         else:
42 43
             c[key] = value
43  
-    return HttpResponse(t.render(c))
  44
+    return HttpResponse(t.render(c), mimetype=mimetype)
44 45
 
45 46
 def archive_year(request, year, queryset, date_field, template_name=None,
46 47
         template_loader=loader, extra_context={}, allow_empty=False,
47  
-        context_processors=None):
  48
+        context_processors=None, mimetype=None):
48 49
     """
49 50
     Generic yearly archive view.
50 51
 
@@ -78,12 +79,12 @@ def archive_year(request, year, queryset, date_field, template_name=None,
78 79
             c[key] = value()
79 80
         else:
80 81
             c[key] = value
81  
-    return HttpResponse(t.render(c))
  82
+    return HttpResponse(t.render(c), mimetype=mimetype)
82 83
 
83 84
 def archive_month(request, year, month, queryset, date_field,
84 85
         month_format='%b', template_name=None, template_loader=loader,
85 86
         extra_context={}, allow_empty=False, context_processors=None,
86  
-        template_object_name='object'):
  87
+        template_object_name='object', mimetype=None):
87 88
     """
88 89
     Generic monthly archive view.
89 90
 
@@ -134,12 +135,12 @@ def archive_month(request, year, month, queryset, date_field,
134 135
             c[key] = value()
135 136
         else:
136 137
             c[key] = value
137  
-    return HttpResponse(t.render(c))
  138
+    return HttpResponse(t.render(c), mimetype=mimetype)
138 139
 
139 140
 def archive_week(request, year, week, queryset, date_field,
140 141
         template_name=None, template_loader=loader,
141 142
         extra_context={}, allow_empty=True, context_processors=None,
142  
-        template_object_name='object'):
  143
+        template_object_name='object', mimetype=None):
143 144
     """
144 145
     Generic weekly archive view.
145 146
 
@@ -181,12 +182,13 @@ def archive_week(request, year, week, queryset, date_field,
181 182
             c[key] = value()
182 183
         else:
183 184
             c[key] = value
184  
-    return HttpResponse(t.render(c))
  185
+    return HttpResponse(t.render(c), mimetype=mimetype)
185 186
 
186 187
 def archive_day(request, year, month, day, queryset, date_field,
187 188
         month_format='%b', day_format='%d', template_name=None,
188 189
         template_loader=loader, extra_context={}, allow_empty=False,
189  
-        context_processors=None, template_object_name='object'):
  190
+        context_processors=None, template_object_name='object',
  191
+        mimetype=None):
190 192
     """
191 193
     Generic daily archive view.
192 194
 
@@ -233,7 +235,7 @@ def archive_day(request, year, month, day, queryset, date_field,
233 235
             c[key] = value()
234 236
         else:
235 237
             c[key] = value
236  
-    return HttpResponse(t.render(c))
  238
+    return HttpResponse(t.render(c), mimetype=mimetype)
237 239
 
238 240
 def archive_today(request, **kwargs):
239 241
     """
@@ -251,7 +253,7 @@ def object_detail(request, year, month, day, queryset, date_field,
251 253
         month_format='%b', day_format='%d', object_id=None, slug=None,
252 254
         slug_field=None, template_name=None, template_name_field=None,
253 255
         template_loader=loader, extra_context={}, context_processors=None,
254  
-        template_object_name='object'):
  256
+        template_object_name='object', mimetype=None):
255 257
     """
256 258
     Generic detail view from year/month/day/slug or year/month/day/id structure.
257 259
 
@@ -300,6 +302,6 @@ def object_detail(request, year, month, day, queryset, date_field,
300 302
             c[key] = value()
301 303
         else:
302 304
             c[key] = value
303  
-    response = HttpResponse(t.render(c))
  305
+    response = HttpResponse(t.render(c), mimetype=mimetype)
304 306
     populate_xheaders(request, response, model, getattr(obj, obj._meta.pk.name))
305 307
     return response
10  django/views/generic/list_detail.py
@@ -6,7 +6,8 @@
6 6
 
7 7
 def object_list(request, queryset, paginate_by=None, allow_empty=False,
8 8
         template_name=None, template_loader=loader,
9  
-        extra_context={}, context_processors=None, template_object_name='object'):
  9
+        extra_context={}, context_processors=None, template_object_name='object',
  10
+        mimetype=None):
10 11
     """
11 12
     Generic list of objects.
12 13
 
@@ -73,12 +74,13 @@ def object_list(request, queryset, paginate_by=None, allow_empty=False,
73 74
         model = queryset.model
74 75
         template_name = "%s/%s_list.html" % (model._meta.app_label, model._meta.object_name.lower())
75 76
     t = template_loader.get_template(template_name)
76  
-    return HttpResponse(t.render(c))
  77
+    return HttpResponse(t.render(c), mimetype=mimetype)
77 78
 
78 79
 def object_detail(request, queryset, object_id=None, slug=None,
79 80
         slug_field=None, template_name=None, template_name_field=None,
80 81
         template_loader=loader, extra_context={},
81  
-        context_processors=None, template_object_name='object'):
  82
+        context_processors=None, template_object_name='object',
  83
+        mimetype=None):
82 84
     """
83 85
     Generic list of objects.
84 86
 
@@ -113,6 +115,6 @@ def object_detail(request, queryset, object_id=None, slug=None,
113 115
             c[key] = value()
114 116
         else:
115 117
             c[key] = value
116  
-    response = HttpResponse(t.render(c))
  118
+    response = HttpResponse(t.render(c), mimetype=mimetype)
117 119
     populate_xheaders(request, response, model, getattr(obj, obj._meta.pk.name))
118 120
     return response
24  docs/generic_views.txt
@@ -182,6 +182,9 @@ a date in the *future* are not included.
182 182
     * ``context_processors``: A list of template-context processors to apply to
183 183
       the view's template. See the `RequestContext docs`_.
184 184
 
  185
+    * ``mimetype``: The MIME type to use for the resulting document. Defaults
  186
+      to the value of the ``DEFAULT_MIME_TYPE`` setting.
  187
+
185 188
 **Template name:**
186 189
 
187 190
 If ``template_name`` isn't specified, this view will use the template
@@ -247,6 +250,9 @@ with a date in the *future* are not displayed.
247 250
     * ``context_processors``: A list of template-context processors to apply to
248 251
       the view's template. See the `RequestContext docs`_.
249 252
 
  253
+    * ``mimetype``: The MIME type to use for the resulting document. Defaults
  254
+      to the value of the ``DEFAULT_MIME_TYPE`` setting.
  255
+
250 256
 **Template name:**
251 257
 
252 258
 If ``template_name`` isn't specified, this view will use the template
@@ -314,6 +320,9 @@ date in the *future* are not displayed.
314 320
        view will append ``'_list'`` to the value of this parameter in
315 321
        determining the variable's name.
316 322
 
  323
+    * ``mimetype``: The MIME type to use for the resulting document. Defaults
  324
+      to the value of the ``DEFAULT_MIME_TYPE`` setting.
  325
+
317 326
 **Template name:**
318 327
 
319 328
 If ``template_name`` isn't specified, this view will use the template
@@ -387,6 +396,9 @@ in the *future* are not displayed.
387 396
        view will append ``'_list'`` to the value of this parameter in
388 397
        determining the variable's name.
389 398
 
  399
+    * ``mimetype``: The MIME type to use for the resulting document. Defaults
  400
+      to the value of the ``DEFAULT_MIME_TYPE`` setting.
  401
+
390 402
 **Template name:**
391 403
 
392 404
 If ``template_name`` isn't specified, this view will use the template
@@ -463,6 +475,9 @@ a 404 error, regardless of whether any objects exist for future days.
463 475
        view will append ``'_list'`` to the value of this parameter in
464 476
        determining the variable's name.
465 477
 
  478
+    * ``mimetype``: The MIME type to use for the resulting document. Defaults
  479
+      to the value of the ``DEFAULT_MIME_TYPE`` setting.
  480
+
466 481
 **Template name:**
467 482
 
468 483
 If ``template_name`` isn't specified, this view will use the template
@@ -563,6 +578,9 @@ A page representing an individual object.
563 578
     * ``template_object_name``:  Designates the name of the template variable
564 579
        to use in the template context. By default, this is ``'object'``.
565 580
 
  581
+    * ``mimetype``: The MIME type to use for the resulting document. Defaults
  582
+      to the value of the ``DEFAULT_MIME_TYPE`` setting.
  583
+
566 584
 **Template name:**
567 585
 
568 586
 If ``template_name`` isn't specified, this view will use the template
@@ -627,6 +645,9 @@ A page representing a list of objects.
627 645
        view will append ``'_list'`` to the value of this parameter in
628 646
        determining the variable's name.
629 647
 
  648
+    * ``mimetype``: The MIME type to use for the resulting document. Defaults
  649
+      to the value of the ``DEFAULT_MIME_TYPE`` setting.
  650
+
630 651
 **Template name:**
631 652
 
632 653
 If ``template_name`` isn't specified, this view will use the template
@@ -717,6 +738,9 @@ A page representing an individual object.
717 738
     * ``template_object_name``:  Designates the name of the template variable
718 739
        to use in the template context. By default, this is ``'object'``.
719 740
 
  741
+    * ``mimetype``: The MIME type to use for the resulting document. Defaults
  742
+      to the value of the ``DEFAULT_MIME_TYPE`` setting.
  743
+
720 744
 **Template name:**
721 745
 
722 746
 If ``template_name`` isn't specified, this view will use the template

0 notes on commit 9030236

Please sign in to comment.
Something went wrong with that request. Please try again.