Opened 18 years ago

Closed 18 years ago

Last modified 17 years ago

#667 closed enhancement (fixed)

[patch] extra_lookup_kwargs and extra_context in infodicts should accept callbacks

Reported by: hugo Owned by: Jacob
Component: Generic views Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

the callback should be called with the request and the dict of the parsed urlpattern to allow dynamic creation of extra_lookup_kwargs based on url parts or request.GET stuff (for example to throw in some filtering).

Attachments (2)

extra_lookup_kwargs_callback_r1217.patch (5.1 KB ) - added by Tom Tobin <korpios@…> 18 years ago.
Patch against r1217 to implement optional callback for extra_lookup_kwargs
generic_extra_callbacks_r1263.patch (8.0 KB ) - added by Tom Tobin <korpios@…> 18 years ago.
Patch against r1263 to implement ticket request (covers both extra_context and extra_lookup_kwargs)

Download all attachments as: .zip

Change History (9)

comment:1 by hugo, 18 years ago

#779 is a duplicate

by Tom Tobin <korpios@…>, 18 years ago

Patch against r1217 to implement optional callback for extra_lookup_kwargs

comment:2 by Tom Tobin <korpios@…>, 18 years ago

As per discussion in #779, I have attached a patch to implement half of the requested behavior in this ticket (the extra_lookup_kwargs callbacks). If this looks good, I'll try to implement the other half for extra_context callbacks.

comment:3 by hugo, 18 years ago

Summary: extra_lookup_kwargs and extra_context in infodicts should accept callbacks[patch] extra_lookup_kwargs and extra_context in infodicts should accept callbacks

comment:4 by Tom Tobin <korpios@…>, 18 years ago

I should note that, in the patch, object_list in list_detail has the only callback called with just one argument (request), rather than two, as there are no significant URL parts there.

by Tom Tobin <korpios@…>, 18 years ago

Patch against r1263 to implement ticket request (covers both extra_context and extra_lookup_kwargs)

comment:5 by Tom Tobin <korpios@…>, 18 years ago

I've attached a patch against r1263 (trunk) to implement all of the requested behavior in this ticket. All related callback functions must accept two positional arguments: request and lookup_kwargs (which will be an empty dictionary in extra_lookup_kwargs of list_detail.object_list and the extra_context of create_update.create_object).

I've been debating whether to have those two callback functions only take request, but opted for the behavior in the patch as to allow for a single defined callback function to handle both cases (with and without a corresponding lookup_kwargs to pass in).

comment:6 by Luke Plant, 18 years ago

You can now use the 'context_processors' argument to generic views to have dynamic 'extra_context'. As for lookup_kwargs, you can easily write a wrapper function that filters the QuerySet as required then passes it on to the generic view function, and I think this approach, which is so easy, is better than trying to cram everything to the generic views and further complicating their interface.

I think this bug and #779 can be closed now.

comment:7 by Adrian Holovaty, 18 years ago

Resolution: fixed
Status: newclosed

Closing for the reason outlined by lukeplant in the previous comment.

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