From 4287932cefc9b4a6d901321b88c0b044330b2704 Mon Sep 17 00:00:00 2001 From: Wesley Barroso Lopes Date: Fri, 8 Mar 2024 19:28:24 -0300 Subject: [PATCH 1/2] Use the mode parameter instead of direction when calling the scale method (#1758) The direction parameter is deprecated. This avoids the warning: DeprecationWarning: The 'direction' option is deprecated, use 'mode' instead. Also change value to scale. Even though we get the warning in Plone 5.2, the tests fail when we use mode. So we keep direction in Plone 5.2. --- news/1758.bugfix | 1 + src/plone/restapi/__init__.py | 7 +++++++ src/plone/restapi/imaging.py | 14 +++++++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 news/1758.bugfix diff --git a/news/1758.bugfix b/news/1758.bugfix new file mode 100644 index 0000000000..21c323b2df --- /dev/null +++ b/news/1758.bugfix @@ -0,0 +1 @@ +Use the ``mode`` parameter instead of ``direction`` when calling the ``scale`` method. Also change value to ``scale`. @wesleybl diff --git a/src/plone/restapi/__init__.py b/src/plone/restapi/__init__.py index 5d449ae90c..c2cd6a1bb3 100644 --- a/src/plone/restapi/__init__.py +++ b/src/plone/restapi/__init__.py @@ -1,12 +1,14 @@ from . import patches # noqa: ignore=F401 from AccessControl import allow_module from AccessControl.Permissions import add_user_folders +from importlib import import_module from plone.restapi.pas import plugin from Products.PluggableAuthService.PluggableAuthService import registerMultiPlugin from zope.i18nmessageid import MessageFactory import pkg_resources + try: pkg_resources.get_distribution("plone.app.multilingual") HAS_MULTILINGUAL = True @@ -19,6 +21,11 @@ allow_module("json") +# BBB: Plone 5.2 +HAS_PLONE_6 = getattr( + import_module("Products.CMFPlone.factory"), "PLONE60MARKER", False +) + def initialize(context): registerMultiPlugin(plugin.JWTAuthenticationPlugin.meta_type) diff --git a/src/plone/restapi/imaging.py b/src/plone/restapi/imaging.py index 087ee9f32a..984fc88fa8 100644 --- a/src/plone/restapi/imaging.py +++ b/src/plone/restapi/imaging.py @@ -1,8 +1,17 @@ +from plone.restapi import HAS_PLONE_6 from zope.component import getMultiAdapter from zope.component import getUtility from zope.globalrequest import getRequest +if HAS_PLONE_6: + # In Plone 6.0+, we must use the mode parameter + scale_parameter = {"mode": "scale"} +else: + # BBB: In Plone 5.2, it is necessary to use the direction parameter. + scale_parameter = {"direction": "thumbnail"} + + def get_scales(context, field, width, height): """Get a dictionary of available scales for a particular image field, with the actual dimensions (aspect ratio of the original image). @@ -51,9 +60,8 @@ def get_original_image_url(context, fieldname, width, height): scale_flags = {} if hasattr(images_view, "picture"): scale_flags["pre"] = True - scale = images_view.scale( - fieldname, width=width, height=height, direction="thumbnail", **scale_flags - ) + parameters = {**scale_flags, **scale_parameter} + scale = images_view.scale(fieldname, width=width, height=height, **parameters) if scale: return scale.url # Corrupt images may not have a scale. From e62bea2121d929d9c35298e7e5841332bd1dcbc5 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Thu, 14 Mar 2024 17:22:37 -0400 Subject: [PATCH 2/2] Bump all the versions in GitHub workflows (#1762) * Bump all the versions in GitHub workflows * changelog * Drop flake8 to Python 3.11. Not ready for 3.12. --- .github/workflows/black.yml | 6 +++--- .github/workflows/flake8.yml | 6 +++--- .github/workflows/pyroma.yml | 6 +++--- .github/workflows/tests.yml | 8 ++++---- .github/workflows/zpretty.yml | 6 +++--- news/1762.internal | 1 + 6 files changed, 17 insertions(+), 16 deletions(-) create mode 100644 news/1762.internal diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml index a4535713e4..584b1142b8 100644 --- a/.github/workflows/black.yml +++ b/.github/workflows/black.yml @@ -7,15 +7,15 @@ jobs: strategy: fail-fast: false matrix: - python-version: [3.8] + python-version: [3.12] steps: # git checkout - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 # python setup - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} cache: pip diff --git a/.github/workflows/flake8.yml b/.github/workflows/flake8.yml index ffbf0b3b2a..554017b6f5 100644 --- a/.github/workflows/flake8.yml +++ b/.github/workflows/flake8.yml @@ -7,15 +7,15 @@ jobs: strategy: fail-fast: false matrix: - python-version: [3.8] + python-version: [3.11] steps: # git checkout - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 # python setup - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} cache: pip diff --git a/.github/workflows/pyroma.yml b/.github/workflows/pyroma.yml index bbe9d5b764..dd5196f64f 100644 --- a/.github/workflows/pyroma.yml +++ b/.github/workflows/pyroma.yml @@ -7,15 +7,15 @@ jobs: strategy: fail-fast: false matrix: - python-version: [3.8] + python-version: [3.12] steps: # git checkout - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 # python setup - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} cache: pip diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ebaa5eaa61..dd4ff01566 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -22,11 +22,11 @@ jobs: plone-version: "6.0" steps: # git checkout - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 # python setup - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} cache: "pip" @@ -54,7 +54,7 @@ jobs: # build sphinx - name: sphinx - run: if [ "${{ matrix.plone-version }}" == "6.0" ] && [ ${{ matrix.python-version }} == '3.9' ]; then make docs-html; fi + run: if [ "${{ matrix.plone-version }}" == "6.0" ] && [ ${{ matrix.python-version }} == '3.12' ]; then make docs-html; fi # test - name: test @@ -69,4 +69,4 @@ jobs: # test for broken links - name: linkcheck - run: if [ "${{ matrix.plone-version }}" == "6.0" ] && [ ${{ matrix.python-version }} == '3.9' ]; then make docs-linkcheckbroken; fi + run: if [ "${{ matrix.plone-version }}" == "6.0" ] && [ ${{ matrix.python-version }} == '3.12' ]; then make docs-linkcheckbroken; fi diff --git a/.github/workflows/zpretty.yml b/.github/workflows/zpretty.yml index 9ebafb5531..666959bde6 100644 --- a/.github/workflows/zpretty.yml +++ b/.github/workflows/zpretty.yml @@ -7,15 +7,15 @@ jobs: strategy: fail-fast: false matrix: - python-version: [3.8] + python-version: [3.12] steps: # git checkout - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 # python setup - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} cache: pip diff --git a/news/1762.internal b/news/1762.internal new file mode 100644 index 0000000000..bc36e98b70 --- /dev/null +++ b/news/1762.internal @@ -0,0 +1 @@ +Bump all the versions in GitHub workflows. @stevepiercy