mirror of https://github.com/django/django.git
Fixed #2000 -- Added 'mimetype' parameter to generic views. Thanks, Ian Holsman
git-svn-id: http://code.djangoproject.com/svn/django/trunk@3022 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
7098389fae
commit
9030236652
|
@ -6,7 +6,8 @@ import datetime, time
|
|||
|
||||
def archive_index(request, queryset, date_field, num_latest=15,
|
||||
template_name=None, template_loader=loader,
|
||||
extra_context={}, allow_empty=False, context_processors=None):
|
||||
extra_context={}, allow_empty=False, context_processors=None,
|
||||
mimetype=None):
|
||||
"""
|
||||
Generic top-level archive of date-based objects.
|
||||
|
||||
|
@ -40,11 +41,11 @@ def archive_index(request, queryset, date_field, num_latest=15,
|
|||
c[key] = value()
|
||||
else:
|
||||
c[key] = value
|
||||
return HttpResponse(t.render(c))
|
||||
return HttpResponse(t.render(c), mimetype=mimetype)
|
||||
|
||||
def archive_year(request, year, queryset, date_field, template_name=None,
|
||||
template_loader=loader, extra_context={}, allow_empty=False,
|
||||
context_processors=None):
|
||||
context_processors=None, mimetype=None):
|
||||
"""
|
||||
Generic yearly archive view.
|
||||
|
||||
|
@ -78,12 +79,12 @@ def archive_year(request, year, queryset, date_field, template_name=None,
|
|||
c[key] = value()
|
||||
else:
|
||||
c[key] = value
|
||||
return HttpResponse(t.render(c))
|
||||
return HttpResponse(t.render(c), mimetype=mimetype)
|
||||
|
||||
def archive_month(request, year, month, queryset, date_field,
|
||||
month_format='%b', template_name=None, template_loader=loader,
|
||||
extra_context={}, allow_empty=False, context_processors=None,
|
||||
template_object_name='object'):
|
||||
template_object_name='object', mimetype=None):
|
||||
"""
|
||||
Generic monthly archive view.
|
||||
|
||||
|
@ -134,12 +135,12 @@ def archive_month(request, year, month, queryset, date_field,
|
|||
c[key] = value()
|
||||
else:
|
||||
c[key] = value
|
||||
return HttpResponse(t.render(c))
|
||||
return HttpResponse(t.render(c), mimetype=mimetype)
|
||||
|
||||
def archive_week(request, year, week, queryset, date_field,
|
||||
template_name=None, template_loader=loader,
|
||||
extra_context={}, allow_empty=True, context_processors=None,
|
||||
template_object_name='object'):
|
||||
template_object_name='object', mimetype=None):
|
||||
"""
|
||||
Generic weekly archive view.
|
||||
|
||||
|
@ -181,12 +182,13 @@ def archive_week(request, year, week, queryset, date_field,
|
|||
c[key] = value()
|
||||
else:
|
||||
c[key] = value
|
||||
return HttpResponse(t.render(c))
|
||||
return HttpResponse(t.render(c), mimetype=mimetype)
|
||||
|
||||
def archive_day(request, year, month, day, queryset, date_field,
|
||||
month_format='%b', day_format='%d', template_name=None,
|
||||
template_loader=loader, extra_context={}, allow_empty=False,
|
||||
context_processors=None, template_object_name='object'):
|
||||
context_processors=None, template_object_name='object',
|
||||
mimetype=None):
|
||||
"""
|
||||
Generic daily archive view.
|
||||
|
||||
|
@ -233,7 +235,7 @@ def archive_day(request, year, month, day, queryset, date_field,
|
|||
c[key] = value()
|
||||
else:
|
||||
c[key] = value
|
||||
return HttpResponse(t.render(c))
|
||||
return HttpResponse(t.render(c), mimetype=mimetype)
|
||||
|
||||
def archive_today(request, **kwargs):
|
||||
"""
|
||||
|
@ -251,7 +253,7 @@ def object_detail(request, year, month, day, queryset, date_field,
|
|||
month_format='%b', day_format='%d', object_id=None, slug=None,
|
||||
slug_field=None, template_name=None, template_name_field=None,
|
||||
template_loader=loader, extra_context={}, context_processors=None,
|
||||
template_object_name='object'):
|
||||
template_object_name='object', mimetype=None):
|
||||
"""
|
||||
Generic detail view from year/month/day/slug or year/month/day/id structure.
|
||||
|
||||
|
@ -300,6 +302,6 @@ def object_detail(request, year, month, day, queryset, date_field,
|
|||
c[key] = value()
|
||||
else:
|
||||
c[key] = value
|
||||
response = HttpResponse(t.render(c))
|
||||
response = HttpResponse(t.render(c), mimetype=mimetype)
|
||||
populate_xheaders(request, response, model, getattr(obj, obj._meta.pk.name))
|
||||
return response
|
||||
|
|
|
@ -6,7 +6,8 @@ from django.core.exceptions import ObjectDoesNotExist
|
|||
|
||||
def object_list(request, queryset, paginate_by=None, allow_empty=False,
|
||||
template_name=None, template_loader=loader,
|
||||
extra_context={}, context_processors=None, template_object_name='object'):
|
||||
extra_context={}, context_processors=None, template_object_name='object',
|
||||
mimetype=None):
|
||||
"""
|
||||
Generic list of objects.
|
||||
|
||||
|
@ -73,12 +74,13 @@ def object_list(request, queryset, paginate_by=None, allow_empty=False,
|
|||
model = queryset.model
|
||||
template_name = "%s/%s_list.html" % (model._meta.app_label, model._meta.object_name.lower())
|
||||
t = template_loader.get_template(template_name)
|
||||
return HttpResponse(t.render(c))
|
||||
return HttpResponse(t.render(c), mimetype=mimetype)
|
||||
|
||||
def object_detail(request, queryset, object_id=None, slug=None,
|
||||
slug_field=None, template_name=None, template_name_field=None,
|
||||
template_loader=loader, extra_context={},
|
||||
context_processors=None, template_object_name='object'):
|
||||
context_processors=None, template_object_name='object',
|
||||
mimetype=None):
|
||||
"""
|
||||
Generic list of objects.
|
||||
|
||||
|
@ -113,6 +115,6 @@ def object_detail(request, queryset, object_id=None, slug=None,
|
|||
c[key] = value()
|
||||
else:
|
||||
c[key] = value
|
||||
response = HttpResponse(t.render(c))
|
||||
response = HttpResponse(t.render(c), mimetype=mimetype)
|
||||
populate_xheaders(request, response, model, getattr(obj, obj._meta.pk.name))
|
||||
return response
|
||||
|
|
|
@ -182,6 +182,9 @@ a date in the *future* are not included.
|
|||
* ``context_processors``: A list of template-context processors to apply to
|
||||
the view's template. See the `RequestContext docs`_.
|
||||
|
||||
* ``mimetype``: The MIME type to use for the resulting document. Defaults
|
||||
to the value of the ``DEFAULT_MIME_TYPE`` setting.
|
||||
|
||||
**Template name:**
|
||||
|
||||
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.
|
|||
* ``context_processors``: A list of template-context processors to apply to
|
||||
the view's template. See the `RequestContext docs`_.
|
||||
|
||||
* ``mimetype``: The MIME type to use for the resulting document. Defaults
|
||||
to the value of the ``DEFAULT_MIME_TYPE`` setting.
|
||||
|
||||
**Template name:**
|
||||
|
||||
If ``template_name`` isn't specified, this view will use the template
|
||||
|
@ -314,6 +320,9 @@ date in the *future* are not displayed.
|
|||
view will append ``'_list'`` to the value of this parameter in
|
||||
determining the variable's name.
|
||||
|
||||
* ``mimetype``: The MIME type to use for the resulting document. Defaults
|
||||
to the value of the ``DEFAULT_MIME_TYPE`` setting.
|
||||
|
||||
**Template name:**
|
||||
|
||||
If ``template_name`` isn't specified, this view will use the template
|
||||
|
@ -387,6 +396,9 @@ in the *future* are not displayed.
|
|||
view will append ``'_list'`` to the value of this parameter in
|
||||
determining the variable's name.
|
||||
|
||||
* ``mimetype``: The MIME type to use for the resulting document. Defaults
|
||||
to the value of the ``DEFAULT_MIME_TYPE`` setting.
|
||||
|
||||
**Template name:**
|
||||
|
||||
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.
|
|||
view will append ``'_list'`` to the value of this parameter in
|
||||
determining the variable's name.
|
||||
|
||||
* ``mimetype``: The MIME type to use for the resulting document. Defaults
|
||||
to the value of the ``DEFAULT_MIME_TYPE`` setting.
|
||||
|
||||
**Template name:**
|
||||
|
||||
If ``template_name`` isn't specified, this view will use the template
|
||||
|
@ -563,6 +578,9 @@ A page representing an individual object.
|
|||
* ``template_object_name``: Designates the name of the template variable
|
||||
to use in the template context. By default, this is ``'object'``.
|
||||
|
||||
* ``mimetype``: The MIME type to use for the resulting document. Defaults
|
||||
to the value of the ``DEFAULT_MIME_TYPE`` setting.
|
||||
|
||||
**Template name:**
|
||||
|
||||
If ``template_name`` isn't specified, this view will use the template
|
||||
|
@ -627,6 +645,9 @@ A page representing a list of objects.
|
|||
view will append ``'_list'`` to the value of this parameter in
|
||||
determining the variable's name.
|
||||
|
||||
* ``mimetype``: The MIME type to use for the resulting document. Defaults
|
||||
to the value of the ``DEFAULT_MIME_TYPE`` setting.
|
||||
|
||||
**Template name:**
|
||||
|
||||
If ``template_name`` isn't specified, this view will use the template
|
||||
|
@ -717,6 +738,9 @@ A page representing an individual object.
|
|||
* ``template_object_name``: Designates the name of the template variable
|
||||
to use in the template context. By default, this is ``'object'``.
|
||||
|
||||
* ``mimetype``: The MIME type to use for the resulting document. Defaults
|
||||
to the value of the ``DEFAULT_MIME_TYPE`` setting.
|
||||
|
||||
**Template name:**
|
||||
|
||||
If ``template_name`` isn't specified, this view will use the template
|
||||
|
|
Loading…
Reference in New Issue