Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add abstract CSV filters, filter overrides for specific lookup types #363

Merged
merged 35 commits into from
Feb 23, 2016

Conversation

rpkilby
Copy link
Collaborator

@rpkilby rpkilby commented Feb 5, 2016

This supersedes/builds on my last PR (#362). Here is the diff between the two.

Relevant issues:

Closes #362 (PR)
Closes #344 (PR)
Fixes #321
Fixes #273

Changes:

  • adds the ability to use transforms in lookup expressions (from previous PR)
  • adds abstract base classes for CSV (in, range) filters and fields.
  • adds filter generation handling for lookups (Filterset.filter_for_lookup).

The abstract CSV filter work is partially based on the work done in #344. The major difference is that type conversion/validation is performed by the field instead of in the widget's customize method. Dynamically created subclasses allow us to use the abstract CSV filter to handle just the list of values, while reusing the cleaning behavior on individual values from the base field class. I also removed sanitize, as it did not allow you to filter by empty char values.

TODO:

This is not fully complete, but wanted to go ahead and try to get eyes on as it should be close to done.

  • test additional field types (datetimes, strings, FKs) for abstract CSV filters
  • testing for lookup overrides (Filterset.filter_for_lookup)
  • documentation
  • decide if dynamic CSV filters/fields should be cached (as two NumberRangeFilter classes would be identical). That said, it seems like a one time cost to generate the class then instance for each filter. Thoughts on this?

Ryan P Kilby and others added 13 commits February 3, 2016 12:10
This will allow us to correctly provide overrides for transformed
lookups. eg, `published_at__year__gte=2016`
- sanitize does not allow for empty values
- type conversion should happen at the field level
Conflicts:
	django_filters/filters.py
- Includes 'isnull' handling
- Includes 'in' and 'range' handling that are dynamically created for
  its underlying field type.
@carltongibson
Copy link
Owner

@rpkilby This looks great. Just on your last point: I'm not too worried about caching. I'd be very surprised if we had a bottleneck here. (And I'm inclined to leave such things as out of scope.)

@rpkilby
Copy link
Collaborator Author

rpkilby commented Feb 18, 2016

Hi @carltongibson. I think this is ready for review. My only outstanding concern is documentation. I have added docs for the base IN and RANGE filters, as well as doc updates for the shift from lookup_type to a lookup_expr that supports transforms.

So, are more extensive docs necessary? While this is a somewhat large PR, it's really just one big bug fix for handling filter generation for some lookups. Maybe adding more detailed notes to the changelog would suffice?

@carltongibson
Copy link
Owner

@rpkilby This is great.

So, are more extensive docs necessary?

What I'd really like to see here is just few lines demonstrating the usage of the (various) CSV options — by that I mean a snippet of the URL query string that the user constructs for the filtering behaviour and the matching filter declaration — i.e. we don't need running examples — but useful extracts.

My main issue is that new users find it hard to see how to put filter sets together — that's a documentation thing — the learning curve is too steep.

Makes sense?

@rpkilby
Copy link
Collaborator Author

rpkilby commented Feb 19, 2016

@carltongibson I've added docs on a separate branch/self-PR because the changes are somewhat extensive. Similar to this PR, there's a bit going on so I tried to isolate the work done in each commit. Reading the history in order might give you a better idea of what's going on than looking at the whole diff at once.

  • documentation PR on my fork here.
  • build of the docs hosted on gh-pages here.

What I'd really like to see here is just few lines demonstrating the usage of the (various) CSV options

Usage docs for the CSV filters are in this commit. This was based off of the DateTimeFromToRangeFilter docs.

My main issue is that new users find it hard to see how to put filter sets together

All of the other commits are an attempt at improving the structure and approachability of the docs. I don't know if that's achieved, but that was the idea. Please nitpick any issues or submit PRs against my fork or whatever.

If all looks good, I'll merge the doc changes PR into this one so we can proceed.

@rpkilby
Copy link
Collaborator Author

rpkilby commented Feb 20, 2016

Also, added some notes on how to override filter_for_lookup. This is also used to explain the method default behavior.

@rpkilby
Copy link
Collaborator Author

rpkilby commented Feb 20, 2016

Alright - docs are updated and merged.

@rpkilby
Copy link
Collaborator Author

rpkilby commented Feb 20, 2016

Quick note - improved handling for isnull lookups. Instead of automatically returning a BooleanFilter with the default arguments, this redoes the DEFAULTS lookup as if it were a boolean field. This ensures 'isnull' lookups conform to any changes in filter_overrides. eg, using the ajax friendly BooleanWidget.

The in and range lookups are still correct, as their underlying model field type is the same.

carltongibson pushed a commit that referenced this pull request Feb 23, 2016
Add abstract CSV filters, filter overrides for specific lookup types
@carltongibson carltongibson merged commit de3147a into carltongibson:develop Feb 23, 2016
@carltongibson
Copy link
Owner

👍

@carltongibson carltongibson modified the milestone: 0.12.1 Feb 23, 2016
@rpkilby
Copy link
Collaborator Author

rpkilby commented Feb 23, 2016

Sweet - any timeframe on the release? There are some updates to drf-filters that will be dependent on it. Thanks.

@carltongibson
Copy link
Owner

This week.

@rpkilby
Copy link
Collaborator Author

rpkilby commented Feb 23, 2016

Great - thanks again.

@rpkilby rpkilby deleted the lookup-filters branch March 22, 2016 04:09
@mlissner
Copy link

mlissner commented Oct 4, 2017

This is an old thread, but I just want to say how wonderful it was to find this feature available today, just when I needed it. Truly wonderful, thank you so much for all your efforts on this project. You've made at least one person super happy today.

@rpkilby
Copy link
Collaborator Author

rpkilby commented Oct 4, 2017

😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants