Fix extract_references for DocumentChooserBlock

pull/9454/head
Alex Tomkins 2022-10-20 00:36:16 +01:00 zatwierdzone przez Dan Braghis
rodzic 912747f6ae
commit 063f2bc7a5
Nie znaleziono w bazie danych klucza dla tego podpisu
4 zmienionych plików z 21 dodań i 1 usunięć

Wyświetl plik

@ -10,6 +10,7 @@ Changelog
* Fix: Make sure workflow timeline icons are visible in high-contrast mode (Loveth Omokaro)
* Fix: Ensure authentication forms (login, password reset) have a visible border in Windows high-contrast mode (Loveth Omokaro)
* Fix: Ensure visual consistency between buttons and links as buttons in Windows high-contrast mode (Albina Starykova)
* Fix: references extraction for ChooserBlock (Alex Tomkins)
4.1 LTS (xx.xx.xxxx) - IN DEVELOPMENT

Wyświetl plik

@ -23,6 +23,7 @@ depth: 1
* Make sure workflow timeline icons are visible in high-contrast mode (Loveth Omokaro)
* Ensure authentication forms (login, password reset) have a visible border in Windows high-contrast mode (Loveth Omokaro)
* Ensure visual consistency between buttons and links as buttons in Windows high-contrast mode (Albina Starykova)
* Ensure `ChooserBlock.extract_references` uses the model class, not the model string (Alex Tomkins)
## Upgrade considerations

Wyświetl plik

@ -829,7 +829,7 @@ class ChooserBlock(FieldBlock):
def extract_references(self, value):
if value is not None:
yield self.target_model, str(value.pk), "", ""
yield self.model_class, str(value.pk), "", ""
class Meta:
# No icon specified here, because that depends on the purpose that the

Wyświetl plik

@ -1,7 +1,10 @@
from django.test import TestCase
from wagtail.documents import get_document_model
from wagtail.documents.blocks import DocumentChooserBlock
from .utils import get_test_document_file
class TestDocumentChooserBlock(TestCase):
def test_deconstruct(self):
@ -10,3 +13,18 @@ class TestDocumentChooserBlock(TestCase):
self.assertEqual(path, "wagtail.documents.blocks.DocumentChooserBlock")
self.assertEqual(args, ())
self.assertEqual(kwargs, {"required": False})
def test_extract_references(self):
Document = get_document_model()
document = Document.objects.create(
title="Test document", file=get_test_document_file()
)
block = DocumentChooserBlock()
self.assertListEqual(
list(block.extract_references(document)),
[(Document, str(document.id), "", "")],
)
# None should not yield any references
self.assertListEqual(list(block.extract_references(None)), [])