Skip to content
Draft
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/bandit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Security check - Bandit

on: push

jobs:
analyze:
runs-on: ubuntu-latest
permissions:
# required for all workflows
security-events: write
# only required for workflows in private repositories
actions: read
contents: read
steps:
- name: Perform Bandit Analysis
uses: PyCQA/bandit-action@v1
with:
targets: ./redturtle
30 changes: 30 additions & 0 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Black
on: [push]
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [3.11]

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-

- name: install black
run: pip install black

- name: run black
run: black redturtle/ --check --diff
30 changes: 30 additions & 0 deletions .github/workflows/flake8.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Flake8
on: [push]
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [3.11]

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-

- name: install flake8
run: pip install flake8

- name: run flake8
run: flake8 redturtle/ setup.py
10 changes: 10 additions & 0 deletions .github/workflows/isort.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Run isort
on:
- push

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: isort/isort-action@v1
30 changes: 30 additions & 0 deletions .github/workflows/pyroma.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Pyroma
on: [push]
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [3.11]

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-

- name: install pyroma
run: pip install pyroma==4.2

- name: run pyroma
run: pyroma -n 10 -d .
14 changes: 8 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ jobs:
strategy:
max-parallel: 4
matrix:
python: ["3.8"]
plone: ["52"]
# exclude:
# - python: "3.7"
# plone: "51"
python: ["3.8", "3.11"]
plone: ["52", "60"]
exclude:
- python: "3.8"
plone: "60"
- python: "3.11"
plone: "52"
steps:
- uses: actions/checkout@v4
- name: Cache eggs
Expand All @@ -26,7 +28,7 @@ jobs:
python-version: ${{ matrix.python }}
- name: Install dependencies
run: |
pip install -r requirements.txt -c constraints_plone${{ matrix.plone }}.txt
pip install -r requirements_${{ matrix.plone }}.txt
cp test_plone${{ matrix.plone }}.cfg buildout.cfg
- name: Install buildout
run: |
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/zpretty.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: zpretty
on: [push]
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [3.11]

steps:
# git checkout
- uses: actions/checkout@v4

# python setup
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

# python cache
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-

# install zpretty
- name: install zpretty
run: pip install zpretty

# run zpretty
- name: run zpretty
run: find redturtle -name '*.zcml' | xargs zpretty -i

# 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ local/
.sass-cache/
__pycache__
.python-version
pyvenv.cfg
2 changes: 2 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[settings]
profile=plone
8 changes: 8 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ Tile

In order to use layout bandi for tile is necessary have installed collective.tiles.collection product.

Behvaiors
=========

redturtle.bandi.forced_state
----------------------------

This behavior allows to set the forced state of an announcement.

plone.restapi integrations
==========================

Expand Down
2 changes: 1 addition & 1 deletion buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

# use this extend one of the buildout configuration:
extends =
test_plone52.cfg
test_plone60.cfg
1 change: 0 additions & 1 deletion constraints.txt

This file was deleted.

3 changes: 0 additions & 3 deletions constraints_plone52.txt

This file was deleted.

3 changes: 2 additions & 1 deletion redturtle/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try:
__import__('pkg_resources').declare_namespace(__name__)
__import__("pkg_resources").declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path

__path__ = extend_path(__path__, __name__)
14 changes: 0 additions & 14 deletions redturtle/bandi/Extensions/Install.py

This file was deleted.

