Skip to content

Commit

Permalink
Resolve error when specifying 'slug' as a read-only field (wagtail#11447
Browse files Browse the repository at this point in the history
)
  • Loading branch information
rohitsrma authored and gasman committed Jan 15, 2024
1 parent 67f495b commit 33fbbed
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Changelog
* Fix: Ensure workflow dashboard panels work when the page/snippet is missing (Sage Abdullah)
* Fix: Prevent a ValueError with `FormSubmissionsPanel` on Django 5.0 when creating a new form page (Matt Westcott)
* Fix: Avoid duplicate entries in "Recent edits" panel when copying pages (Matt Westcott)
* Fix: Prevent TitleFieldPanel from raising an error when the slug field is missing or read-only (Rohit Sharma)
* Docs: Document, for contributors, the use of translate string literals passed as arguments to tags and filters using `_()` within templates (Chiemezuo Akujobi)
* Docs: Document all features for the Documents app in one location (Neeraj Yetheendran)
* Docs: Add section to testing docs about creating pages and working with page content (Mariana Bedran Lesche)
Expand Down
2 changes: 2 additions & 0 deletions docs/releases/6.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ Thank you to Thibaud Colas and Badr Fourane for their work on this feature.
* Prevent a ValueError with `FormSubmissionsPanel` on Django 5.0 when creating a new form page (Matt Westcott)
* Add ability to [customise a page's copy form](custom_page_copy_form) including an auto-incrementing slug example (Neeraj Yetheendran)
* Avoid duplicate entries in "Recent edits" panel when copying pages (Matt Westcott)
* Prevent TitleFieldPanel from raising an error when the slug field is missing or read-only (Rohit Sharma)


### Documentation

Expand Down
6 changes: 5 additions & 1 deletion wagtail/admin/panels/title_field_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ def get_attrs(self):
actions = [widget.attrs.get("data-action", None)] + self.apply_actions
attrs["data-action"] = " ".join(filter(None, actions))

targets = [self.get_target_selector(target) for target in panel.targets]
targets = [
self.get_target_selector(target)
for target in panel.targets
if target in self.form.fields
]
attrs["data-w-sync-target-value"] = ", ".join(filter(None, targets))

placeholder = self.get_placeholder()
Expand Down
19 changes: 19 additions & 0 deletions wagtail/admin/tests/test_edit_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2258,6 +2258,25 @@ def test_default_title_field_panel(self):
"focus->w-sync#check blur->w-sync#apply change->w-sync#apply keyup->w-sync#apply",
)

def test_form_without_slugfield(self):
html = self.get_edit_handler_html(ObjectList([TitleFieldPanel("title")]))

self.assertIsNotNone(html.find(attrs={"class": "w-panel title"}))

attrs = html.find("input").attrs
self.assertEqual(attrs["data-w-sync-target-value"], "")

def test_form_with_readonly_slugfield(self):
html = self.get_edit_handler_html(
ObjectList([TitleFieldPanel("title"), FieldPanel("slug", read_only=True)]),
instance=EventPage(),
)

self.assertIsNotNone(html.find(attrs={"class": "w-panel title"}))

attrs = html.find("input").attrs
self.assertEqual(attrs["data-w-sync-target-value"], "")

def test_not_using_apply_actions_if_live(self):
"""
If the Page (or any model) has `live = True`, do not apply the actions by default.
Expand Down

0 comments on commit 33fbbed

Please sign in to comment.