Skip to content

Commit

Permalink
enable reference also a UO in Servizio
Browse files Browse the repository at this point in the history
  • Loading branch information
cekk committed Oct 16, 2024
1 parent bb9bdef commit 6ddc981
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.coverage
.coverage.*
.python-version
*.egg-info
*.log
*.mo
Expand Down
8 changes: 6 additions & 2 deletions src/iosanita/contenttypes/interfaces/servizio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -151,7 +155,7 @@ class IServizio(model.Schema, IIosanitaContenttypes):
RelatedItemsFieldWidget,
vocabulary="plone.app.vocabularies.Catalog",
pattern_options={
"selectableTypes": ["Struttura"],
"selectableTypes": ["Struttura", "UnitaOrganizzativa"],
},
)
form.widget(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(
Expand All @@ -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}

Expand All @@ -96,7 +101,7 @@ def __call__(self):
""" """
return {
"back-references": self.get_back_references(
reference_id="struttura_correlata"
reference_id=["struttura_correlata"]
)
}

Expand All @@ -107,24 +112,26 @@ 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"]
)
}


@implementer(IoSanitaViewExtraData)
@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"]
),
}
)
Expand Down

0 comments on commit 6ddc981

Please sign in to comment.