django.views.generic.list_detail.object_list behavior with callables in extra_context
|Reported by:||jpileborg||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
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