def test_expansion_returns_multiple_expanded_elements(self): request = TestRequest(form={'expand': 'foo,bar'}) self.assertEqual( {'@components': { 'bar': 'expanded', 'foo': 'expanded' }}, expandable_elements(None, request))
def __call__(self, version=None): version = 'current' if version is None else version obj = self.getVersion(version) parent = aq_parent(aq_inner(obj)) parent_summary = getMultiAdapter((parent, self.request), ISerializeToJsonSummary)() result = { # '@context': 'http://www.w3.org/ns/hydra/context.jsonld', '@id': obj.absolute_url(), 'id': obj.id, '@type': obj.portal_type, 'parent': parent_summary, 'review_state': self._get_workflow_state(obj), 'UID': obj.UID(), 'layout': self.context.getLayout(), 'is_folderish': False } # Insert expandable elements result.update(expandable_elements(self.context, self.request)) for field in obj.Schema().fields(): if 'r' not in field.mode or not field.checkPermission('r', obj): continue name = field.getName() serializer = queryMultiAdapter((field, self.context, self.request), IFieldSerializer) if serializer is not None: result[name] = serializer() return result
def __call__(self, version=None): version = 'current' if version is None else version if version != 'current': return {} query = self._build_query() catalog = getToolByName(self.context, 'portal_catalog') brains = catalog(query) batch = HypermediaBatch(self.request, brains) result = { # '@context': 'http://www.w3.org/ns/hydra/context.jsonld', '@id': batch.canonical_url, 'id': self.context.id, '@type': 'Plone Site', 'title': self.context.Title(), 'parent': {}, 'is_folderish': True } # Insert expandable elements result.update(expandable_elements(self.context, self.request)) result['items_total'] = batch.items_total if batch.links: result['batching'] = batch.links result['items'] = [ getMultiAdapter((brain, self.request), ISerializeToJsonSummary)() for brain in batch ] return result
def test_expansion_returns_collapsed_elements(self): request = TestRequest() self.assertEqual( {'@components': { 'bar': 'collapsed', 'foo': 'collapsed' }}, expandable_elements(None, request))
def __call__(self, version=None, include_items=True): version = "current" if version is None else version obj = self.getVersion(version) parent = aq_parent(aq_inner(obj)) parent_summary = getMultiAdapter( (parent, self.request), ISerializeToJsonSummary )() result = { # '@context': 'http://www.w3.org/ns/hydra/context.jsonld', "@id": obj.absolute_url(), "id": obj.id, "@type": obj.portal_type, "parent": parent_summary, "created": json_compatible(obj.created()), "modified": json_compatible(obj.modified()), "review_state": self._get_workflow_state(obj), "UID": obj.UID(), "version": version, "layout": self.context.getLayout(), "is_folderish": False, } # Insert next/prev information nextprevious = NextPrevious(obj) result.update( {"previous_item": nextprevious.previous, "next_item": nextprevious.next} ) # Insert expandable elements result.update(expandable_elements(self.context, self.request)) # Insert field values for schema in iterSchemata(self.context): read_permissions = mergedTaggedValueDict(schema, READ_PERMISSIONS_KEY) for name, field in getFields(schema).items(): if not self.check_permission(read_permissions.get(name), obj): continue # serialize the field serializer = queryMultiAdapter( (field, obj, self.request), IFieldSerializer ) value = serializer() result[json_compatible(name)] = value target_url = getMultiAdapter( (self.context, self.request), IObjectPrimaryFieldTarget )() if target_url: result["targetUrl"] = target_url result["allow_discussion"] = getMultiAdapter( (self.context, self.request), name="conversation_view" ).enabled() return result
def test_expansion_returns_multiple_expanded_elements(self): request = TestRequest(form={"expand": ["foo", "bar"]}) self.assertEqual( {"@components": { "bar": "expanded", "foo": "expanded" }}, expandable_elements(None, request), )
def test_expansion_returns_collapsed_elements(self): request = TestRequest() self.assertEqual( {"@components": { "bar": "collapsed", "foo": "collapsed" }}, expandable_elements(None, request), )
def __call__(self, version=None, include_items=False): version = "current" if version is None else version obj = self.getVersion(version) parent = aq_parent(aq_inner(obj)) parent_summary = getMultiAdapter( (parent, self.request), ISerializeToJsonSummary )() result = { # '@context': 'http://www.w3.org/ns/hydra/context.jsonld', "@id": obj.absolute_url(), "id": obj.id, "@type": obj.portal_type, "parent": parent_summary, "review_state": self._get_workflow_state(obj), "UID": obj.UID(), "layout": self.context.getLayout(), "is_folderish": False, } # Insert next/prev information nextprevious = NextPrevious(obj) result.update( {"previous_item": nextprevious.previous, "next_item": nextprevious.next} ) # Insert expandable elements result.update(expandable_elements(self.context, self.request)) for field in obj.Schema().fields(): if "r" not in field.mode or not field.checkPermission( "r", obj ): # noqa: E501 continue name = field.getName() serializer = queryMultiAdapter( (field, self.context, self.request), IFieldSerializer ) if serializer is not None: result[name] = serializer() return result
def __call__(self, version=None, include_items=True): version = 'current' if version is None else version obj = self.getVersion(version) parent = aq_parent(aq_inner(obj)) parent_summary = getMultiAdapter((parent, self.request), ISerializeToJsonSummary)() result = { # '@context': 'http://www.w3.org/ns/hydra/context.jsonld', '@id': obj.absolute_url(), 'id': obj.id, '@type': obj.portal_type, 'parent': parent_summary, 'created': json_compatible(obj.created()), 'modified': json_compatible(obj.modified()), 'review_state': self._get_workflow_state(obj), 'UID': obj.UID(), 'version': version, 'layout': self.context.getLayout(), 'is_folderish': False } # Insert expandable elements result.update(expandable_elements(self.context, self.request)) # Insert field values for schema in iterSchemata(self.context): read_permissions = mergedTaggedValueDict(schema, READ_PERMISSIONS_KEY) for name, field in getFields(schema).items(): if not self.check_permission(read_permissions.get(name), obj): continue serializer = queryMultiAdapter((field, obj, self.request), IFieldSerializer) value = serializer() result[json_compatible(name)] = value result['allow_discussion'] = getMultiAdapter( (self.context, self.request), name='conversation_view').enabled() return result
def __call__(self, version=None): version = "current" if version is None else version if version != "current": return {} query = self._build_query() catalog = getToolByName(self.context, "portal_catalog") brains = catalog(query) batch = HypermediaBatch(self.request, brains) result = { # '@context': 'http://www.w3.org/ns/hydra/context.jsonld', "@id": batch.canonical_url, "id": self.context.id, "@type": "Plone Site", "title": self.context.Title(), "parent": {}, "is_folderish": True, "description": self.context.description, "blocks": json.loads(getattr(self.context, "blocks", "{}")), "blocks_layout": json.loads( getattr(self.context, "blocks_layout", "{}") ), # noqa } # Insert expandable elements result.update(expandable_elements(self.context, self.request)) result["items_total"] = batch.items_total if batch.links: result["batching"] = batch.links result["items"] = [ getMultiAdapter((brain, self.request), ISerializeToJsonSummary)() for brain in batch ] return result
def __call__(self, version=None): version = "current" if version is None else version if version != "current": return {} query = self._build_query() catalog = getToolByName(self.context, "portal_catalog") brains = catalog(query) batch = HypermediaBatch(self.request, brains) result = { # '@context': 'http://www.w3.org/ns/hydra/context.jsonld', "@id": self.context.absolute_url(), "id": self.context.id, "@type": "Plone Site", "title": self.context.Title(), "parent": {}, "is_folderish": True, "description": self.context.description, } if HAS_PLONE_6: # Insert Plone Site DX root field values for schema in iterSchemata(self.context): read_permissions = mergedTaggedValueDict( schema, READ_PERMISSIONS_KEY) for name, field in getFields(schema).items(): if not self.check_permission(read_permissions.get(name), self.context): continue # serialize the field serializer = queryMultiAdapter( (field, self.context, self.request), IFieldSerializer) value = serializer() result[json_compatible(name)] = value # Insert locking information result.update({"lock": lock_info(self.context)}) else: # Apply the fake blocks behavior in site root hack using site root properties result.update({ "blocks": self.serialize_blocks(), "blocks_layout": json.loads(getattr(self.context, "blocks_layout", "{}")), }) # Insert expandable elements result.update(expandable_elements(self.context, self.request)) result["items_total"] = batch.items_total if batch.links: result["batching"] = batch.links result["items"] = [ getMultiAdapter((brain, self.request), ISerializeToJsonSummary)() for brain in batch ] return result
def _include_components(self, obj): """ """ result = {} if self.include_all or self._get_param('include_components'): result.update(expandable_elements(self.context, self.request)) return result