From bf1ce583057b651c31b19625372fae4489be1f77 Mon Sep 17 00:00:00 2001 From: Matthew Wilkes Date: Fri, 29 Mar 2019 15:35:31 +0000 Subject: [PATCH] Add new `connections` attribute to Places JSON This adds a JSON marshalling adapter for Connections and includes the connections children in the marshalling of a place. --- .../browser/adapters/configure.zcml | 4 +++ .../browser/adapters/connection.py | 32 +++++++++++++++++++ .../PleiadesEntity/browser/adapters/place.py | 2 ++ 3 files changed, 38 insertions(+) create mode 100644 Products/PleiadesEntity/browser/adapters/connection.py diff --git a/Products/PleiadesEntity/browser/adapters/configure.zcml b/Products/PleiadesEntity/browser/adapters/configure.zcml index 2e84a914..c204805c 100644 --- a/Products/PleiadesEntity/browser/adapters/configure.zcml +++ b/Products/PleiadesEntity/browser/adapters/configure.zcml @@ -4,6 +4,10 @@ i18n_domain="Products.PleiadesEntity" > + + diff --git a/Products/PleiadesEntity/browser/adapters/connection.py b/Products/PleiadesEntity/browser/adapters/connection.py new file mode 100644 index 00000000..e5614aab --- /dev/null +++ b/Products/PleiadesEntity/browser/adapters/connection.py @@ -0,0 +1,32 @@ +from Products.PleiadesEntity.time import to_ad +from . import ContentExportAdapter +from . import PlaceSubObjectExportAdapter +from . import TemporalExportAdapter +from . import WorkExportAdapter +from . import archetypes_getter +from . import get_export_adapter +from . import memoize_all_methods + + +@memoize_all_methods +class ConnectionExportAdapter( + ContentExportAdapter, + WorkExportAdapter, + TemporalExportAdapter, + PlaceSubObjectExportAdapter): + + associationCertainty = archetypes_getter('associationCertainty') + details = archetypes_getter('text') + + connectionType = archetypes_getter('relationshipType') + + def connectionTypeURI(self): + return "{}/relationship-types/{}".format( + self.context.restrictedTraverse('vocabularies').aq_inner.absolute_url(), + self.context.getRelationshipType() + ) + + def connectsTo(self): + target = self.context.getConnection() + adapter = get_export_adapter(target) + return adapter.uri() diff --git a/Products/PleiadesEntity/browser/adapters/place.py b/Products/PleiadesEntity/browser/adapters/place.py index fef8b501..f355141e 100644 --- a/Products/PleiadesEntity/browser/adapters/place.py +++ b/Products/PleiadesEntity/browser/adapters/place.py @@ -27,6 +27,8 @@ def connectsWith(self): for id in (self._connectsWith() + self._hasConnectionsWith()) ] + connections = export_children('Connection') + def reprPoint(self): value = self.brain.reprPt if not value: