Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable reference also a UO in Servizio #9

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 6 additions & 2 deletions src/iosanita/contenttypes/interfaces/servizio.py
Original file line number Diff line number Diff line change
@@ -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(
Original file line number Diff line number Diff line change
@@ -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,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"]
),
}
)
Loading