kopia lustrzana https://github.com/wagtail/wagtail
Add WAGTAIL_ prefix to non-taggit settings
rodzic
251d1d188c
commit
4f37b011f5
|
@ -4,6 +4,7 @@ Changelog
|
|||
6.5 (xx.xx.xxxx) - IN DEVELOPMENT
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
* Add `WAGTAIL_` prefix to Wagtail-specific tag settings (Aayushman Singh)
|
||||
* Docs: Add missing `django.contrib.admin` to list of apps in "add to Django project" guide (Mohamed Rabiaa)
|
||||
|
||||
|
||||
|
|
|
@ -808,18 +808,26 @@ TAGGIT_CASE_INSENSITIVE = True
|
|||
|
||||
Tags are case-sensitive by default ('music' and 'Music' are treated as distinct tags). In many cases the reverse behavior is preferable.
|
||||
|
||||
### `TAG_SPACES_ALLOWED`
|
||||
### `WAGTAIL_TAG_SPACES_ALLOWED`
|
||||
|
||||
```{versionchanged} 6.5
|
||||
The setting was renamed from `TAG_SPACES_ALLOWED` to `WAGTAIL_TAG_SPACES_ALLOWED`.
|
||||
```
|
||||
|
||||
```python
|
||||
TAG_SPACES_ALLOWED = False
|
||||
WAGTAIL_TAG_SPACES_ALLOWED = False
|
||||
```
|
||||
|
||||
Tags can only consist of a single word, no spaces allowed. The default setting is `True` (spaces in tags are allowed).
|
||||
|
||||
### `TAG_LIMIT`
|
||||
### `WAGTAIL_TAG_LIMIT`
|
||||
|
||||
```{versionchanged} 6.5
|
||||
The setting was renamed from `TAG_LIMIT` to `WAGTAIL_TAG_LIMIT`.
|
||||
```
|
||||
|
||||
```python
|
||||
TAG_LIMIT = 5
|
||||
WAGTAIL_TAG_LIMIT = 5
|
||||
```
|
||||
|
||||
Limit the number of tags that can be added to (django-taggit) Tag model. Default setting is `None`, meaning no limit on tags.
|
||||
|
|
|
@ -31,6 +31,10 @@ depth: 1
|
|||
|
||||
## Upgrade considerations - deprecation of old functionality
|
||||
|
||||
### `TAG_LIMIT` and `TAG_SPACES_ALLOWED` settings renamed to `WAGTAIL_TAG_LIMIT` and `WAGTAIL_TAG_SPACES_ALLOWED`
|
||||
|
||||
The `TAG_LIMIT` and `TAG_SPACES_ALLOWED` settings have been renamed to `WAGTAIL_TAG_LIMIT` and `WAGTAIL_TAG_SPACES_ALLOWED` respectively. The old settings will continue to work for now, but will be removed in a future release.
|
||||
|
||||
## Upgrade considerations - changes affecting Wagtail customisations
|
||||
|
||||
## Upgrade considerations - changes to undocumented internals
|
||||
|
|
|
@ -12,6 +12,7 @@ from wagtail.admin.forms.tags import TagField
|
|||
from wagtail.models import Page
|
||||
from wagtail.test.testapp.forms import AdminStarDateInput
|
||||
from wagtail.test.testapp.models import EventPage, RestaurantTag, SimplePage
|
||||
from wagtail.utils.deprecation import RemovedInWagtail70Warning
|
||||
|
||||
|
||||
class TestAdminPageChooserWidget(TestCase):
|
||||
|
@ -430,9 +431,9 @@ class TestAdminTagWidget(TestCase):
|
|||
],
|
||||
)
|
||||
|
||||
@override_settings(TAG_SPACES_ALLOWED=False)
|
||||
@override_settings(WAGTAIL_TAG_SPACES_ALLOWED=False)
|
||||
def test_render_js_init_no_spaces_allowed(self):
|
||||
"""Checks that the 'w-tag' controller attributes are correctly added to the tag widgets based on TAG_SPACES_ALLOWED in settings"""
|
||||
"""Checks that the 'w-tag' controller attributes are correctly added to the tag widgets based on WAGTAIL_TAG_SPACES_ALLOWED in settings"""
|
||||
widget = widgets.AdminTagWidget()
|
||||
|
||||
html = widget.render("tags", None, attrs={"id": "alpha"})
|
||||
|
@ -447,9 +448,9 @@ class TestAdminTagWidget(TestCase):
|
|||
],
|
||||
)
|
||||
|
||||
@override_settings(TAG_LIMIT=5)
|
||||
@override_settings(WAGTAIL_TAG_LIMIT=5)
|
||||
def test_render_js_init_with_tag_limit(self):
|
||||
"""Checks that the 'w-tag' controller attributes are correctly added to the tag widget using options based on TAG_LIMIT in settings"""
|
||||
"""Checks that the 'w-tag' controller attributes are correctly added to the tag widget using options based on WAGTAIL_TAG_LIMIT in settings"""
|
||||
|
||||
widget = widgets.AdminTagWidget()
|
||||
|
||||
|
@ -517,9 +518,9 @@ class TestAdminTagWidget(TestCase):
|
|||
],
|
||||
)
|
||||
|
||||
@override_settings(TAG_SPACES_ALLOWED=True)
|
||||
@override_settings(WAGTAIL_TAG_SPACES_ALLOWED=True)
|
||||
def test_tags_help_text_spaces_allowed(self):
|
||||
"""Checks that the tags help text html element content is correct when TAG_SPACES_ALLOWED is True"""
|
||||
"""Checks that the tags help text html element content is correct when WAGTAIL_TAG_SPACES_ALLOWED is True"""
|
||||
widget = widgets.AdminTagWidget()
|
||||
help_text = widget.get_context(None, None, {})["widget"]["help_text"]
|
||||
|
||||
|
@ -535,9 +536,9 @@ class TestAdminTagWidget(TestCase):
|
|||
html,
|
||||
)
|
||||
|
||||
@override_settings(TAG_SPACES_ALLOWED=False)
|
||||
@override_settings(WAGTAIL_TAG_SPACES_ALLOWED=False)
|
||||
def test_tags_help_text_no_spaces_allowed(self):
|
||||
"""Checks that the tags help text html element content is correct when TAG_SPACES_ALLOWED is False"""
|
||||
"""Checks that the tags help text html element content is correct when WAGTAIL_TAG_SPACES_ALLOWED is False"""
|
||||
widget = widgets.AdminTagWidget()
|
||||
help_text = widget.get_context(None, None, {})["widget"]["help_text"]
|
||||
|
||||
|
@ -552,6 +553,44 @@ class TestAdminTagWidget(TestCase):
|
|||
html,
|
||||
)
|
||||
|
||||
@override_settings(TAG_LIMIT=3)
|
||||
def test_legacy_tag_limit_setting(self):
|
||||
widget = widgets.AdminTagWidget()
|
||||
with self.assertWarnsMessage(
|
||||
RemovedInWagtail70Warning,
|
||||
"The setting 'TAG_LIMIT' is deprecated. "
|
||||
"Please use 'WAGTAIL_TAG_LIMIT' instead.",
|
||||
):
|
||||
html = widget.render("tags", None, attrs={"id": "alpha"})
|
||||
params = self.get_js_init_params(html)
|
||||
self.assertEqual(
|
||||
params,
|
||||
[
|
||||
"alpha",
|
||||
"/admin/tag-autocomplete/",
|
||||
{"allowSpaces": True, "tagLimit": 3, "autocompleteOnly": False},
|
||||
],
|
||||
)
|
||||
|
||||
@override_settings(TAG_SPACES_ALLOWED=False)
|
||||
def test_legacy_tag_spaces_allowed_setting(self):
|
||||
widget = widgets.AdminTagWidget()
|
||||
with self.assertWarnsMessage(
|
||||
RemovedInWagtail70Warning,
|
||||
"The setting 'TAG_SPACES_ALLOWED' is deprecated. "
|
||||
"Please use 'WAGTAIL_TAG_SPACES_ALLOWED' instead.",
|
||||
):
|
||||
html = widget.render("tags", None, attrs={"id": "alpha"})
|
||||
params = self.get_js_init_params(html)
|
||||
self.assertEqual(
|
||||
params,
|
||||
[
|
||||
"alpha",
|
||||
"/admin/tag-autocomplete/",
|
||||
{"allowSpaces": False, "tagLimit": None, "autocompleteOnly": False},
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
class TestTagField(TestCase):
|
||||
def setUp(self):
|
||||
|
|
|
@ -2,6 +2,8 @@ from django.contrib.contenttypes.models import ContentType
|
|||
from django.http import Http404, JsonResponse
|
||||
from taggit.models import Tag, TagBase
|
||||
|
||||
TAGS_AUTOCOMPLETE_LIMIT = 10
|
||||
|
||||
|
||||
def autocomplete(request, app_name=None, model_name=None):
|
||||
if app_name and model_name:
|
||||
|
@ -22,7 +24,7 @@ def autocomplete(request, app_name=None, model_name=None):
|
|||
tags = (
|
||||
tag_model.objects.filter(name__istartswith=term)
|
||||
.order_by("name")
|
||||
.values_list("name", flat=True)[:10]
|
||||
.values_list("name", flat=True)[:TAGS_AUTOCOMPLETE_LIMIT]
|
||||
)
|
||||
else:
|
||||
tags = tag_model.objects.none()
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import json
|
||||
from warnings import warn
|
||||
|
||||
from django.conf import settings
|
||||
from django.urls import reverse
|
||||
|
@ -6,6 +7,8 @@ from django.utils.translation import gettext_lazy as _
|
|||
from taggit.forms import TagWidget
|
||||
from taggit.models import Tag
|
||||
|
||||
from wagtail.utils.deprecation import RemovedInWagtail70Warning
|
||||
|
||||
|
||||
class AdminTagWidget(TagWidget):
|
||||
template_name = "wagtailadmin/widgets/tag_widget.html"
|
||||
|
@ -39,7 +42,19 @@ class AdminTagWidget(TagWidget):
|
|||
else:
|
||||
free_tagging = self.free_tagging
|
||||
|
||||
tag_spaces_allowed = getattr(settings, "TAG_SPACES_ALLOWED", True)
|
||||
if hasattr(settings, "TAG_SPACES_ALLOWED"):
|
||||
warn(
|
||||
"The setting 'TAG_SPACES_ALLOWED' is deprecated. "
|
||||
"Please use 'WAGTAIL_TAG_SPACES_ALLOWED' instead.",
|
||||
RemovedInWagtail70Warning,
|
||||
)
|
||||
tag_spaces_allowed = getattr(
|
||||
settings,
|
||||
"WAGTAIL_TAG_SPACES_ALLOWED",
|
||||
# RemovedInWagtail70Warning: Remove fallback to deprecated setting
|
||||
getattr(settings, "TAG_SPACES_ALLOWED", True),
|
||||
)
|
||||
|
||||
if tag_spaces_allowed:
|
||||
help_text = _(
|
||||
'Multi-word tags with spaces will automatically be enclosed in double quotes (").'
|
||||
|
@ -47,13 +62,26 @@ class AdminTagWidget(TagWidget):
|
|||
else:
|
||||
help_text = _("Tags can only consist of a single word, no spaces allowed.")
|
||||
|
||||
if hasattr(settings, "TAG_LIMIT"):
|
||||
warn(
|
||||
"The setting 'TAG_LIMIT' is deprecated. "
|
||||
"Please use 'WAGTAIL_TAG_LIMIT' instead.",
|
||||
RemovedInWagtail70Warning,
|
||||
)
|
||||
tag_limit = getattr(
|
||||
settings,
|
||||
"WAGTAIL_TAG_LIMIT",
|
||||
# RemovedInWagtail70Warning: Remove fallback to deprecated setting
|
||||
getattr(settings, "TAG_LIMIT", None),
|
||||
)
|
||||
|
||||
context["widget"]["help_text"] = help_text
|
||||
context["widget"]["attrs"]["data-w-tag-delay-value"] = 200
|
||||
context["widget"]["attrs"]["data-w-tag-url-value"] = autocomplete_url
|
||||
context["widget"]["attrs"]["data-w-tag-options-value"] = json.dumps(
|
||||
{
|
||||
"allowSpaces": getattr(settings, "TAG_SPACES_ALLOWED", True),
|
||||
"tagLimit": getattr(settings, "TAG_LIMIT", None),
|
||||
"allowSpaces": tag_spaces_allowed,
|
||||
"tagLimit": tag_limit,
|
||||
"autocompleteOnly": not free_tagging,
|
||||
}
|
||||
)
|
||||
|
|
Ładowanie…
Reference in New Issue