#14532: django.views.generic.list_detail.object_list behavior with callables in
extra_context
---------------------------+------------------------------------------------
Reporter: jpileborg | Owner: nobody
Status: new | Milestone:
Component: Uncategorized | Version: 1.2
Keywords: | Stage: Unreviewed
Has_patch: 0 |
---------------------------+------------------------------------------------
When using django.views.generic.list_detail.object_list, if it is called
with an extra_context parameter that contains an entry with a callable,
that callable will be called when copying the extra context to the actual
context. This behavior is not always wanted.
In my application, the extra_context contains an object instance in which
the class have a custom __call__ method. Since my __call__ method have
some required parameters, I will get an error when trying to display the
page using the view.
The callable should only be called if it is a function. If the user of
object_list wants a callable object in the extra_context, then the user
should call the object instance when adding the object to the context
dictionary.
I changed the code in django/views/generic/list_detail.py on line 93 to 96
to:
{{{
import types
if isinstance(value, types.FunctionType):
c[key] = value()
else:
c[key] = value
}}}
--
Ticket URL: <http://code.djangoproject.com/ticket/14532>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.