diff --git a/docs/topics/media-pipeline.rst b/docs/topics/media-pipeline.rst index 3da243d29..2b41a4f43 100644 --- a/docs/topics/media-pipeline.rst +++ b/docs/topics/media-pipeline.rst @@ -191,6 +191,10 @@ For the Images Pipeline, set :setting:`IMAGES_URLS_FIELD` and/or If you need something more complex and want to override the custom pipeline behaviour, see :ref:`topics-media-pipeline-override`. +.. note:: If you have multiple image pipelines and you want to have different settings in different pipelines + you can either set class attributes in pipeline object or add custom settings keys and load them at pipeline + initialization. + Additional features =================== diff --git a/tests/test_pipeline_images.py b/tests/test_pipeline_images.py index 3ce138000..49257e175 100644 --- a/tests/test_pipeline_images.py +++ b/tests/test_pipeline_images.py @@ -256,6 +256,29 @@ class ImagesPipelineTestCaseCustomSettings(unittest.TestCase): self.assertEqual(self.pipeline.thumbs, self.default_settings.get('IMAGES_THUMBS', default)) self.assertEqual(another_pipeline.thumbs, custom_thumbs) + def test_class_attrs_preserved(self): + + class UserDefinedImagePipeline(ImagesPipeline): + MIN_WIDTH = 1000 + + # If image settings are not defined values are taken from class attributes. + pipeline = UserDefinedImagePipeline.from_settings(Settings({"IMAGES_STORE": self.tempdir})) + self.assertEqual(pipeline.min_width, 1000) + + def test_class_attrs_not_preserved_if_settings_defined(self): + + class UserDefinedImagePipeline(ImagesPipeline): + MIN_WIDTH = 1000 + + settings = { + "IMAGES_STORE": self.tempdir, + "IMAGES_MIN_WIDTH": 90 + } + + # If image settings are defined they override class attributes. + pipeline = UserDefinedImagePipeline.from_settings(Settings(settings)) + self.assertEqual(pipeline.min_width, 90) + def _create_image(format, *a, **kw): buf = TemporaryFile()