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
Rework form labels #437
Rework form labels #437
Conversation
244a315
to
f6254cd
Compare
f6254cd
to
c5dbf7c
Compare
c5dbf7c
to
2879f0a
Compare
7a275c4
to
d4dce7a
Compare
Hey @carltongibson - this should be ready for review whenever. Any thoughts on the remaining questions/issues? |
Yep. :-) To wit: It's probably OK as it is. |
Will there be an option to disable those "help-text" labels? I have actually set FILTERS_HELP_TEXT_FILTER to False and I would like to keep it the same way. |
Hi @eriktelepovsky. I'm not entirely sure what you're asking here - could you clarify? If you're concerned with If you're concerned with the more verbose labels, keep in mind that these are
You can also checkout the PR's branch and see if the form output is suitable. |
I was using older version of django-filters and after update, all my filter fields had "Filter" help text below the form field. So I had to use FILTERS_HELP_TEXT_FILTER to hide them. I don't want to display such information for any kind of filter even their lookup_expr is non-exact. Will it be possible to achieve that using simple approach/setting without necessarily updating all of my fields? |
@eriktelepovsky - Here are some explanatory examples (before, after). Whoops - forgot to add the code in question: from tests import models
from django_filters import FilterSet, filters
class CharInFilter(filters.BaseInFilter, filters.CharFilter):
pass
class UserFilter(FilterSet):
username = filters.CharFilter(name='username', lookup_expr='exact')
username__icontains = filters.CharFilter(name='username', lookup_expr='icontains')
username_is_like = filters.CharFilter(name='username', lookup_expr='icontains', label='Username is like')
status__in = CharInFilter(name='status', lookup_expr='in')
class Meta:
model = models.User
fields = []
print(str(UserFilter().form)) |
I don't want any "helptext" to be displayed by default. Neither "Values should be comma-separated". Can be all helptexts disabled using single setting, just like previous FILTERS_HELP_TEXT_FILTER? |
3d45f2e
to
251173d
Compare
Thank you for DISABLE_HELP_TEXT ;) |
Yep - I've added it since it was trivial to do. @carltongibson - thoughts on the @eriktelepovsky - if class FilterSet(django_filters.FilterSet):
def __init__(self, *args, **kwargs):
super(FilterSet, self).__init__(*args, **kwargs)
for f in six.iteritems(self.filters.values()):
f.extra.pop('help_text', '') |
Yes I know, but it seems to be unnecessary workaround for me. DISABLE_HELP_TEXT is definitely a better solution and I don't see a reason why it should be cut off 👍 |
Grrr. I think it needs to stay. (I don't particularly like it, but I see the use-case.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Great. 👍
@@ -9,6 +9,14 @@ default values. All settings are prefixed with ``FILTERS_``, although this | |||
is a bit verbose it helps to make it easy to identify these settings. | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rpkilby Can I just ask you to add
- A sub/section header grouping these
help_text
related settings - A paragraph highlighting the out-of-the-box "Off but with BaseCSV default" behaviour, which leads to needing
FILTERS_DISABLE_HELP_TEXT
Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A sub/section header grouping these help_text related settings
I've removed the docs for FILTERS_HELP_TEXT_FILTER
and FILTERS_HELP_TEXT_EXCLUDE
since they've been deprecated for the 1.0 release. Does that work?
A paragraph highlighting the out-of-the-box "Off but with BaseCSV default" behaviour, which leads to needing
FILTERS_DISABLE_HELP_TEXT
.
Done.
Also, added a section on FILTERS_VERBOSE_LABELS
.
Preview docs here.
3570024
to
6c88cc3
Compare
Hey @carltongibson - wanted to take a stab at improving the form output. In brief, the PR allows filters to automatically generate more verbose, human friendly labels to use in forms. Given the following...
This would generate default filter labels such as "Exclude author name starts with" and "Published date is less than". It's not perfect, but it should convey enough information and be suitable for DRF's filter integration.
Context:
The current form implementation works well for the
Meta.fields
list syntax, but kind of falls apart when it comes to the dict syntax. From the above example, there are a few issues:Meta.fields
. Instead of 'author first name', we just get 'first name', which doesn't make sense as it is not an attribute on the book model. This is even worse for shared fields, such as 'id' - no way to differentiate between the book 'id' and author 'id' labels.Meta.fields
dict syntax and with declarative filters. Ordering is kind of borked - only really works with theMeta.fields
list syntax.help_text
for filters.help_text
doesn't add any meaningful context. See Odd p tag #422 and DRF's default FilterSet, which comments them out.help_text
should provide additional context about usage. eg, CSV filters indicating that the expected input should be comma-separated.Change list:
Filter
class.help_text
has been removed.FILTERS_VERBOSE_LABELS
is a dict (or callable that resolves to a dict) of lookup expressions mapped to verbose expressions. eg, {'exact': 'is equal to'}.FILTERS_HELP_TEXT_FILTER
andFILTERS_HELP_TEXT_EXCLUDE
have been removed.help_text
to the base CSV filter.Misc notes:
Meta.fields
list syntax. eg, 'Author name' instead of 'Author name is equal to'.FILTERS_VERBOSE_LOOKUPS
.Questions:
At this point, the PR is 'feature complete' and tested, but there are a couple of issues/questions.
The ordering field is somewhat borked (more details in Ordering filter problems #438), and the label changes exacerbate this. Currently, one test is failing. Should the PR temporarily mark the test as an expected failure (to be fixed in a separate PR), or should this PR grow in scope and fix ordering field?Separate PR merged.Should there be a usage warning thatSeparate PR merged.FILTERS_HELP_TEXT_FILTER
andFILTERS_HELP_TEXT_EXCLUDE
no longer have effect?LookupTypeField
be integrated with theFILTERS_VERBOSE_LOOKUPS
setting? (Probably could be handled as a separate PR).TODO:
help_text
removal