Django

Code

Ticket #5833 (assigned)

Opened 10 months ago

Last modified 3 days ago

[newforms-admin] Custom FilterSpecs

Reported by: Honza_Kral Assigned to: jkocherhans (accepted)
Milestone: Component: Admin interface
Version: SVN Keywords: nfa-someday list_filter filterspec nfa-changelist ep2008
Cc: eallik@gmail.com, semente@taurinus.org, andreas@pelme.se Triage Stage: Design decision needed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 1

Description (Last modified by korpios)

One should be able to create custom FilterSpecs for the admin's list_filter interface.

Honza_Kral: I modified the filterspec definition to allow for users to register their own filters in admin. The mechanism is simple - I just reverted the order of the registry so that newly registered specs will come first. That way if you register your own filter via FilterSpec.register, it will be used before the default one.

Another approach by korpios is described in the comments.

Attachments

ticket-5833-against-newforms-admin-6477.diff (3.6 kB) - added by Honza_Kral on 10/29/07 10:29:24.
custom_filterspecs_plus_fieldless.patch (10.1 kB) - added by korpios on 01/18/08 13:15:08.
Custom FilterSpecs?, also allowing fieldless FilterSpecs?
5833-against-7875.patch (3.7 kB) - added by Honza_Kral on 07/10/08 03:52:31.
updated version of my simple patch,
5833-against-7875.2.patch (3.6 kB) - added by Honza_Kral on 07/10/08 10:27:29.
5833-against-7875.3.patch (3.7 kB) - added by Honza_Kral on 07/10/08 10:33:38.

Change History

10/29/07 10:29:24 changed by Honza_Kral

  • attachment ticket-5833-against-newforms-admin-6477.diff added.

12/01/07 11:12:56 changed by jkocherhans

  • owner changed from nobody to jkocherhans.
  • needs_better_patch changed.
  • status changed from new to assigned.
  • needs_tests changed.
  • needs_docs changed.

I really like the idea behind this, but I'd need to review the code closer and won't take the time to do it right now since it's a new feature. I'd rather focus on bugs preventing newforms-admin from being used.

12/01/07 11:26:06 changed by Honza_Kral

Also see #3400 for another ideas about filters which could benefit from this scheme...

12/07/07 19:58:26 changed by brosner

  • keywords changed from newforms admin list_filter filterspec to nfa-someday list_filter filterspec.

This ticket isn't critical to merge newforms-admin into trunk. Tagging with nfa-someday.

12/26/07 12:25:58 changed by buriy

How about FilterSpec?.insert method to do prepend and FilterSpec?.register to do append? discussed somewhere, no?

01/18/08 13:14:04 changed by korpios

I'm attaching my crack at this issue; in particular, I wanted to allow custom FilterSpecs that aren't associated with a field. This way, you can throw together a filter for fairly arbitrary queries.

Much of the field-specific code from FilterSpec has been moved out to a subclass, FieldFilterSpec; that should be used as the superclass for custom field-based filterspecs, while FilterSpec can be used for non-field-based ones.

The list_filter syntax gains two further options besides field names: a FilterSpec subclass, or a tuple of ('field_name', FieldFilterSpecSubclass).

An example combining all three:

list_filter = (
    'field1',
    ('field2', SomeFieldFilterSpec),
    SomeFilterSpec,
)

01/18/08 13:15:08 changed by korpios

  • attachment custom_filterspecs_plus_fieldless.patch added.

Custom FilterSpecs?, also allowing fieldless FilterSpecs?

01/18/08 13:22:09 changed by korpios

  • cc set to korpios@korpios.com.

01/18/08 14:01:21 changed by korpios

  • description changed.
  • summary changed from newforms-admin enable registering custom FilterSpecs to [newforms-admin] Custom FilterSpecs.

Tweaked the summary and description.

03/03/08 21:07:04 changed by anonymous

  • stage changed from Unreviewed to Design decision needed.

03/03/08 21:08:37 changed by jacob

that was me; sorry.

03/19/08 00:28:26 changed by ales_zoulek

  • keywords changed from nfa-someday list_filter filterspec to nfa-someday list_filter filterspec nfa-changelist.

06/04/08 03:11:55 changed by RaceCondition <eallik@gmail.com>

  • cc changed from korpios@korpios.com to korpios@korpios.com, eallik@gmail.com.

07/10/08 03:52:31 changed by Honza_Kral

  • attachment 5833-against-7875.patch added.

updated version of my simple patch,

07/10/08 10:18:02 changed by Honza_Kral

  • keywords changed from nfa-someday list_filter filterspec nfa-changelist to nfa-someday list_filter filterspec nfa-changelist ep2008.

07/10/08 10:27:29 changed by Honza_Kral

  • attachment 5833-against-7875.2.patch added.

07/10/08 10:33:38 changed by Honza_Kral

  • attachment 5833-against-7875.3.patch added.

07/19/08 16:42:01 changed by Alex

  • version changed from newforms-admin to SVN.

08/14/08 22:21:13 changed by elwaywitvac <elwaywitvac@gmail.com>

  • needs_better_patch set to 1.
Honza_Kral: I modified the filterspec definition to allow for users to register their own filters in admin. The mechanism is simple - I just reverted the order of the registry so that newly registered specs will come first. That way if you register your own filter via FilterSpec.register, it will be used before the default one.

I'm not sure having a reversed registry is intuitive. It certainly makes overriding FilterSpecs? simple. Except if I were to register two FilterSpecs? I would expect them to be tested the order I add them, the same way it is done in the rest of Django. Maybe the FilterSpec?'s should be in a Priority Queue instead of a Queue?

I had created a solution which doesn't reverse the registry ticket:8330. But I'm realizing now that this wouldn't allow for overriding other filters like Boolean. I'll keep playing.

08/14/08 22:45:48 changed by elwaywitvac <elwaywitvac@gmail.com>

Suggestion: make FieldFilterSpec?'s similar to how widgets work in newforms admin.

08/20/08 16:07:27 changed by Guilherme M. Gondim <semente@taurinus.org>

  • cc changed from korpios@korpios.com, eallik@gmail.com to korpios@korpios.com, eallik@gmail.com, semente@taurinus.org.

08/21/08 11:05:27 changed by korpios

  • cc changed from korpios@korpios.com, eallik@gmail.com, semente@taurinus.org to eallik@gmail.com, semente@taurinus.org.

09/05/08 02:57:04 changed by anonymous

  • cc changed from eallik@gmail.com, semente@taurinus.org to eallik@gmail.com, semente@taurinus.org, andreas@pelme.se.

Add/Change #5833 ([newforms-admin] Custom FilterSpecs)




Change Properties
Action