Added raw check for fixtures and test for pre_save_feature_detection

Fixes #3589
pull/8307/head
4the4ryushin 2022-10-28 13:56:25 +05:30 zatwierdzone przez LB (Ben Johnston)
rodzic af1f1715a3
commit bc05374c95
4 zmienionych plików z 24 dodań i 5 usunięć

Wyświetl plik

@ -33,6 +33,7 @@ Changelog
* Fix: Allow both horizontal and vertical manual resizing of TextFields (Anisha Singh)
* Fix: Move DateField, DateTimeField, TimeField comment buttons to be right next to the fields (Theresa Okoro)
* Fix: Support text resizing in workflow steps cards (Ivy Jeptoo)
* Fix: Ignore images added via fixtures when using `WAGTAILIMAGES_FEATURE_DETECTION_ENABLED` to avoid errors for images that do not exist (Aman Pandey)
* Docs: Add custom permissions section to permissions documentation page (Dan Hayden)
* Docs: Add documentation for how to get started with contributing translations for the Wagtail admin (Ogunbanjo Oluwadamilare)
* Docs: Officially recommend `fnm` over `nvm` in development documentation (LB (Ben) Johnston)

Wyświetl plik

@ -45,6 +45,7 @@ depth: 1
* Allow both horizontal and vertical manual resizing of TextFields (Anisha Singh)
* Move DateField, DateTimeField, TimeField comment buttons to be right next to the fields (Theresa Okoro)
* Support text resizing in workflow steps cards (Ivy Jeptoo)
* Ignore images added via fixtures when using `WAGTAILIMAGES_FEATURE_DETECTION_ENABLED` to avoid errors for images that do not exist (Aman Pandey)
### Documentation

Wyświetl plik

@ -16,10 +16,12 @@ def post_delete_purge_rendition_cache(instance, **kwargs):
def pre_save_image_feature_detection(instance, **kwargs):
if getattr(settings, "WAGTAILIMAGES_FEATURE_DETECTION_ENABLED", False):
# Make sure the image doesn't already have a focal point
if not instance.has_focal_point():
# Set the focal point
instance.set_focal_point(instance.get_suggested_focal_point())
# Make sure the image is not from a fixture
if kwargs["raw"] is False:
# Make sure the image doesn't already have a focal point
if not instance.has_focal_point():
# Set the focal point
instance.set_focal_point(instance.get_suggested_focal_point())
def register_signal_handlers():

Wyświetl plik

@ -1,10 +1,12 @@
from django.db import transaction
from django.test import TransactionTestCase, override_settings
from django.test import TestCase, TransactionTestCase, override_settings
from wagtail.images import get_image_model, signal_handlers
from wagtail.images.tests.utils import get_test_image_file
from wagtail.models import Collection
from .utils import Image
class TestFilesDeletedForDefaultModels(TransactionTestCase):
"""
@ -80,3 +82,16 @@ class TestFilesDeletedForCustomModels(TestFilesDeletedForDefaultModels):
self.assertEqual(
"%s.%s" % (cls._meta.app_label, cls.__name__), "tests.CustomImage"
)
@override_settings(WAGTAILIMAGES_FEATURE_DETECTION_ENABLED=True)
class TestRawForPreSaveImageFeatureDetection(TestCase):
fixtures = ["test.json"]
# just to test the file is from a fixture doesn't actually exists.
# raw check in pre_save_image_feature_detection skips on the provided condition of this test
# hence avoiding an error
def test_image_does_not_exist(self):
bad_image = Image.objects.get(pk=1)
self.assertFalse(bad_image.file.storage.exists(bad_image.file.name))