Skip to content

Commit

Permalink
refactoring for issue #28788
Browse files Browse the repository at this point in the history
  • Loading branch information
daniele-andreotti committed Nov 6, 2024
1 parent d0bd3f8 commit e60e85e
Show file tree
Hide file tree
Showing 13 changed files with 204 additions and 145 deletions.
10 changes: 9 additions & 1 deletion rer/bandi/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@
provides="Products.GenericSetup.interfaces.EXTENSION"
/>

<genericsetup:registerProfile
name="migrate_to_3200"
title="Migrate to version 3200"
directory="profiles/migrate_to_3200"
description="RER:Bandi migrate to version 3200"
provides="Products.GenericSetup.interfaces.EXTENSION"
/>

<genericsetup:importStep
name="rer.bandi"
title="RER: Bandi configuration"
Expand All @@ -88,7 +96,7 @@
<adapter name="chiusura_procedimento_bando" factory=".indexer.chiusura_procedimento_bando" />
<adapter name="scadenza_bando" factory=".indexer.scadenza_bando" />
<adapter name="tipologia_bando" factory=".indexer.tipologia_bando" />
<adapter name="finanziatori" factory=".indexer.finanziatori" />
<adapter name="finanziato" factory=".indexer.finanziato" />
<adapter name="materie" factory=".indexer.materie" />

</configure>
33 changes: 15 additions & 18 deletions rer/bandi/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,66 +13,63 @@ def dateToDatetime(d):

@indexer(IBando)
def destinatari_bando(object, **kw):
destinatari = getattr(object, 'destinatari', [])
destinatari = getattr(object, "destinatari", [])
if not destinatari:
return []
if six.PY2:
return [x.encode('utf-8') for x in destinatari]
return [x.encode("utf-8") for x in destinatari]
return destinatari


@indexer(IBando)
def chiusura_procedimento_bando(object, **kw):

date_chiusura_procedimento_bando = getattr(
object, 'chiusura_procedimento_bando', None
object, "chiusura_procedimento_bando", None
)
if date_chiusura_procedimento_bando:
datetime_chiusura_procedimento_bando = dateToDatetime(
date_chiusura_procedimento_bando
)
else:
return DateTime('2100/12/31')
return DateTime("2100/12/31")

if datetime_chiusura_procedimento_bando:
return DateTime(datetime_chiusura_procedimento_bando)


@indexer(IBando)
def scadenza_bando(object, **kw):
datetime_scadenza_bando = getattr(object, 'scadenza_bando', None)
datetime_scadenza_bando = getattr(object, "scadenza_bando", None)
if not datetime_scadenza_bando:
return DateTime('2100/12/31')
return DateTime("2100/12/31")
zope_dt_scadenza_bando = DateTime(datetime_scadenza_bando)
if zope_dt_scadenza_bando.Time() == '00:00:00':
if zope_dt_scadenza_bando.Time() == "00:00:00":
return zope_dt_scadenza_bando + 1
else:
return zope_dt_scadenza_bando


@indexer(IBando)
def tipologia_bando(object, **kw):
tipologia = getattr(object, 'tipologia_bando', '')
tipologia = getattr(object, "tipologia_bando", "")
if six.PY2:
return tipologia.encode('utf-8')
return tipologia.encode("utf-8")
return tipologia


@indexer(IBando)
def finanziatori(object, **kw):
finanziatori = getattr(object, 'finanziatori', [])
if not finanziatori:
return []
if six.PY2:
return [x.encode('utf-8') for x in finanziatori]
return finanziatori
def finanziato(object, **kw):
finanziato = getattr(object, "finanziato", [])

return finanziato


@indexer(IBando)
def materie(object, **kw):
materie = getattr(object, 'materie', [])
materie = getattr(object, "materie", [])
if not materie:
return []
if six.PY2:
return [x.encode('utf-8') for x in materie]
return [x.encode("utf-8") for x in materie]
return materie
62 changes: 28 additions & 34 deletions rer/bandi/interfaces/bandoSchema.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,78 +19,72 @@ def checkRequiredField(value):


class IBandoSchema(model.Schema):
""" A Dexterity schema for Annoucements """
"""A Dexterity schema for Annoucements"""

directives.widget(tipologia_bando=RadioFieldWidget)
tipologia_bando = schema.Choice(
title=_('tipologia_bando_label', default=u"Announcement type"),
description=_('tipologia_bando_help', default=''),
vocabulary='rer.bandi.tipologie.vocabulary',
title=_("tipologia_bando_label", default="Announcement type"),
description=_("tipologia_bando_help", default=""),
vocabulary="rer.bandi.tipologie.vocabulary",
required=True,
)

directives.widget(destinatari=CheckBoxFieldWidget)
destinatari = schema.List(
title=_('destinatari_label', default=u'Who can apply'),
title=_("destinatari_label", default="Who can apply"),
description=_(
'bandi_multiselect_help', default='Select one or more values.'
"bandi_multiselect_help", default="Select one or more values."
),
constraint=checkRequiredField,
required=True,
value_type=schema.Choice(
vocabulary='rer.bandi.destinatari.vocabulary'
vocabulary="rer.bandi.destinatari.vocabulary"
),
)

