From 6ddc981eb4f88f4bc414d2318c7564e867e3334e Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Wed, 16 Oct 2024 17:07:19 +0200 Subject: [PATCH] enable reference also a UO in Servizio --- .gitignore | 1 + .../contenttypes/interfaces/servizio.py | 8 +++-- .../services/view_extra_data/extractor.py | 35 +++++++++++-------- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 3988bfb..94e6dc9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .coverage .coverage.* +.python-version *.egg-info *.log *.mo diff --git a/src/iosanita/contenttypes/interfaces/servizio.py b/src/iosanita/contenttypes/interfaces/servizio.py index 9f8c41a..5b1ed9f 100644 --- a/src/iosanita/contenttypes/interfaces/servizio.py +++ b/src/iosanita/contenttypes/interfaces/servizio.py @@ -76,9 +76,13 @@ class IServizio(model.Schema, IIosanitaContenttypes): ) struttura_correlata = RelationList( title=_( - "struttura_correlata_label", + "struttura_correlata_servizio_label", default="Struttura di riferimento", ), + description=_( + "struttura_correlata_servizio_help", + default="Seleziona una Struttura o Unità organizzativa di riferimento.", + ), default=[], value_type=RelationChoice(vocabulary="plone.app.vocabularies.Catalog"), required=True, @@ -151,7 +155,7 @@ class IServizio(model.Schema, IIosanitaContenttypes): RelatedItemsFieldWidget, vocabulary="plone.app.vocabularies.Catalog", pattern_options={ - "selectableTypes": ["Struttura"], + "selectableTypes": ["Struttura", "UnitaOrganizzativa"], }, ) form.widget( diff --git a/src/iosanita/contenttypes/restapi/services/view_extra_data/extractor.py b/src/iosanita/contenttypes/restapi/services/view_extra_data/extractor.py index 9f2f790..97989e2 100644 --- a/src/iosanita/contenttypes/restapi/services/view_extra_data/extractor.py +++ b/src/iosanita/contenttypes/restapi/services/view_extra_data/extractor.py @@ -44,12 +44,16 @@ def get_back_references(self, reference_id): catalog = getUtility(ICatalog) intids = getUtility(IIntIds) - relations = catalog.findRelations( - { - "to_id": intids.getId(aq_inner(self.context)), - "from_attribute": reference_id, - } - ) + relations = [] + for ref_id in reference_id: + relations.extend( + catalog.findRelations( + { + "to_id": intids.getId(aq_inner(self.context)), + "from_attribute": ref_id, + } + ) + ) data = {} for rel in relations: obj = intids.queryObject(rel.from_id) @@ -62,7 +66,8 @@ def get_back_references(self, reference_id): summary = getMultiAdapter( (obj, getRequest()), ISerializeToJsonSummary )() - data[portal_type].append(summary) + if summary not in data[portal_type]: + data[portal_type].append(summary) for portal_type, values in data.items(): if portal_type == "News Item": data[portal_type] = sorted( @@ -81,10 +86,10 @@ def __call__(self): Servizio can also be referenced by a custom field """ - data = self.get_back_references(reference_id="servizio_correlato") + data = self.get_back_references(reference_id=["servizio_correlato"]) data.update( - self.get_back_references(reference_id="servizio_procedura_riferimento") + self.get_back_references(reference_id=["servizio_procedura_riferimento"]) ) return {"back-references": data} @@ -96,7 +101,7 @@ def __call__(self): """ """ return { "back-references": self.get_back_references( - reference_id="struttura_correlata" + reference_id=["struttura_correlata"] ) } @@ -107,7 +112,9 @@ class ViewExtraDataExtractorUnitaOrganizzativa(ViewExtraDataExtractor): def __call__(self): """ """ return { - "back-references": self.get_back_references(reference_id="uo_correlata") + "back-references": self.get_back_references( + reference_id=["uo_correlata", "struttura_correlata"] + ) } @@ -115,16 +122,16 @@ def __call__(self): @adapter(IPersona, Interface) class ViewExtraDataExtractorPersona(ViewExtraDataExtractor): def __call__(self): - data = self.get_back_references(reference_id="persona_correlata") + data = self.get_back_references(reference_id=["persona_correlata"]) # append additional references data.update( { "responsabile": self.get_back_references( - reference_id="responsabile_correlato" + reference_id=["responsabile_correlato"] ), "personale": self.get_back_references( - reference_id="personale_correlato" + reference_id=["personale_correlato"] ), } )