mirror of
https://github.com/django/django.git
synced 2025-07-05 10:19:20 +00:00
magic-removal: Fixed #1643 -- Updated generic views for template extension change
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2701 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
6442fd27bc
commit
d40781952b
@ -14,7 +14,7 @@ def create_object(request, model, template_name=None,
|
|||||||
"""
|
"""
|
||||||
Generic object-creation function.
|
Generic object-creation function.
|
||||||
|
|
||||||
Templates: ``<app_label>/<model_name>_form``
|
Templates: ``<app_label>/<model_name>_form.html``
|
||||||
Context:
|
Context:
|
||||||
form
|
form
|
||||||
the form wrapper for the object
|
the form wrapper for the object
|
||||||
@ -57,7 +57,7 @@ def create_object(request, model, template_name=None,
|
|||||||
# Create the FormWrapper, template, context, response
|
# Create the FormWrapper, template, context, response
|
||||||
form = forms.FormWrapper(manipulator, new_data, errors)
|
form = forms.FormWrapper(manipulator, new_data, errors)
|
||||||
if not template_name:
|
if not template_name:
|
||||||
template_name = "%s/%s_form" % (model._meta.app_label, model._meta.object_name.lower())
|
template_name = "%s/%s_form.html" % (model._meta.app_label, model._meta.object_name.lower())
|
||||||
t = template_loader.get_template(template_name)
|
t = template_loader.get_template(template_name)
|
||||||
c = RequestContext(request, {
|
c = RequestContext(request, {
|
||||||
'form': form,
|
'form': form,
|
||||||
@ -77,7 +77,7 @@ def update_object(request, model, object_id=None, slug=None,
|
|||||||
"""
|
"""
|
||||||
Generic object-update function.
|
Generic object-update function.
|
||||||
|
|
||||||
Templates: ``<app_label>/<model_name>_form``
|
Templates: ``<app_label>/<model_name>_form.html``
|
||||||
Context:
|
Context:
|
||||||
form
|
form
|
||||||
the form wrapper for the object
|
the form wrapper for the object
|
||||||
@ -127,7 +127,7 @@ def update_object(request, model, object_id=None, slug=None,
|
|||||||
|
|
||||||
form = forms.FormWrapper(manipulator, new_data, errors)
|
form = forms.FormWrapper(manipulator, new_data, errors)
|
||||||
if not template_name:
|
if not template_name:
|
||||||
template_name = "%s/%s_form" % (model._meta.app_label, model._meta.object_name.lower())
|
template_name = "%s/%s_form.html" % (model._meta.app_label, model._meta.object_name.lower())
|
||||||
t = template_loader.get_template(template_name)
|
t = template_loader.get_template(template_name)
|
||||||
c = RequestContext(request, {
|
c = RequestContext(request, {
|
||||||
'form': form,
|
'form': form,
|
||||||
@ -153,7 +153,7 @@ def delete_object(request, model, post_delete_redirect,
|
|||||||
fetched using GET; for safty, deletion will only be performed if this
|
fetched using GET; for safty, deletion will only be performed if this
|
||||||
view is POSTed.
|
view is POSTed.
|
||||||
|
|
||||||
Templates: ``<app_label>/<model_name>_confirm_delete``
|
Templates: ``<app_label>/<model_name>_confirm_delete.html``
|
||||||
Context:
|
Context:
|
||||||
object
|
object
|
||||||
the original object being deleted
|
the original object being deleted
|
||||||
@ -182,7 +182,7 @@ def delete_object(request, model, post_delete_redirect,
|
|||||||
return HttpResponseRedirect(post_delete_redirect)
|
return HttpResponseRedirect(post_delete_redirect)
|
||||||
else:
|
else:
|
||||||
if not template_name:
|
if not template_name:
|
||||||
template_name = "%s/%s_confirm_delete" % (model._meta.app_label, model._meta.object_name.lower())
|
template_name = "%s/%s_confirm_delete.html" % (model._meta.app_label, model._meta.object_name.lower())
|
||||||
t = template_loader.get_template(template_name)
|
t = template_loader.get_template(template_name)
|
||||||
c = RequestContext(request, {
|
c = RequestContext(request, {
|
||||||
template_object_name: object,
|
template_object_name: object,
|
||||||
|
@ -10,7 +10,7 @@ def archive_index(request, queryset, date_field, num_latest=15,
|
|||||||
"""
|
"""
|
||||||
Generic top-level archive of date-based objects.
|
Generic top-level archive of date-based objects.
|
||||||
|
|
||||||
Templates: ``<app_label>/<model_name>_archive``
|
Templates: ``<app_label>/<model_name>_archive.html``
|
||||||
Context:
|
Context:
|
||||||
date_list
|
date_list
|
||||||
List of years
|
List of years
|
||||||
@ -29,7 +29,7 @@ def archive_index(request, queryset, date_field, num_latest=15,
|
|||||||
latest = None
|
latest = None
|
||||||
|
|
||||||
if not template_name:
|
if not template_name:
|
||||||
template_name = "%s/%s_archive" % (model._meta.app_label, model._meta.object_name.lower())
|
template_name = "%s/%s_archive.html" % (model._meta.app_label, model._meta.object_name.lower())
|
||||||
t = template_loader.get_template(template_name)
|
t = template_loader.get_template(template_name)
|
||||||
c = RequestContext(request, {
|
c = RequestContext(request, {
|
||||||
'date_list' : date_list,
|
'date_list' : date_list,
|
||||||
@ -48,7 +48,7 @@ def archive_year(request, year, queryset, date_field, template_name=None,
|
|||||||
"""
|
"""
|
||||||
Generic yearly archive view.
|
Generic yearly archive view.
|
||||||
|
|
||||||
Templates: ``<app_label>/<model_name>_archive_year``
|
Templates: ``<app_label>/<model_name>_archive_year.html``
|
||||||
Context:
|
Context:
|
||||||
date_list
|
date_list
|
||||||
List of months in this year with objects
|
List of months in this year with objects
|
||||||
@ -65,7 +65,7 @@ def archive_year(request, year, queryset, date_field, template_name=None,
|
|||||||
if not date_list and not allow_empty:
|
if not date_list and not allow_empty:
|
||||||
raise Http404
|
raise Http404
|
||||||
if not template_name:
|
if not template_name:
|
||||||
template_name = "%s/%s_archive_year" % (model._meta.app_label, model._meta.object_name.lower())
|
template_name = "%s/%s_archive_year.html" % (model._meta.app_label, model._meta.object_name.lower())
|
||||||
t = template_loader.get_template(template_name)
|
t = template_loader.get_template(template_name)
|
||||||
c = RequestContext(request, {
|
c = RequestContext(request, {
|
||||||
'date_list': date_list,
|
'date_list': date_list,
|
||||||
@ -85,7 +85,7 @@ def archive_month(request, year, month, queryset, date_field,
|
|||||||
"""
|
"""
|
||||||
Generic monthly archive view.
|
Generic monthly archive view.
|
||||||
|
|
||||||
Templates: ``<app_label>/<model_name>_archive_month``
|
Templates: ``<app_label>/<model_name>_archive_month.html``
|
||||||
Context:
|
Context:
|
||||||
month:
|
month:
|
||||||
(date) this month
|
(date) this month
|
||||||
@ -117,7 +117,7 @@ def archive_month(request, year, month, queryset, date_field,
|
|||||||
if not object_list and not allow_empty:
|
if not object_list and not allow_empty:
|
||||||
raise Http404
|
raise Http404
|
||||||
if not template_name:
|
if not template_name:
|
||||||
template_name = "%s/%s_archive_month" % (model._meta.app_label, model._meta.object_name.lower())
|
template_name = "%s/%s_archive_month.html" % (model._meta.app_label, model._meta.object_name.lower())
|
||||||
t = template_loader.get_template(template_name)
|
t = template_loader.get_template(template_name)
|
||||||
c = RequestContext(request, {
|
c = RequestContext(request, {
|
||||||
'%s_list' % template_object_name: object_list,
|
'%s_list' % template_object_name: object_list,
|
||||||
@ -139,7 +139,7 @@ def archive_day(request, year, month, day, queryset, date_field,
|
|||||||
"""
|
"""
|
||||||
Generic daily archive view.
|
Generic daily archive view.
|
||||||
|
|
||||||
Templates: ``<app_label>/<model_name>_archive_day``
|
Templates: ``<app_label>/<model_name>_archive_day.html``
|
||||||
Context:
|
Context:
|
||||||
object_list:
|
object_list:
|
||||||
list of objects published that day
|
list of objects published that day
|
||||||
@ -167,7 +167,7 @@ def archive_day(request, year, month, day, queryset, date_field,
|
|||||||
if not allow_empty and not object_list:
|
if not allow_empty and not object_list:
|
||||||
raise Http404
|
raise Http404
|
||||||
if not template_name:
|
if not template_name:
|
||||||
template_name = "%s/%s_archive_day" % (model._meta.app_label, model._meta.object_name.lower())
|
template_name = "%s/%s_archive_day.html" % (model._meta.app_label, model._meta.object_name.lower())
|
||||||
t = template_loader.get_template(template_name)
|
t = template_loader.get_template(template_name)
|
||||||
c = RequestContext(request, {
|
c = RequestContext(request, {
|
||||||
'%s_list' % template_object_name: object_list,
|
'%s_list' % template_object_name: object_list,
|
||||||
@ -202,7 +202,7 @@ def object_detail(request, year, month, day, queryset, date_field,
|
|||||||
"""
|
"""
|
||||||
Generic detail view from year/month/day/slug or year/month/day/id structure.
|
Generic detail view from year/month/day/slug or year/month/day/id structure.
|
||||||
|
|
||||||
Templates: ``<app_label>/<model_name>_detail``
|
Templates: ``<app_label>/<model_name>_detail.html``
|
||||||
Context:
|
Context:
|
||||||
object:
|
object:
|
||||||
the object to be detailed
|
the object to be detailed
|
||||||
@ -231,7 +231,7 @@ def object_detail(request, year, month, day, queryset, date_field,
|
|||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
raise Http404, "No %s found for" % model._meta.verbose_name
|
raise Http404, "No %s found for" % model._meta.verbose_name
|
||||||
if not template_name:
|
if not template_name:
|
||||||
template_name = "%s/%s_detail" % (model._meta.app_label, model._meta.object_name.lower())
|
template_name = "%s/%s_detail.html" % (model._meta.app_label, model._meta.object_name.lower())
|
||||||
if template_name_field:
|
if template_name_field:
|
||||||
template_name_list = [getattr(obj, template_name_field), template_name]
|
template_name_list = [getattr(obj, template_name_field), template_name]
|
||||||
t = template_loader.select_template(template_name_list)
|
t = template_loader.select_template(template_name_list)
|
||||||
|
@ -10,7 +10,7 @@ def object_list(request, queryset, paginate_by=None, allow_empty=False,
|
|||||||
"""
|
"""
|
||||||
Generic list of objects.
|
Generic list of objects.
|
||||||
|
|
||||||
Templates: ``<app_label>/<model_name>_list``
|
Templates: ``<app_label>/<model_name>_list.html``
|
||||||
Context:
|
Context:
|
||||||
object_list
|
object_list
|
||||||
list of objects
|
list of objects
|
||||||
@ -71,7 +71,7 @@ def object_list(request, queryset, paginate_by=None, allow_empty=False,
|
|||||||
else:
|
else:
|
||||||
c[key] = value
|
c[key] = value
|
||||||
if not template_name:
|
if not template_name:
|
||||||
template_name = "%s/%s_list" % (model._meta.app_label, model._meta.object_name.lower())
|
template_name = "%s/%s_list.html" % (model._meta.app_label, model._meta.object_name.lower())
|
||||||
t = template_loader.get_template(template_name)
|
t = template_loader.get_template(template_name)
|
||||||
return HttpResponse(t.render(c))
|
return HttpResponse(t.render(c))
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ def object_detail(request, queryset, object_id=None, slug=None,
|
|||||||
"""
|
"""
|
||||||
Generic list of objects.
|
Generic list of objects.
|
||||||
|
|
||||||
Templates: ``<app_label>/<model_name>_detail``
|
Templates: ``<app_label>/<model_name>_detail.html``
|
||||||
Context:
|
Context:
|
||||||
object
|
object
|
||||||
the object
|
the object
|
||||||
@ -99,7 +99,7 @@ def object_detail(request, queryset, object_id=None, slug=None,
|
|||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
raise Http404, "No %s found matching the query" % (model._meta.verbose_name)
|
raise Http404, "No %s found matching the query" % (model._meta.verbose_name)
|
||||||
if not template_name:
|
if not template_name:
|
||||||
template_name = "%s/%s_detail" % (model._meta.app_label, model._meta.object_name.lower())
|
template_name = "%s/%s_detail.html" % (model._meta.app_label, model._meta.object_name.lower())
|
||||||
if template_name_field:
|
if template_name_field:
|
||||||
template_name_list = [getattr(obj, template_name_field), template_name]
|
template_name_list = [getattr(obj, template_name_field), template_name]
|
||||||
t = template_loader.select_template(template_name_list)
|
t = template_loader.select_template(template_name_list)
|
||||||
|
@ -146,7 +146,7 @@ The date-based generic functions are:
|
|||||||
an empty index page. ``False`` is default.
|
an empty index page. ``False`` is default.
|
||||||
======================= =================================================
|
======================= =================================================
|
||||||
|
|
||||||
Uses the template ``<app_label>/<model_name>_archive`` by default, where:
|
Uses the template ``<app_label>/<model_name>_archive.html`` by default, where:
|
||||||
|
|
||||||
* ``<model_name>`` is your model's name in all lowercase. For a model
|
* ``<model_name>`` is your model's name in all lowercase. For a model
|
||||||
``StaffMember``, that'd be ``staffmember``.
|
``StaffMember``, that'd be ``staffmember``.
|
||||||
@ -168,7 +168,7 @@ The date-based generic functions are:
|
|||||||
|
|
||||||
Takes an optional ``allow_empty`` parameter, as ``archive_index``.
|
Takes an optional ``allow_empty`` parameter, as ``archive_index``.
|
||||||
|
|
||||||
Uses the template ``<app_label>/<model_name>_archive_year`` by default.
|
Uses the template ``<app_label>/<model_name>_archive_year.html`` by default.
|
||||||
|
|
||||||
Has the following template context:
|
Has the following template context:
|
||||||
|
|
||||||
@ -193,7 +193,7 @@ The date-based generic functions are:
|
|||||||
``template_object_name`` parameter, which designates the name of the
|
``template_object_name`` parameter, which designates the name of the
|
||||||
template variable to use. Default is ``'object'``.
|
template variable to use. Default is ``'object'``.
|
||||||
|
|
||||||
Uses the template ``<app_label>/<model_name>_archive_month`` by default.
|
Uses the template ``<app_label>/<model_name>_archive_month.html`` by default.
|
||||||
|
|
||||||
Has the following template context:
|
Has the following template context:
|
||||||
|
|
||||||
@ -225,7 +225,7 @@ The date-based generic functions are:
|
|||||||
``template_object_name`` parameter, which designates the name of the
|
``template_object_name`` parameter, which designates the name of the
|
||||||
template variable to use. Default is ``'object'``.
|
template variable to use. Default is ``'object'``.
|
||||||
|
|
||||||
Uses the template ``<app_label>/<model_name>_archive_day`` by default.
|
Uses the template ``<app_label>/<model_name>_archive_day.html`` by default.
|
||||||
|
|
||||||
Has the following template context:
|
Has the following template context:
|
||||||
|
|
||||||
@ -307,7 +307,7 @@ Individual views are:
|
|||||||
is ``'object'``.
|
is ``'object'``.
|
||||||
======================== =================================================
|
======================== =================================================
|
||||||
|
|
||||||
Uses the template ``<app_label>/<module_name_list>`` by default.
|
Uses the template ``<app_label>/<module_name_list>.html`` by default.
|
||||||
|
|
||||||
Has the following template context:
|
Has the following template context:
|
||||||
|
|
||||||
@ -364,9 +364,9 @@ The create/update/delete views are:
|
|||||||
be interpolated against the object's field attributes. For example, you
|
be interpolated against the object's field attributes. For example, you
|
||||||
could use ``post_save_redirect="/polls/%(slug)s/"``.
|
could use ``post_save_redirect="/polls/%(slug)s/"``.
|
||||||
|
|
||||||
Uses the template ``<app_label>/<model_name>_form`` by default. This is the
|
Uses the template ``<app_label>/<model_name>_form.html`` by default. This
|
||||||
same template as the ``update_object`` view below. Your template can tell
|
is the same template as the ``update_object`` view below. Your template can
|
||||||
the difference by the presence or absence of ``{{ object }}`` in the
|
tell the difference by the presence or absence of ``{{ object }}`` in the
|
||||||
context.
|
context.
|
||||||
|
|
||||||
Has the following template context:
|
Has the following template context:
|
||||||
@ -390,7 +390,7 @@ The create/update/delete views are:
|
|||||||
``template_object_name`` parameter, which designates the name of the
|
``template_object_name`` parameter, which designates the name of the
|
||||||
template variable to use. Default is ``'object'``.
|
template variable to use. Default is ``'object'``.
|
||||||
|
|
||||||
Uses the template ``<app_label>/<model_name>_form`` by default.
|
Uses the template ``<app_label>/<model_name>_form.html`` by default.
|
||||||
|
|
||||||
Has the following template context:
|
Has the following template context:
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user