kopia lustrzana https://github.com/wagtail/wagtail
Fix extract_references for DocumentChooserBlock
rodzic
912747f6ae
commit
063f2bc7a5
|
@ -10,6 +10,7 @@ Changelog
|
||||||
* Fix: Make sure workflow timeline icons are visible in high-contrast mode (Loveth Omokaro)
|
* 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 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: 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
|
4.1 LTS (xx.xx.xxxx) - IN DEVELOPMENT
|
||||||
|
|
|
@ -23,6 +23,7 @@ depth: 1
|
||||||
* Make sure workflow timeline icons are visible in high-contrast mode (Loveth Omokaro)
|
* 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 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 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
|
## Upgrade considerations
|
||||||
|
|
||||||
|
|
|
@ -829,7 +829,7 @@ class ChooserBlock(FieldBlock):
|
||||||
|
|
||||||
def extract_references(self, value):
|
def extract_references(self, value):
|
||||||
if value is not None:
|
if value is not None:
|
||||||
yield self.target_model, str(value.pk), "", ""
|
yield self.model_class, str(value.pk), "", ""
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
# No icon specified here, because that depends on the purpose that the
|
# No icon specified here, because that depends on the purpose that the
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
|
from wagtail.documents import get_document_model
|
||||||
from wagtail.documents.blocks import DocumentChooserBlock
|
from wagtail.documents.blocks import DocumentChooserBlock
|
||||||
|
|
||||||
|
from .utils import get_test_document_file
|
||||||
|
|
||||||
|
|
||||||
class TestDocumentChooserBlock(TestCase):
|
class TestDocumentChooserBlock(TestCase):
|
||||||
def test_deconstruct(self):
|
def test_deconstruct(self):
|
||||||
|
@ -10,3 +13,18 @@ class TestDocumentChooserBlock(TestCase):
|
||||||
self.assertEqual(path, "wagtail.documents.blocks.DocumentChooserBlock")
|
self.assertEqual(path, "wagtail.documents.blocks.DocumentChooserBlock")
|
||||||
self.assertEqual(args, ())
|
self.assertEqual(args, ())
|
||||||
self.assertEqual(kwargs, {"required": False})
|
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)), [])
|
||||||
|
|
Ładowanie…
Reference in New Issue