10 changes: 6 additions & 4 deletions redturtle/bandi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Main product initializer
"""
"""Main product initializer"""

from zope.i18nmessageid import MessageFactory

import logging

logger = logging.getLogger('redturtle.bandi')
bandiMessageFactory = MessageFactory('redturtle.bandi')

logger = logging.getLogger("redturtle.bandi")
bandiMessageFactory = MessageFactory("redturtle.bandi")
_ = bandiMessageFactory
15 changes: 15 additions & 0 deletions redturtle/bandi/behaviors/configure.zcml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:plone="http://namespaces.plone.org/plone"
i18n_domain="redturtle.bandi"
>


<plone:behavior
name="redturtle.bandi.forced_state"
title="Possibilità di impostare lo stato del bando"
factory=".force.ForcedState"
provides=".force.IForcedState"
marker=".force.IForcedState"
/>
</configure>
43 changes: 43 additions & 0 deletions redturtle/bandi/behaviors/force.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from plone.autoform.interfaces import IFormFieldProvider
from plone.dexterity.interfaces import IDexterityContent
from plone.supermodel import model
from redturtle.bandi import _
from redturtle.bandi.config import STATES
from redturtle.bandi.interfaces.bando import IBando
from zope import schema
from zope.component import adapter
from zope.interface import implementer
from zope.interface import provider
from zope.schema.vocabulary import SimpleTerm
from zope.schema.vocabulary import SimpleVocabulary


@provider(IFormFieldProvider)
class IForcedState(model.Schema):
"""Marker inteerface for content type Bando"""

forced_state = schema.Choice(
title=_("stato_avanzamento_label", default="Stato di avanzamento"),
description=_(
"stato_avanzamento_help",
default=(
"Indica lo stato di avanzamento. Se il campo esiste, viene "
"utilizzato per determinare lo stato del bando. Se non esiste, "
"viene utilizzato il metodo di base per cui lo stato del bando "
"è determinato dalle date di apertura, scadenza e chiusura procedimento."
),
),
required=False,
vocabulary=SimpleVocabulary(
[SimpleTerm(state, state, STATES[state]["label"]) for state in STATES]
),
)


@implementer(IBando)
@adapter(IDexterityContent)
class ForcedState(object):
"""Bando adapter"""

def __init__(self, context):
self.context = context
14 changes: 12 additions & 2 deletions redturtle/bandi/browser/bando.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from plone.i18n.normalizer.interfaces import IIDNormalizer
from Products.Five import BrowserView
from redturtle.bandi import bandiMessageFactory as _
from redturtle.bandi.behaviors.force import IForcedState
from redturtle.bandi.config import STATES
from redturtle.bandi.interfaces import IBandoFolderDeepening
from z3c.form import field
from zope.component import getMultiAdapter
Expand All @@ -17,8 +19,8 @@


try:
from plone.restapi.serializer.utils import uid_to_url
from plone.restapi.serializer.converters import json_compatible
from plone.restapi.serializer.utils import uid_to_url

HAS_PLONERESTAPI = True
except ImportError:
Expand Down Expand Up @@ -156,7 +158,7 @@ def type_hook_link(self, brain):
# probabilmente legato al fatto che i link ora sono creati via
# api e non da interfaccia Plone (?)
if data["url"].startswith(f"/{siteid}"):
data["url"] = data["url"][len(siteid) + 1 :]
data["url"] = data["url"][len(siteid) + 1 :] # noqa: E203
if HAS_PLONERESTAPI:
data["url"] = uid_to_url(data["url"])
return data
Expand Down Expand Up @@ -252,6 +254,14 @@ def getBandoState(self):
"""
return right bando state
"""
if IForcedState.providedBy(self.context):
forced_state = getattr(self.context, "forced_state", None)
if forced_state in STATES:
return (
forced_state,
translate(STATES[forced_state]["label"], context=self.request),
)

apertura_bando = getattr(self.context, "apertura_bando", None)
scadenza_bando = getattr(self.context, "scadenza_bando", None)
chiusura_procedimento_bando = getattr(
Expand Down
2 changes: 0 additions & 2 deletions redturtle/bandi/browser/collection.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# -*- coding: utf-8 -*-
from plone import api
from Products.Five import BrowserView
from redturtle.bandi import bandiMessageFactory as _
from zope.component import getUtility
from zope.i18n import translate
from zope.interface import implementer
from zope.interface import Interface
from zope.schema.interfaces import IVocabularyFactory
Expand Down
5 changes: 2 additions & 3 deletions redturtle/bandi/browser/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@

@implementer(IContextState)
class ContextState(BaseClass):
"""modifica il metodo Folder, per poter aggiungere elementi al documento anche quando è
impostato come vista predefinita
"""modifica il metodo Folder, per poter aggiungere elementi al documento anche quando è
impostato come vista predefinita
"""

def folder(self):
if self.is_structural_folder():
return aq_inner(self.context)
else:
return self.parent()

Loading
Loading