diff --git a/docs/advanced_topics/images/custom_image_model.rst b/docs/advanced_topics/images/custom_image_model.rst index 4f0e001a43..6e322673ef 100644 --- a/docs/advanced_topics/images/custom_image_model.rst +++ b/docs/advanced_topics/images/custom_image_model.rst @@ -58,11 +58,6 @@ Here's an example: the image and entering custom data happen as two separate actions, and Wagtail needs to be able to create an image record immediately on upload. -.. note:: - - If you are using image feature detection, follow these instructions to - enable it on your custom image model: :ref:`feature_detection_custom_image_model` - Then set the ``WAGTAILIMAGES_IMAGE_MODEL`` setting to point to it: .. code-block:: python diff --git a/docs/advanced_topics/images/feature_detection.rst b/docs/advanced_topics/images/feature_detection.rst index a9955a3327..f44c7b3c3e 100644 --- a/docs/advanced_topics/images/feature_detection.rst +++ b/docs/advanced_topics/images/feature_detection.rst @@ -85,28 +85,3 @@ You can manually run feature detection on all images by running the following co if not image.has_focal_point(): image.set_focal_point(image.get_suggested_focal_point()) image.save() - -.. _feature_detection_custom_image_model: - -Feature detection and custom image models -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -When using a :ref:`custom_image_model`, you need to add a signal handler to -the model to trigger feature detection whenever a new image is uploaded: - -.. code-block:: python - - # Do feature detection when a user saves an image without a focal point - @receiver(pre_save, sender=CustomImage) - def image_feature_detection(sender, instance, **kwargs): - # 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()) - -.. note:: - - This example will always run feature detection regardless of whether the - ``WAGTAILIMAGES_FEATURE_DETECTION_ENABLED`` setting is set. - - Add a check for this setting if you still want it to have effect. diff --git a/docs/releases/1.10.rst b/docs/releases/1.10.rst index d14ebe880f..97b35d2d07 100644 --- a/docs/releases/1.10.rst +++ b/docs/releases/1.10.rst @@ -37,7 +37,7 @@ Upgrade considerations Signals on custom ``Image`` and ``Rendition`` models connected automatically ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Projects using :ref:`custom image models ` no longer need to set up signal receivers to handle deletion of image files, as this is now handled automatically by Wagtail. The following lines of code should be removed: +Projects using :ref:`custom image models ` no longer need to set up signal receivers to handle deletion of image files and image feature detection, as these are now handled automatically by Wagtail. The following lines of code should be removed: .. code-block:: python @@ -51,3 +51,10 @@ Projects using :ref:`custom image models ` no longer need to @receiver(post_delete, sender=CustomRendition) def rendition_delete(sender, instance, **kwargs): instance.file.delete(False) + + + # Perform image feature detection (if enabled) + @receiver(pre_save, sender=CustomImage) + def image_feature_detection(sender, instance, **kwargs): + if not instance.has_focal_point(): + instance.set_focal_point(instance.get_suggested_focal_point())