Opened 10 years ago

Closed 9 years ago

Last modified 9 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: UI/UX:

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@…> 10 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@…> 10 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 Changed 10 years ago by hugo

#779 is a duplicate

Changed 10 years ago by Tom Tobin <korpios@…>

Patch against r1217 to implement optional callback for extra_lookup_kwargs

comment:2 Changed 10 years ago by Tom Tobin <korpios@…>

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 Changed 10 years ago by hugo

  • Summary changed from extra_lookup_kwargs and extra_context in infodicts should accept callbacks to [patch] extra_lookup_kwargs and extra_context in infodicts should accept callbacks

comment:4 Changed 10 years ago by Tom Tobin <korpios@…>

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.

Changed 10 years ago by Tom Tobin <korpios@…>

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

comment:5 Changed 10 years ago by Tom Tobin <korpios@…>

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 Changed 9 years ago by lukeplant

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 Changed 9 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

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

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