magic-removal: Merged to [2454]
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2455 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
b2dd439085
commit
7901c93328
1
AUTHORS
1
AUTHORS
|
@ -45,6 +45,7 @@ answer newbie questions, and generally made Django that much better:
|
||||||
Antonio Cavedoni <http://cavedoni.com/>
|
Antonio Cavedoni <http://cavedoni.com/>
|
||||||
C8E
|
C8E
|
||||||
Amit Chakradeo <http://amit.chakradeo.net/>
|
Amit Chakradeo <http://amit.chakradeo.net/>
|
||||||
|
ChaosKCW
|
||||||
Matt Croydon <http://www.postneo.com/>
|
Matt Croydon <http://www.postneo.com/>
|
||||||
Jonathan Daugherty (cygnus) <http://www.cprogrammer.org/>
|
Jonathan Daugherty (cygnus) <http://www.cprogrammer.org/>
|
||||||
Jason Davies (Esaj) <http://www.jasondavies.com/>
|
Jason Davies (Esaj) <http://www.jasondavies.com/>
|
||||||
|
|
|
@ -9,8 +9,8 @@ from django.utils.text import capfirst
|
||||||
from django.utils.translation import gettext_lazy, ngettext
|
from django.utils.translation import gettext_lazy, ngettext
|
||||||
import datetime, os
|
import datetime, os
|
||||||
|
|
||||||
# Random entropy string used by "default" param.
|
class NOT_PROVIDED:
|
||||||
NOT_PROVIDED = 'oijpwojefiojpanv'
|
pass
|
||||||
|
|
||||||
# Values for filter_interface.
|
# Values for filter_interface.
|
||||||
HORIZONTAL, VERTICAL = 1, 2
|
HORIZONTAL, VERTICAL = 1, 2
|
||||||
|
@ -158,11 +158,11 @@ class Field(object):
|
||||||
|
|
||||||
def has_default(self):
|
def has_default(self):
|
||||||
"Returns a boolean of whether this field has a default value."
|
"Returns a boolean of whether this field has a default value."
|
||||||
return self.default != NOT_PROVIDED
|
return self.default is not NOT_PROVIDED
|
||||||
|
|
||||||
def get_default(self):
|
def get_default(self):
|
||||||
"Returns the default value for this field."
|
"Returns the default value for this field."
|
||||||
if self.default != NOT_PROVIDED:
|
if self.default is not NOT_PROVIDED:
|
||||||
if callable(self.default):
|
if callable(self.default):
|
||||||
return self.default()
|
return self.default()
|
||||||
return self.default
|
return self.default
|
||||||
|
|
|
@ -72,7 +72,8 @@ def create_object(request, model, template_name=None,
|
||||||
def update_object(request, model, object_id=None, slug=None,
|
def update_object(request, model, object_id=None, slug=None,
|
||||||
slug_field=None, template_name=None, template_loader=loader,
|
slug_field=None, template_name=None, template_loader=loader,
|
||||||
extra_lookup_kwargs={}, extra_context={}, post_save_redirect=None,
|
extra_lookup_kwargs={}, extra_context={}, post_save_redirect=None,
|
||||||
login_required=False, follow=None, context_processors=None):
|
login_required=False, follow=None, context_processors=None,
|
||||||
|
template_object_name='object'):
|
||||||
"""
|
"""
|
||||||
Generic object-update function.
|
Generic object-update function.
|
||||||
|
|
||||||
|
@ -130,7 +131,7 @@ def update_object(request, model, object_id=None, slug=None,
|
||||||
t = template_loader.get_template(template_name)
|
t = template_loader.get_template(template_name)
|
||||||
c = RequestContext(request, {
|
c = RequestContext(request, {
|
||||||
'form': form,
|
'form': form,
|
||||||
'object': object,
|
template_object_name: object,
|
||||||
}, context_processors)
|
}, context_processors)
|
||||||
for key, value in extra_context.items():
|
for key, value in extra_context.items():
|
||||||
if callable(value):
|
if callable(value):
|
||||||
|
@ -144,7 +145,7 @@ def update_object(request, model, object_id=None, slug=None,
|
||||||
def delete_object(request, model, post_delete_redirect,
|
def delete_object(request, model, post_delete_redirect,
|
||||||
object_id=None, slug=None, slug_field=None, template_name=None,
|
object_id=None, slug=None, slug_field=None, template_name=None,
|
||||||
template_loader=loader, extra_lookup_kwargs={}, extra_context={},
|
template_loader=loader, extra_lookup_kwargs={}, extra_context={},
|
||||||
login_required=False, context_processors=None):
|
login_required=False, context_processors=None, template_object_name='object'):
|
||||||
"""
|
"""
|
||||||
Generic object-delete function.
|
Generic object-delete function.
|
||||||
|
|
||||||
|
@ -184,7 +185,7 @@ def delete_object(request, model, post_delete_redirect,
|
||||||
template_name = "%s/%s_confirm_delete" % (model._meta.app_label, model._meta.object_name.lower())
|
template_name = "%s/%s_confirm_delete" % (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, {
|
||||||
'object': object,
|
template_object_name: object,
|
||||||
}, context_processors)
|
}, context_processors)
|
||||||
for key, value in extra_context.items():
|
for key, value in extra_context.items():
|
||||||
if callable(value):
|
if callable(value):
|
||||||
|
|
|
@ -80,7 +80,8 @@ def archive_year(request, year, queryset, date_field, template_name=None,
|
||||||
|
|
||||||
def archive_month(request, year, month, queryset, date_field,
|
def archive_month(request, year, month, queryset, date_field,
|
||||||
month_format='%b', template_name=None, template_loader=loader,
|
month_format='%b', template_name=None, template_loader=loader,
|
||||||
extra_context={}, allow_empty=False, context_processors=None):
|
extra_context={}, allow_empty=False, context_processors=None,
|
||||||
|
template_object_name='object'):
|
||||||
"""
|
"""
|
||||||
Generic monthly archive view.
|
Generic monthly archive view.
|
||||||
|
|
||||||
|
@ -119,7 +120,7 @@ def archive_month(request, year, month, queryset, date_field,
|
||||||
template_name = "%s/%s_archive_month" % (model._meta.app_label, model._meta.object_name.lower())
|
template_name = "%s/%s_archive_month" % (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, {
|
||||||
'object_list': object_list,
|
'%s_list' % template_object_name: object_list,
|
||||||
'month': date,
|
'month': date,
|
||||||
'next_month': (last_day < datetime.date.today()) and (last_day + datetime.timedelta(days=1)) or None,
|
'next_month': (last_day < datetime.date.today()) and (last_day + datetime.timedelta(days=1)) or None,
|
||||||
'previous_month': first_day - datetime.timedelta(days=1),
|
'previous_month': first_day - datetime.timedelta(days=1),
|
||||||
|
@ -134,7 +135,7 @@ def archive_month(request, year, month, queryset, date_field,
|
||||||
def archive_day(request, year, month, day, queryset, date_field,
|
def archive_day(request, year, month, day, queryset, date_field,
|
||||||
month_format='%b', day_format='%d', template_name=None,
|
month_format='%b', day_format='%d', template_name=None,
|
||||||
template_loader=loader, extra_context={}, allow_empty=False,
|
template_loader=loader, extra_context={}, allow_empty=False,
|
||||||
context_processors=None):
|
context_processors=None, template_object_name='object'):
|
||||||
"""
|
"""
|
||||||
Generic daily archive view.
|
Generic daily archive view.
|
||||||
|
|
||||||
|
@ -169,7 +170,7 @@ def archive_day(request, year, month, day, queryset, date_field,
|
||||||
template_name = "%s/%s_archive_day" % (model._meta.app_label, model._meta.object_name.lower())
|
template_name = "%s/%s_archive_day" % (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, {
|
||||||
'object_list': object_list,
|
'%s_list' % template_object_name: object_list,
|
||||||
'day': date,
|
'day': date,
|
||||||
'previous_day': date - datetime.timedelta(days=1),
|
'previous_day': date - datetime.timedelta(days=1),
|
||||||
'next_day': (date < datetime.date.today()) and (date + datetime.timedelta(days=1)) or None,
|
'next_day': (date < datetime.date.today()) and (date + datetime.timedelta(days=1)) or None,
|
||||||
|
@ -196,7 +197,8 @@ def archive_today(request, **kwargs):
|
||||||
def object_detail(request, year, month, day, queryset, date_field,
|
def object_detail(request, year, month, day, queryset, date_field,
|
||||||
month_format='%b', day_format='%d', object_id=None, slug=None,
|
month_format='%b', day_format='%d', object_id=None, slug=None,
|
||||||
slug_field=None, template_name=None, template_name_field=None,
|
slug_field=None, template_name=None, template_name_field=None,
|
||||||
template_loader=loader, extra_context={}, context_processors=None):
|
template_loader=loader, extra_context={}, context_processors=None,
|
||||||
|
template_object_name='object'):
|
||||||
"""
|
"""
|
||||||
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.
|
||||||
|
|
||||||
|
@ -236,7 +238,7 @@ def object_detail(request, year, month, day, queryset, date_field,
|
||||||
else:
|
else:
|
||||||
t = template_loader.get_template(template_name)
|
t = template_loader.get_template(template_name)
|
||||||
c = RequestContext(request, {
|
c = RequestContext(request, {
|
||||||
'object': obj,
|
template_object_name: obj,
|
||||||
}, context_processors)
|
}, context_processors)
|
||||||
for key, value in extra_context.items():
|
for key, value in extra_context.items():
|
||||||
if callable(value):
|
if callable(value):
|
||||||
|
|
|
@ -6,7 +6,7 @@ from django.core.exceptions import ObjectDoesNotExist
|
||||||
|
|
||||||
def object_list(request, queryset, paginate_by=None, allow_empty=False,
|
def object_list(request, queryset, paginate_by=None, allow_empty=False,
|
||||||
template_name=None, template_loader=loader,
|
template_name=None, template_loader=loader,
|
||||||
extra_context={}, context_processors=None):
|
extra_context={}, context_processors=None, template_object_name='object'):
|
||||||
"""
|
"""
|
||||||
Generic list of objects.
|
Generic list of objects.
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ def object_list(request, queryset, paginate_by=None, allow_empty=False,
|
||||||
else:
|
else:
|
||||||
raise Http404
|
raise Http404
|
||||||
c = RequestContext(request, {
|
c = RequestContext(request, {
|
||||||
'object_list': object_list,
|
'%s_list' % template_object_name: object_list,
|
||||||
'is_paginated': paginator.pages > 1,
|
'is_paginated': paginator.pages > 1,
|
||||||
'results_per_page': paginate_by,
|
'results_per_page': paginate_by,
|
||||||
'has_next': paginator.has_next_page(page - 1),
|
'has_next': paginator.has_next_page(page - 1),
|
||||||
|
@ -60,7 +60,7 @@ def object_list(request, queryset, paginate_by=None, allow_empty=False,
|
||||||
}, context_processors)
|
}, context_processors)
|
||||||
else:
|
else:
|
||||||
c = RequestContext(request, {
|
c = RequestContext(request, {
|
||||||
'object_list': queryset,
|
'%s_list' % template_object_name: queryset,
|
||||||
'is_paginated': False
|
'is_paginated': False
|
||||||
}, context_processors)
|
}, context_processors)
|
||||||
if not allow_empty and len(queryset) == 0:
|
if not allow_empty and len(queryset) == 0:
|
||||||
|
@ -78,7 +78,7 @@ def object_list(request, queryset, paginate_by=None, allow_empty=False,
|
||||||
def object_detail(request, queryset, object_id=None, slug=None,
|
def object_detail(request, queryset, object_id=None, slug=None,
|
||||||
slug_field=None, template_name=None, template_name_field=None,
|
slug_field=None, template_name=None, template_name_field=None,
|
||||||
template_loader=loader, extra_context={},
|
template_loader=loader, extra_context={},
|
||||||
context_processors=None):
|
context_processors=None, template_object_name='object'):
|
||||||
"""
|
"""
|
||||||
Generic list of objects.
|
Generic list of objects.
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ def object_detail(request, queryset, object_id=None, slug=None,
|
||||||
else:
|
else:
|
||||||
t = template_loader.get_template(template_name)
|
t = template_loader.get_template(template_name)
|
||||||
c = RequestContext(request, {
|
c = RequestContext(request, {
|
||||||
'object': obj,
|
template_object_name: obj,
|
||||||
}, context_processors)
|
}, context_processors)
|
||||||
for key, value in extra_context.items():
|
for key, value in extra_context.items():
|
||||||
if callable(value):
|
if callable(value):
|
||||||
|
|
|
@ -189,6 +189,10 @@ The date-based generic functions are:
|
||||||
|
|
||||||
Takes an optional ``allow_empty`` parameter, as ``archive_index``.
|
Takes an optional ``allow_empty`` parameter, as ``archive_index``.
|
||||||
|
|
||||||
|
**New in Django development version:** Takes an optional
|
||||||
|
``template_object_name`` parameter, which designates the name of the
|
||||||
|
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`` by default.
|
||||||
|
|
||||||
Has the following template context:
|
Has the following template context:
|
||||||
|
@ -203,7 +207,11 @@ The date-based generic functions are:
|
||||||
**New in Django development version.** The first day of the
|
**New in Django development version.** The first day of the
|
||||||
previous month (a datetime.date object)
|
previous month (a datetime.date object)
|
||||||
``object_list``
|
``object_list``
|
||||||
List of objects published in the given month
|
List of objects published in the given month.
|
||||||
|
In the Django development version, you can change this variable
|
||||||
|
name from ``object_list`` by using the ``template_object_name``
|
||||||
|
parameter. (See above.) For example, if ``template_object_name`` is
|
||||||
|
``foo``, the variable will be ``foo_list``.
|
||||||
|
|
||||||
``archive_day``
|
``archive_day``
|
||||||
Daily archive. Requires that ``year``, ``month``, and ``day`` arguments be
|
Daily archive. Requires that ``year``, ``month``, and ``day`` arguments be
|
||||||
|
@ -213,12 +221,20 @@ The date-based generic functions are:
|
||||||
also pass ``day_format``, which defaults to ``"%d"`` (day of the month as a
|
also pass ``day_format``, which defaults to ``"%d"`` (day of the month as a
|
||||||
decimal number, 1-31).
|
decimal number, 1-31).
|
||||||
|
|
||||||
|
**New in Django development version:** Takes an optional
|
||||||
|
``template_object_name`` parameter, which designates the name of the
|
||||||
|
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`` by default.
|
||||||
|
|
||||||
Has the following template context:
|
Has the following template context:
|
||||||
|
|
||||||
``object_list``
|
``object_list``
|
||||||
List of objects published this day
|
List of objects published on the given day.
|
||||||
|
In the Django development version, you can change this variable
|
||||||
|
name from ``object_list`` by using the ``template_object_name``
|
||||||
|
parameter. (See above.) For example, if ``template_object_name`` is
|
||||||
|
``foo``, the variable will be ``foo_list``.
|
||||||
``day``
|
``day``
|
||||||
The given day (a datetime.datetime object)
|
The given day (a datetime.datetime object)
|
||||||
``previous_day``
|
``previous_day``
|
||||||
|
@ -250,6 +266,10 @@ The date-based generic functions are:
|
||||||
As in ``archive_day``, ``object_detail`` takes optional ``month_format``
|
As in ``archive_day``, ``object_detail`` takes optional ``month_format``
|
||||||
and ``day_format`` parameters.
|
and ``day_format`` parameters.
|
||||||
|
|
||||||
|
**New in Django development version:** Takes an optional
|
||||||
|
``template_object_name`` parameter, which designates the name of the
|
||||||
|
template variable to use. Default is ``'object'``.
|
||||||
|
|
||||||
.. _strftime docs: http://www.python.org/doc/current/lib/module-time.html#l2h-1941
|
.. _strftime docs: http://www.python.org/doc/current/lib/module-time.html#l2h-1941
|
||||||
|
|
||||||
Using list/detail generic views
|
Using list/detail generic views
|
||||||
|
@ -281,6 +301,9 @@ Individual views are:
|
||||||
``allow_empty`` If ``False`` and there are no objects to display,
|
``allow_empty`` If ``False`` and there are no objects to display,
|
||||||
the view will raise a 404 instead of displaying
|
the view will raise a 404 instead of displaying
|
||||||
an empty index page. ``False`` is default.
|
an empty index page. ``False`` is default.
|
||||||
|
``template_object_name`` **New in Django development version.** Designates
|
||||||
|
the name of the object template variable. Default
|
||||||
|
is ``'object'``.
|
||||||
======================= =================================================
|
======================= =================================================
|
||||||
|
|
||||||
Uses the template ``<app_label>/<model_name>_list`` by default.
|
Uses the template ``<app_label>/<model_name>_list`` by default.
|
||||||
|
@ -288,7 +311,11 @@ Individual views are:
|
||||||
Has the following template context:
|
Has the following template context:
|
||||||
|
|
||||||
``object_list``
|
``object_list``
|
||||||
List of objects
|
List of objects. In the Django development version, you can change
|
||||||
|
this variable name from ``object_list`` by using the
|
||||||
|
``template_object_name`` parameter. (See above.) For example, if
|
||||||
|
``template_object_name`` is ``foo``, the variable will be
|
||||||
|
``foo_list``.
|
||||||
``is_paginated``
|
``is_paginated``
|
||||||
Are the results paginated? Either True or False
|
Are the results paginated? Either True or False
|
||||||
|
|
||||||
|
@ -358,6 +385,10 @@ The create/update/delete views are:
|
||||||
``list_detail.object_detail`` does (see above), and the same
|
``list_detail.object_detail`` does (see above), and the same
|
||||||
``post_save_redirect`` as ``create_object`` does.
|
``post_save_redirect`` as ``create_object`` does.
|
||||||
|
|
||||||
|
**New in Django development version:** Takes an optional
|
||||||
|
``template_object_name`` parameter, which designates the name of the
|
||||||
|
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`` by default.
|
||||||
|
|
||||||
Has the following template context:
|
Has the following template context:
|
||||||
|
@ -365,7 +396,11 @@ The create/update/delete views are:
|
||||||
form
|
form
|
||||||
The form wrapper for the object
|
The form wrapper for the object
|
||||||
object
|
object
|
||||||
The original object being edited
|
The original object being edited.
|
||||||
|
In the Django development version, you can change this variable
|
||||||
|
name from ``object`` by using the ``template_object_name``
|
||||||
|
parameter. (See above.) For example, if ``template_object_name`` is
|
||||||
|
``foo``, the variable will be ``foo`` instead of ``object``.
|
||||||
|
|
||||||
``delete_object``
|
``delete_object``
|
||||||
Delete an existing object. The given object will only actually be deleted
|
Delete an existing object. The given object will only actually be deleted
|
||||||
|
@ -380,7 +415,15 @@ The create/update/delete views are:
|
||||||
``<app_label>/<model_name>_confirm_delete`` by default. It uses no template
|
``<app_label>/<model_name>_confirm_delete`` by default. It uses no template
|
||||||
if POSTed -- it simply deletes the object and redirects.
|
if POSTed -- it simply deletes the object and redirects.
|
||||||
|
|
||||||
|
**New in Django development version:** Takes an optional
|
||||||
|
``template_object_name`` parameter, which designates the name of the
|
||||||
|
template variable to use. Default is ``'object'``.
|
||||||
|
|
||||||
Has the following template context:
|
Has the following template context:
|
||||||
|
|
||||||
object
|
object
|
||||||
The object about to be deleted
|
The object about to be deleted
|
||||||
|
In the Django development version, you can change this variable
|
||||||
|
name from ``object`` by using the ``template_object_name``
|
||||||
|
parameter. (See above.) For example, if ``template_object_name`` is
|
||||||
|
``foo``, the variable will be ``foo`` instead of ``object``.
|
||||||
|
|
Loading…
Reference in New Issue