Merge pull request #386 from rpkilby/settings-help-text
Settings help text
This commit is contained in:
commit
6639fd6850
|
@ -8,6 +8,7 @@ from django import forms
|
|||
from django.db.models import Q
|
||||
from django.db.models.sql.constants import QUERY_TERMS
|
||||
from django.db.models.constants import LOOKUP_SEP
|
||||
from django.conf import settings
|
||||
from django.utils import six
|
||||
from django.utils.timezone import now
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
@ -83,7 +84,13 @@ class Filter(object):
|
|||
if not hasattr(self, '_field'):
|
||||
help_text = self.extra.pop('help_text', None)
|
||||
if help_text is None:
|
||||
help_text = _('This is an exclusion filter') if self.exclude else _('Filter')
|
||||
if self.exclude and getattr(settings, "FILTERS_HELP_TEXT_EXCLUDE", True):
|
||||
help_text = _('This is an exclusion filter')
|
||||
elif not self.exclude and getattr(settings, "FILTERS_HELP_TEXT_FILTER", True):
|
||||
help_text = _('Filter')
|
||||
else:
|
||||
help_text = ''
|
||||
|
||||
if (self.lookup_expr is None or
|
||||
isinstance(self.lookup_expr, (list, tuple))):
|
||||
|
||||
|
|
|
@ -18,4 +18,5 @@ Contents:
|
|||
ref/filters
|
||||
ref/fields
|
||||
ref/widgets
|
||||
ref/settings
|
||||
tests
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
.. _ref-settings:
|
||||
|
||||
==================
|
||||
Available Settings
|
||||
==================
|
||||
|
||||
Here is a list of all available settings of django-filters and their
|
||||
default values. All settings are prefixed with ``FILTERS_``, although this
|
||||
is a bit verbose it helps to make it easy to identify these settings.
|
||||
|
||||
|
||||
FILTERS_HELP_TEXT_EXCLUDE
|
||||
-------------------------
|
||||
|
||||
Default: ``True``
|
||||
|
||||
Enable / disable the default field ``help_text`` on filters where ``exclude=True`` (:doc:`/ref/filters`). This does not affect fields which explicitly define ``help_text``.
|
||||
|
||||
FILTERS_HELP_TEXT_FILTER
|
||||
------------------------
|
||||
|
||||
Default: ``True``
|
||||
|
||||
Enable / disable the default field ``help_text`` on filters where ``exclude=False`` (:doc:`/ref/filters`). This does not affect fields which explicitly define ``help_text``.
|
|
@ -7,7 +7,7 @@ import warnings
|
|||
import unittest
|
||||
|
||||
from django import forms
|
||||
from django.test import TestCase
|
||||
from django.test import TestCase, override_settings
|
||||
|
||||
from django_filters import filters
|
||||
from django_filters.fields import (
|
||||
|
@ -70,6 +70,20 @@ class FilterTests(TestCase):
|
|||
self.assertIsInstance(field, forms.Field)
|
||||
self.assertEqual(field.help_text, 'This is an exclusion filter')
|
||||
|
||||
@override_settings(FILTERS_HELP_TEXT_FILTER=False)
|
||||
def test_default_field_settings(self):
|
||||
f = Filter()
|
||||
field = f.field
|
||||
self.assertIsInstance(field, forms.Field)
|
||||
self.assertEqual(field.help_text, '')
|
||||
|
||||
@override_settings(FILTERS_HELP_TEXT_EXCLUDE=False)
|
||||
def test_field_with_exclusion_settings(self):
|
||||
f = Filter(exclude=True)
|
||||
field = f.field
|
||||
self.assertIsInstance(field, forms.Field)
|
||||
self.assertEqual(field.help_text, '')
|
||||
|
||||
def test_field_with_single_lookup_expr(self):
|
||||
f = Filter(lookup_expr='iexact')
|
||||
field = f.field
|
||||
|
|
Loading…
Reference in New Issue