directives.widget(finanziatori=CheckBoxFieldWidget)
finanziatori = schema.List(
title=_('finanziatori_label', default=u'Financed by EU programmes'),
description=_(
'bandi_multiselect_help', default='Select one or more values.'
),
finanziato = schema.Bool(
title=_("finanziatori_label", default="Financed by EU programmes"),
description=_("", default=""),
required=False,
value_type=schema.Choice(
vocabulary='rer.bandi.finanziatori.vocabulary'
),
)

directives.widget(materie=CheckBoxFieldWidget)
materie = schema.List(
title=_('materie_label', default=u'Topic'),
title=_("materie_label", default="Topic"),
description=_(
'bandi_multiselect_help', default='Select one or more values.'
"bandi_multiselect_help", default="Select one or more values."
),
required=False,
value_type=schema.Choice(vocabulary='rer.bandi.materie.vocabulary'),
value_type=schema.Choice(vocabulary="rer.bandi.materie.vocabulary"),
)

scadenza_bando = schema.Datetime(
title=_('scadenza_bando_label', default=u"Expiration date and time"),
title=_("scadenza_bando_label", default="Expiration date and time"),
description=_(
'scadenza_bando_help',
default=u"Deadline to participate in the announcement",
"scadenza_bando_help",
default="Deadline to participate in the announcement",
),
required=False,
)
chiusura_procedimento_bando = schema.Date(
title=_(
'chiusura_procedimento_bando_label',
default=u"Closing date procedure",
"chiusura_procedimento_bando_label",
default="Closing date procedure",
),
description=_('chiusura_procedimento_bando_help', default=u''),
description=_("chiusura_procedimento_bando_help", default=""),
required=False,
)

riferimenti_bando = RichText(
title=_('riferimenti_bando_label', default=u"References"),
description=_('riferimenti_bando_help', default=u""),
title=_("riferimenti_bando_label", default="References"),
description=_("riferimenti_bando_help", default=""),
required=False,
)

form.order_after(tipologia_bando='IRichText.text')
form.order_after(destinatari='tipologia_bando')
form.order_after(finanziatori='destinatari')
form.order_after(materie='finanziatori')
form.order_after(scadenza_bando='materie')
form.order_after(chiusura_procedimento_bando='scadenza_bando')
form.order_after(riferimenti_bando='chiusura_procedimento_bando')
form.order_after(tipologia_bando="IRichText.text")
form.order_after(destinatari="tipologia_bando")
form.order_after(finanziato="destinatari")
form.order_after(materie="finanziato")
form.order_after(scadenza_bando="materie")
form.order_after(chiusura_procedimento_bando="scadenza_bando")
form.order_after(riferimenti_bando="chiusura_procedimento_bando")
4 changes: 2 additions & 2 deletions rer/bandi/profiles/default/catalog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<index name="tipologia_bando" meta_type="FieldIndex">
<indexed_attr value="tipologia_bando"/>
</index>
<index name="finanziatori" meta_type="KeywordIndex">
<indexed_attr value="finanziatori"/>
<index name="finanziato" meta_type="KeywordIndex">
<indexed_attr value="finanziato"/>
</index>
<index name="materie" meta_type="KeywordIndex">
<indexed_attr value="materie"/>
Expand Down
2 changes: 1 addition & 1 deletion rer/bandi/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<metadata>
<version>3100</version>
<version>3200</version>
<dependencies>
<dependency>profile-plone.restapi:default</dependency>
</dependencies>
Expand Down
12 changes: 5 additions & 7 deletions rer/bandi/profiles/default/registry/topic.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,15 @@
<value i18n:translate="" i18n:domain="plone" key="group">Bando</value>
</records>
<records interface="plone.app.querystring.interfaces.IQueryField"
prefix="plone.app.querystring.field.finanziatori">
prefix="plone.app.querystring.field.finanziato">
<value key="title" i18n:translate="finanziatori_label">Financed by EU programmes</value>
<value key="description"></value>
<value key="enabled">True</value>
<value key="enabled">False</value>
<value key="sortable">False</value>
<value key="operations">
<element>plone.app.querystring.operation.string.contains</element>
<element>plone.app.querystring.operation.selection.any</element>
<element>plone.app.querystring.operation.selection.all</element>
<element>plone.app.querystring.operation.boolean.isTrue</element>
<element>plone.app.querystring.operation.boolean.isFalse</element>
</value>
<value key="vocabulary">rer.bandi.finanziatori.vocabulary</value>
<value i18n:translate="" i18n:domain="plone" key="group">Bando</value>
</records>
<records interface="plone.app.querystring.interfaces.IQueryField"
Expand All @@ -102,4 +100,4 @@
<value key="vocabulary">rer.bandi.materie.vocabulary</value>
<value i18n:translate="" i18n:domain="plone" key="group">Bando</value>
</records>
</registry>
</registry>
5 changes: 5 additions & 0 deletions rer/bandi/profiles/migrate_to_3200/catalog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0"?>
<object name="portal_catalog" meta_type="Plone Catalog Tool">

<index name="fiinanziatori" remove="True" />
</object>
9 changes: 9 additions & 0 deletions rer/bandi/profiles/migrate_to_3200/registry.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<registry xmlns:i18n="http://xml.zope.org/namespaces/i18n"
i18n:domain="rer.bandi">

<records interface="plone.app.querystring.interfaces.IQueryField"
prefix="plone.app.querystring.field.finanziatori"
remove="True">
</records>

</registry>
Loading

0 comments on commit e60e85e

Please sign in to comment.