Skip to content

Commit

Permalink
Added 'tipologia_bando_label' metadata. (#20)
Browse files Browse the repository at this point in the history
* Added 'tipologia_bando_label' metadata.

* Improved check on token

* added upgrade step

* reindex just the new metadata
  • Loading branch information
daniele-andreotti authored Mar 29, 2024
1 parent a7d62fe commit 8278397
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 2 deletions.
3 changes: 2 additions & 1 deletion docs/HISTORY.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Changelog
1.4.5 (unreleased)
------------------

- Nothing changed yet.
- Added "tipologia_bando_label" metadata.
[daniele]


1.4.4 (2024-02-20)
Expand Down
1 change: 1 addition & 0 deletions redturtle/bandi/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,6 @@
<adapter name="scadenza_bando" factory=".indexer.scadenza_bando" />
<adapter name="ente_bando" factory=".indexer.ente_bando" />
<adapter name="tipologia_bando" factory=".indexer.tipologia_bando" />
<adapter name="tipologia_bando_label" factory=".indexer.tipologia_bando_label" />
<adapter name="apertura_bando" factory=".indexer.apertura_bando" />
</configure>
13 changes: 13 additions & 0 deletions redturtle/bandi/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from DateTime import DateTime
from plone.indexer.decorator import indexer
from redturtle.bandi.interfaces.bando import IBando
from redturtle.bandi.vocabularies import TipologiaBandoVocabulary

# importo il datetime di python
from datetime import datetime
Expand Down Expand Up @@ -63,3 +64,15 @@ def ente_bando(object, **kw):
@indexer(IBando)
def tipologia_bando(object, **kw):
return getattr(object, "tipologia_bando", None)


@indexer(IBando)
def tipologia_bando_label(object, **kw):
if not object.tipologia_bando:
return None
vocab = TipologiaBandoVocabulary().__call__(object)
try:
vocab.getTermByToken(object.tipologia_bando)
except LookupError:
return None
return vocab.getTermByToken(object.tipologia_bando).title
1 change: 1 addition & 0 deletions redturtle/bandi/profiles/default/catalog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
<column value="destinatari_bando"/>
<column value="scadenza_bando"/>
<column value="tipologia_bando"/>
<column value="tipologia_bando_label"/>
</object>
2 changes: 1 addition & 1 deletion redturtle/bandi/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0"?>
<metadata>
<version>2101</version>
<version>2102</version>
</metadata>
16 changes: 16 additions & 0 deletions redturtle/bandi/upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,19 @@ def migrate_to_2101(context):
)
bando = brain.getObject()
bando.reindexObject(idxs=['scadenza_bando'])


def migrate_to_2102(context):
update_catalog(context)

bandi = api.content.find(portal_type="Bando")
tot_results = len(bandi)
logger.info("### Fixing {tot} Bandi ###".format(tot=tot_results))
for counter, brain in enumerate(bandi):
logger.info(
"[{counter}/{tot}] - {bando}".format(
counter=counter + 1, tot=tot_results, bando=brain.getPath()
)
)
bando = brain.getObject()
bando.reindexObject(idxs=['tipologia_bando_label'])
8 changes: 8 additions & 0 deletions redturtle/bandi/upgrades.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,12 @@
handler=".upgrades.migrate_to_2101"
profile="redturtle.bandi:default" />

<gs:upgradeStep
title="Add new metadata for tipologia_bando_label"
description=""
source="2101"
destination="2102"
handler=".upgrades.migrate_to_2102"
profile="redturtle.bandi:default" />

</configure>

0 comments on commit 8278397

Please sign in to comment.