From fe317565c7540968d3316ed9ffc0bc808a343966 Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Fri, 28 Feb 2025 17:48:34 +0100 Subject: [PATCH 1/5] Add Bando serializer to return bando_state and approfondimento --- CHANGES.rst | 3 +- .../contenttypes/restapi/serializers/bando.py | 36 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/iosanita/contenttypes/restapi/serializers/bando.py diff --git a/CHANGES.rst b/CHANGES.rst index 891f016..d6f44d1 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,7 +5,8 @@ Changelog 1.0.5 (unreleased) ------------------ -- Nothing changed yet. +- Add Bando serializer to return bando_state and approfondimento. + [cekk] 1.0.4 (2024-11-22) diff --git a/src/iosanita/contenttypes/restapi/serializers/bando.py b/src/iosanita/contenttypes/restapi/serializers/bando.py new file mode 100644 index 0000000..14f98b7 --- /dev/null +++ b/src/iosanita/contenttypes/restapi/serializers/bando.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +from plone.restapi.serializer.dxcontent import SerializeFolderToJson +from redturtle.bandi.interfaces.bandoSchema import IBandoSchema +from plone.restapi.interfaces import ISerializeToJson +from zope.component import adapter +from zope.interface import implementer +from zope.interface import Interface + + +@implementer(ISerializeToJson) +@adapter(IBandoSchema, Interface) +class BandoSerializer(SerializeFolderToJson): + def get_approfondimenti(self, bando_view): + """ """ + folders = bando_view.retrieveFolderDeepening() + results = [] + + for folder in folders: + contents = bando_view.retrieveContentsOfFolderDeepening(folder["path"]) + if not contents: + continue + # fix results for enhancedlinks + for content in contents: + content["getObjSize"] = content.get("filesize", "") + content["mime_type"] = content.get("content-type", "") + content["enhanced_links_enabled"] = "filesize" in content + folder.update({"children": contents}) + results.append(folder) + return results + + def __call__(self, version=None, include_items=True): + result = super().__call__(version=version, include_items=include_items) + bando_view = self.context.restrictedTraverse("bando_view") + result["approfondimento"] = self.get_approfondimenti(bando_view) + result["bando_state"] = bando_view.getBandoState() + return result From 2c1ddd3e8c2f1634d4c6eb7995c937b5f93fbac0 Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Fri, 28 Feb 2025 17:59:30 +0100 Subject: [PATCH 2/5] fix ytpo --- src/iosanita/contenttypes/restapi/serializers/bando.py | 2 +- src/iosanita/contenttypes/restapi/serializers/configure.zcml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/iosanita/contenttypes/restapi/serializers/bando.py b/src/iosanita/contenttypes/restapi/serializers/bando.py index 14f98b7..3f696fb 100644 --- a/src/iosanita/contenttypes/restapi/serializers/bando.py +++ b/src/iosanita/contenttypes/restapi/serializers/bando.py @@ -9,7 +9,7 @@ @implementer(ISerializeToJson) @adapter(IBandoSchema, Interface) -class BandoSerializer(SerializeFolderToJson): +class BandoSerializeToJson(SerializeFolderToJson): def get_approfondimenti(self, bando_view): """ """ folders = bando_view.retrieveFolderDeepening() diff --git a/src/iosanita/contenttypes/restapi/serializers/configure.zcml b/src/iosanita/contenttypes/restapi/serializers/configure.zcml index b78cd47..e3d6916 100644 --- a/src/iosanita/contenttypes/restapi/serializers/configure.zcml +++ b/src/iosanita/contenttypes/restapi/serializers/configure.zcml @@ -2,7 +2,7 @@ xmlns="http://namespaces.zope.org/zope" xmlns:zcml="http://namespaces.zope.org/zcml" > - + From 8bf82d23d2b8ef67d7c4a47d33152278411a9025 Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Mon, 3 Mar 2025 15:52:24 +0100 Subject: [PATCH 3/5] code cleanup --- setup.cfg | 19 ++++++------------- .../contenttypes/restapi/serializers/bando.py | 2 +- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/setup.cfg b/setup.cfg index bd9250c..c726a5e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -15,17 +15,10 @@ line_length = 200 not_skip = __init__.py [flake8] -# black compatible flake8 rules: -ignore = - W503, - C812, - E501 - T001 - C813 -# E203, E266 exclude = bootstrap.py,docs,*.egg.,omelette -max-line-length = 88 -max-complexity = 18 -select = B,C,E,F,W,T4,B9 -builtins = unicode,basestring - +max-complexity = 15 +max-line-length = 100000 +extend-ignore = + E203, + C901, + C101 diff --git a/src/iosanita/contenttypes/restapi/serializers/bando.py b/src/iosanita/contenttypes/restapi/serializers/bando.py index 3f696fb..33949fe 100644 --- a/src/iosanita/contenttypes/restapi/serializers/bando.py +++ b/src/iosanita/contenttypes/restapi/serializers/bando.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- +from plone.restapi.interfaces import ISerializeToJson from plone.restapi.serializer.dxcontent import SerializeFolderToJson from redturtle.bandi.interfaces.bandoSchema import IBandoSchema -from plone.restapi.interfaces import ISerializeToJson from zope.component import adapter from zope.interface import implementer from zope.interface import Interface From 8129de752d642f5e8f95bc1814698ea56dbdd1cd Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Mon, 3 Mar 2025 15:54:10 +0100 Subject: [PATCH 4/5] use actions/cache@v4 --- .github/workflows/flake8.yml | 2 +- .github/workflows/pyroma.yml | 2 +- .github/workflows/tests.yml | 6 +++--- .github/workflows/zpretty.yml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/flake8.yml b/.github/workflows/flake8.yml index 29fa34b..fad8f11 100644 --- a/.github/workflows/flake8.yml +++ b/.github/workflows/flake8.yml @@ -19,7 +19,7 @@ jobs: python-version: ${{ matrix.python-version }} # python cache - - uses: actions/cache@v1 + - uses: actions/cache@v4 with: path: ~/.cache/pip key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} diff --git a/.github/workflows/pyroma.yml b/.github/workflows/pyroma.yml index 81bd325..6f64267 100644 --- a/.github/workflows/pyroma.yml +++ b/.github/workflows/pyroma.yml @@ -19,7 +19,7 @@ jobs: python-version: ${{ matrix.python-version }} # python cache - - uses: actions/cache@v1 + - uses: actions/cache@v4 with: path: ~/.cache/pip key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a3469b9..60e7104 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -3,8 +3,8 @@ name: Tests on: push: paths-ignore: - - '**.md' - - '**.rst' + - "**.md" + - "**.rst" jobs: build: runs-on: ubuntu-latest @@ -16,7 +16,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Cache eggs - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: eggs key: ${{ runner.OS }}-build-python${{ matrix.python }}-${{ matrix.plone }} diff --git a/.github/workflows/zpretty.yml b/.github/workflows/zpretty.yml index 23a03bb..9f3117b 100644 --- a/.github/workflows/zpretty.yml +++ b/.github/workflows/zpretty.yml @@ -19,7 +19,7 @@ jobs: python-version: ${{ matrix.python-version }} # python cache - - uses: actions/cache@v1 + - uses: actions/cache@v4 with: path: ~/.cache/pip key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} @@ -37,4 +37,4 @@ jobs: # XXX: this doesn't work on gh actions (https://github.com/plone/plone.restapi/pull/1119/checks?check_run_id=2686474411) # run git diff - name: run git diff - run: git diff --exit-code \ No newline at end of file + run: git diff --exit-code From 6693007558c2bf8d39541231341acf97b498970b Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Mon, 3 Mar 2025 15:55:20 +0100 Subject: [PATCH 5/5] use actions/cache@v4 --- .github/workflows/zpretty.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/zpretty.yml b/.github/workflows/zpretty.yml index 9f3117b..99de6a8 100644 --- a/.github/workflows/zpretty.yml +++ b/.github/workflows/zpretty.yml @@ -6,7 +6,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: [3.8] + python-version: [3.11] steps: # git checkout