mirror of
https://github.com/wagtail/wagtail.git
synced 2024-12-01 11:41:20 +01:00
Remove deprecation path for ImageOperation.run methods that don't accept env
This commit is contained in:
parent
6aff245474
commit
3a92774f8c
@ -1,7 +1,6 @@
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import hashlib
|
||||
import inspect
|
||||
import os.path
|
||||
import warnings
|
||||
from collections import OrderedDict
|
||||
@ -25,7 +24,7 @@ from taggit.managers import TaggableManager
|
||||
from unidecode import unidecode
|
||||
from willow.image import Image as WillowImage
|
||||
|
||||
from wagtail.utils.deprecation import RemovedInWagtail19Warning, RemovedInWagtail110Warning
|
||||
from wagtail.utils.deprecation import RemovedInWagtail110Warning
|
||||
from wagtail.wagtailadmin.utils import get_object_usage
|
||||
from wagtail.wagtailcore import hooks
|
||||
from wagtail.wagtailcore.models import CollectionMember
|
||||
@ -404,24 +403,7 @@ class Filter(models.Model):
|
||||
'original-format': original_format,
|
||||
}
|
||||
for operation in self.operations:
|
||||
# Check that the operation can take the "env" argument
|
||||
try:
|
||||
inspect.getcallargs(operation.run, willow, image, env)
|
||||
accepts_env = True
|
||||
except TypeError:
|
||||
# Check that the paramters fit the old style, so we don't
|
||||
# raise a warning if there is a coding error
|
||||
inspect.getcallargs(operation.run, willow, image)
|
||||
accepts_env = False
|
||||
warnings.warn("ImageOperation run methods should take 4 "
|
||||
"arguments. %d.run only takes 3.",
|
||||
RemovedInWagtail19Warning)
|
||||
|
||||
# Call operation
|
||||
if accepts_env:
|
||||
willow = operation.run(willow, image, env) or willow
|
||||
else:
|
||||
willow = operation.run(willow, image) or willow
|
||||
willow = operation.run(willow, image, env) or willow
|
||||
|
||||
# Find the output format to use
|
||||
if 'output-format' in env:
|
||||
|
@ -1,12 +1,9 @@
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import warnings
|
||||
|
||||
from django.test import TestCase, override_settings
|
||||
from django.utils.six import BytesIO
|
||||
from mock import Mock, patch
|
||||
|
||||
from wagtail.utils.deprecation import RemovedInWagtail19Warning
|
||||
from wagtail.wagtailcore import hooks
|
||||
from wagtail.wagtailimages import image_operations
|
||||
from wagtail.wagtailimages.exceptions import InvalidFilterSpecError
|
||||
@ -417,33 +414,6 @@ class TestFilter(TestCase):
|
||||
|
||||
self.assertEqual(run_mock.call_count, 2)
|
||||
|
||||
def test_runs_operations_without_env_argument(self):
|
||||
# The "env" argument was added in Wagtail 1.5. This tests that
|
||||
# image operations written for 1.4 will still work
|
||||
|
||||
run_mock = Mock()
|
||||
|
||||
def run(willow, image):
|
||||
run_mock(willow, image)
|
||||
|
||||
self.operation_instance.run = run
|
||||
|
||||
fil = Filter(spec='operation1|operation2')
|
||||
image = Image.objects.create(
|
||||
title="Test image",
|
||||
file=get_test_image_file(),
|
||||
)
|
||||
|
||||
with warnings.catch_warnings(record=True) as ws:
|
||||
warnings.simplefilter('always')
|
||||
|
||||
fil.run(image, BytesIO())
|
||||
|
||||
self.assertEqual(len(ws), 2)
|
||||
self.assertIs(ws[0].category, RemovedInWagtail19Warning)
|
||||
|
||||
self.assertEqual(run_mock.call_count, 2)
|
||||
|
||||
|
||||
@hooks.register('register_image_operations')
|
||||
def register_image_operations():
|
||||
|
Loading…
Reference in New Issue
Block a user