diff --git a/docs/HISTORY.txt b/docs/HISTORY.txt
index 263df17..28e7e9d 100644
--- a/docs/HISTORY.txt
+++ b/docs/HISTORY.txt
@@ -4,7 +4,8 @@ Changelog
1.4.5 (unreleased)
------------------
-- Nothing changed yet.
+- Added "tipologia_bando_label" metadata.
+ [daniele]
1.4.4 (2024-02-20)
diff --git a/redturtle/bandi/configure.zcml b/redturtle/bandi/configure.zcml
index 08d366b..ae217c1 100644
--- a/redturtle/bandi/configure.zcml
+++ b/redturtle/bandi/configure.zcml
@@ -80,5 +80,6 @@
+
diff --git a/redturtle/bandi/indexer.py b/redturtle/bandi/indexer.py
index 19c20df..65755a3 100644
--- a/redturtle/bandi/indexer.py
+++ b/redturtle/bandi/indexer.py
@@ -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
@@ -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
diff --git a/redturtle/bandi/profiles/default/catalog.xml b/redturtle/bandi/profiles/default/catalog.xml
index 014479e..8905971 100644
--- a/redturtle/bandi/profiles/default/catalog.xml
+++ b/redturtle/bandi/profiles/default/catalog.xml
@@ -24,4 +24,5 @@
+
diff --git a/redturtle/bandi/profiles/default/metadata.xml b/redturtle/bandi/profiles/default/metadata.xml
index 0ad88e5..882cc6e 100644
--- a/redturtle/bandi/profiles/default/metadata.xml
+++ b/redturtle/bandi/profiles/default/metadata.xml
@@ -1,4 +1,4 @@
- 2101
+ 2102
diff --git a/redturtle/bandi/upgrades.py b/redturtle/bandi/upgrades.py
index 39d408a..9e0fc22 100644
--- a/redturtle/bandi/upgrades.py
+++ b/redturtle/bandi/upgrades.py
@@ -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'])
diff --git a/redturtle/bandi/upgrades.zcml b/redturtle/bandi/upgrades.zcml
index 8c7263e..9c32caf 100644
--- a/redturtle/bandi/upgrades.zcml
+++ b/redturtle/bandi/upgrades.zcml
@@ -59,4 +59,12 @@
handler=".upgrades.migrate_to_2101"
profile="redturtle.bandi:default" />
+
+