#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)
Change History (9)
comment:1 by , 19 years ago
by , 19 years ago
Attachment: | extra_lookup_kwargs_callback_r1217.patch added |
---|
Patch against r1217 to implement optional callback for extra_lookup_kwargs
comment:2 by , 19 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 , 19 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 , 19 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 , 19 years ago
Attachment: | generic_extra_callbacks_r1263.patch added |
---|
Patch against r1263 to implement ticket request (covers both extra_context and extra_lookup_kwargs)
comment:5 by , 19 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 , 19 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 , 19 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Closing for the reason outlined by lukeplant in the previous comment.
#779 is a duplicate