зеркало из https://github.com/mozilla/bedrock.git
15330 add animated gif support to cms (#15346)
* Add support for animated GIF processing in Wagtail with Wand * Stop sending the BedrockImage object instance into the task queue Instead, just send its ID and then pluck the model from the DB as part of the task
This commit is contained in:
Родитель
0945bba064
Коммит
8401aa5e1d
|
@ -68,7 +68,7 @@ EXPOSE 8000
|
|||
CMD ["./bin/run.sh"]
|
||||
|
||||
COPY docker/bin/apt-install /usr/local/bin/
|
||||
RUN apt-install gettext libxslt1.1 git curl sqlite3
|
||||
RUN apt-install gettext libxslt1.1 git curl sqlite3 libmagickwand-dev
|
||||
|
||||
# copy in Python environment
|
||||
COPY --from=python-builder /venv /venv
|
||||
|
|
|
@ -22,6 +22,11 @@ AUTOMATIC_RENDITION_FILTER_SPECS = [
|
|||
]
|
||||
|
||||
|
||||
def _make_renditions(image_id, filter_specs):
|
||||
image = BedrockImage.objects.get(id=image_id)
|
||||
image.get_renditions(*filter_specs)
|
||||
|
||||
|
||||
class BedrockImage(AbstractImage):
|
||||
"""
|
||||
Custom image model from which we can hang extra methods, such as the one that
|
||||
|
@ -64,9 +69,12 @@ class BedrockImage(AbstractImage):
|
|||
# If a background worker queue is available, this call will use it
|
||||
# to generate renditions, else it will immediately generate them
|
||||
defer_task(
|
||||
self.get_renditions,
|
||||
_make_renditions,
|
||||
queue_name="image_renditions",
|
||||
func_args=AUTOMATIC_RENDITION_FILTER_SPECS,
|
||||
func_kwargs={
|
||||
"image_id": self.id,
|
||||
"filter_specs": AUTOMATIC_RENDITION_FILTER_SPECS,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -6,7 +6,11 @@ from unittest.mock import Mock, patch
|
|||
|
||||
from django.test import TestCase, override_settings
|
||||
|
||||
from bedrock.cms.models.images import BedrockImage
|
||||
import pytest
|
||||
|
||||
from bedrock.cms.models.images import BedrockImage, _make_renditions
|
||||
|
||||
pytestmark = [pytest.mark.django_db]
|
||||
|
||||
|
||||
class BedrockImageTestCase(TestCase):
|
||||
|
@ -30,9 +34,9 @@ class BedrockImageTestCase(TestCase):
|
|||
"max-165x165",
|
||||
]
|
||||
|
||||
with patch.object(image, "get_renditions") as get_renditions_mock:
|
||||
with patch("bedrock.cms.models.images._make_renditions") as _make_renditions_mock:
|
||||
image._pre_generate_expected_renditions()
|
||||
get_renditions_mock.assert_called_once_with(*expected_filter_specs)
|
||||
_make_renditions_mock.assert_called_once_with(image_id=image.id, filter_specs=expected_filter_specs)
|
||||
|
||||
@override_settings(TASK_QUEUE_AVAILABLE=True)
|
||||
def test_pre_generate_expected_renditions__queue_available(self):
|
||||
|
@ -62,8 +66,9 @@ class BedrockImageTestCase(TestCase):
|
|||
|
||||
mock_django_rq.get_queue.assert_called_once_with("image_renditions")
|
||||
mock_queue.enqueue.assert_called_once_with(
|
||||
image.get_renditions,
|
||||
*expected_filter_specs,
|
||||
_make_renditions,
|
||||
image_id=image.id,
|
||||
filter_specs=expected_filter_specs,
|
||||
)
|
||||
|
||||
def test_pre_generate_expected_renditions_uses_defer_task(self):
|
||||
|
@ -87,9 +92,12 @@ class BedrockImageTestCase(TestCase):
|
|||
with patch("bedrock.cms.models.images.defer_task") as mock_defer_task:
|
||||
image._pre_generate_expected_renditions()
|
||||
mock_defer_task.assert_called_once_with(
|
||||
image.get_renditions,
|
||||
_make_renditions,
|
||||
queue_name="image_renditions",
|
||||
func_args=expected_filter_specs,
|
||||
func_kwargs={
|
||||
"image_id": image.id,
|
||||
"filter_specs": expected_filter_specs,
|
||||
},
|
||||
)
|
||||
|
||||
def test_pre_generate_expected_renditions_called_on_save(self):
|
||||
|
|
|
@ -2299,6 +2299,10 @@ wagtail-localize-smartling==0.3.0 \
|
|||
wagtaildraftsharing @ https://github.com/mozmeao/wagtaildraftsharing/archive/refs/tags/mozmeao-0.1.1.tar.gz#egg=wagtaildraftsharing \
|
||||
--hash=sha256:606c45c305dda042f8d058ef49d789cab5cced4c6905adebb82620e8ebbcf1cd
|
||||
# via -r requirements/prod.txt
|
||||
wand==0.6.13 \
|
||||
--hash=sha256:e5dda0ac2204a40c29ef5c4cb310770c95d3d05c37b1379e69c94ea79d7d19c0 \
|
||||
--hash=sha256:f5013484eaf7a20eb22d1821aaefe60b50cc329722372b5f8565d46d4aaafcca
|
||||
# via -r requirements/prod.txt
|
||||
wcwidth==0.2.13 \
|
||||
--hash=sha256:3da69048e4540d84af32131829ff948f1e022c1c6bdb8d6102117aac784f6859 \
|
||||
--hash=sha256:72ea0c06399eb286d978fdedb6923a9eb47e1c486ce63e9b4e64fc18303972b5
|
||||
|
|
|
@ -59,5 +59,6 @@ timeago==1.0.16
|
|||
https://github.com/mozmeao/wagtaildraftsharing/archive/refs/tags/mozmeao-0.1.1.tar.gz#egg=wagtaildraftsharing
|
||||
wagtail-localize-smartling==0.3.0
|
||||
wagtail-localize==1.10
|
||||
Wand==0.6.13 # For animated GIF support
|
||||
Wagtail==6.1.3
|
||||
whitenoise==6.7.0
|
||||
|
|
|
@ -1640,6 +1640,10 @@ wagtail-localize-smartling==0.3.0 \
|
|||
wagtaildraftsharing @ https://github.com/mozmeao/wagtaildraftsharing/archive/refs/tags/mozmeao-0.1.1.tar.gz#egg=wagtaildraftsharing \
|
||||
--hash=sha256:606c45c305dda042f8d058ef49d789cab5cced4c6905adebb82620e8ebbcf1cd
|
||||
# via -r requirements/prod.in
|
||||
wand==0.6.13 \
|
||||
--hash=sha256:e5dda0ac2204a40c29ef5c4cb310770c95d3d05c37b1379e69c94ea79d7d19c0 \
|
||||
--hash=sha256:f5013484eaf7a20eb22d1821aaefe60b50cc329722372b5f8565d46d4aaafcca
|
||||
# via -r requirements/prod.in
|
||||
webencodings==0.5.1 \
|
||||
--hash=sha256:a0af1213f3c2226497a97e2b3aa01a7e4bee4f403f95be16fc9acd2947514a78 \
|
||||
--hash=sha256:b36a1c245f2d304965eb4e0a82848379241dc04b865afcc4aab16748587e1923
|
||||
|
|
Загрузка…
Ссылка в новой задаче