Opened 14 years ago

Closed 14 years ago

#14532 closed (wontfix)

django.views.generic.list_detail.object_list behavior with callables in extra_context

Reported by: jpileborg Owned by: nobody
Component: Uncategorized Version: 1.2
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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

Change History (1)

comment:1 by Russell Keith-Magee, 14 years ago

Resolution: wontfix
Status: newclosed

Function-based generic views have been deprecated in favor of class-based generic views. Complications with the interpretations of extra_context are one (of many) reasons for this.

Note: See TracTickets for help on using tickets.
Back to Top