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..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 @@ -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 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/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 new file mode 100644 index 0000000..33949fe --- /dev/null +++ b/src/iosanita/contenttypes/restapi/serializers/bando.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +from plone.restapi.interfaces import ISerializeToJson +from plone.restapi.serializer.dxcontent import SerializeFolderToJson +from redturtle.bandi.interfaces.bandoSchema import IBandoSchema +from zope.component import adapter +from zope.interface import implementer +from zope.interface import Interface + + +@implementer(ISerializeToJson) +@adapter(IBandoSchema, Interface) +class BandoSerializeToJson(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 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" > - +