Skip to content

Commit

Permalink
Improve is_folderish property to include Plone site and AT content types
Browse files Browse the repository at this point in the history
  • Loading branch information
sneridagh committed Nov 7, 2017
1 parent 64ea75a commit f2a7128
Show file tree
Hide file tree
Showing 20 changed files with 35 additions and 14 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Expand Up @@ -4,7 +4,8 @@ Changelog
1.0b1 (unreleased)
------------------

- Nothing changed yet.
- Improve is_folderish property to include Plone site and AT content types
[sneridagh]


1.0a23 (2017-11-07)
Expand Down
2 changes: 1 addition & 1 deletion docs/source/_json/collection.resp
Expand Up @@ -29,7 +29,7 @@ Content-Type: application/json
"exclude_from_nav": false,
"expires": null,
"id": "collection",
"is_folderish": false,
"is_folderish": false,
"item_count": 30,
"items": [
{
Expand Down
2 changes: 1 addition & 1 deletion docs/source/_json/content_get.resp
Expand Up @@ -28,7 +28,7 @@ Content-Type: application/json
"exclude_from_nav": false,
"expires": null,
"id": "my-document",
"is_folderish": false,
"is_folderish": false,
"language": "",
"layout": "document_view",
"modified": "2016-10-21T19:00:00+00:00",
Expand Down
2 changes: 1 addition & 1 deletion docs/source/_json/content_post.resp
Expand Up @@ -29,7 +29,7 @@ Location: http://localhost:55001/plone/folder/my-document
"exclude_from_nav": false,
"expires": null,
"id": "my-document",
"is_folderish": false,
"is_folderish": false,
"language": "",
"layout": "document_view",
"modified": "2016-10-21T19:00:00+00:00",
Expand Down
2 changes: 1 addition & 1 deletion docs/source/_json/document.resp
Expand Up @@ -29,7 +29,7 @@ Content-Type: application/json
"exclude_from_nav": false,
"expires": null,
"id": "front-page",
"is_folderish": false,
"is_folderish": false,
"language": "",
"layout": "document_view",
"modified": "2016-01-21T01:24:11+00:00",
Expand Down
2 changes: 1 addition & 1 deletion docs/source/_json/event.resp
Expand Up @@ -35,7 +35,7 @@ Content-Type: application/json
"exclude_from_nav": false,
"expires": null,
"id": "event",
"is_folderish": false,
"is_folderish": false,
"language": "",
"layout": "event_view",
"location": null,
Expand Down
2 changes: 1 addition & 1 deletion docs/source/_json/expansion.resp
Expand Up @@ -29,7 +29,7 @@ Content-Type: application/json
"exclude_from_nav": false,
"expires": null,
"id": "front-page",
"is_folderish": false,
"is_folderish": false,
"language": "",
"layout": "document_view",
"modified": "2016-01-21T01:24:11+00:00",
Expand Down
2 changes: 1 addition & 1 deletion docs/source/_json/expansion_expanded.resp
Expand Up @@ -35,7 +35,7 @@ Content-Type: application/json
"exclude_from_nav": false,
"expires": null,
"id": "front-page",
"is_folderish": false,
"is_folderish": false,
"language": "",
"layout": "document_view",
"modified": "2016-01-21T01:24:11+00:00",
Expand Down
2 changes: 1 addition & 1 deletion docs/source/_json/expansion_expanded_full.resp
Expand Up @@ -65,7 +65,7 @@ Content-Type: application/json
"exclude_from_nav": false,
"expires": null,
"id": "front-page",
"is_folderish": false,
"is_folderish": false,
"language": "",
"layout": "document_view",
"modified": "2016-01-21T01:24:11+00:00",
Expand Down
2 changes: 1 addition & 1 deletion docs/source/_json/file.resp
Expand Up @@ -34,7 +34,7 @@ Content-Type: application/json
"size": 74429
},
"id": "file",
"is_folderish": false,
"is_folderish": false,
"language": "",
"layout": "file_view",
"modified": "2016-01-21T05:24:11+00:00",
Expand Down
2 changes: 1 addition & 1 deletion docs/source/_json/folder.resp
Expand Up @@ -28,7 +28,7 @@ Content-Type: application/json
"exclude_from_nav": false,
"expires": null,
"id": "folder",
"is_folderish": true,
"is_folderish": true,
"items": [
{
"@id": "http://localhost:55001/plone/folder/doc1",
Expand Down
2 changes: 1 addition & 1 deletion docs/source/_json/image.resp
Expand Up @@ -73,7 +73,7 @@ Content-Type: application/json
"size": 1185,
"width": 215
},
"is_folderish": false,
"is_folderish": false,
"language": "",
"layout": "image_view",
"modified": "2016-01-21T06:24:11+00:00",
Expand Down
1 change: 1 addition & 0 deletions docs/source/_json/jwt_logged_in.resp
Expand Up @@ -13,6 +13,7 @@ Content-Type: application/json
"@id": "http://localhost:55001/plone/",
"@type": "Plone Site",
"id": "plone",
"is_folderish": true,
"items": [
{
"@id": "http://localhost:55001/plone/front-page",
Expand Down
2 changes: 1 addition & 1 deletion docs/source/_json/link.resp
Expand Up @@ -29,7 +29,7 @@ Content-Type: application/json
"exclude_from_nav": false,
"expires": null,
"id": "link",
"is_folderish": false,
"is_folderish": false,
"language": "",
"layout": "link_redirect_view",
"modified": "2016-01-21T04:24:11+00:00",
Expand Down
2 changes: 1 addition & 1 deletion docs/source/_json/newsitem.resp
Expand Up @@ -75,7 +75,7 @@ Content-Type: application/json
"width": 215
},
"image_caption": "This is an image caption.",
"is_folderish": false,
"is_folderish": false,
"language": "",
"layout": "newsitem_view",
"modified": "2016-01-21T02:24:11+00:00",
Expand Down
1 change: 1 addition & 0 deletions docs/source/_json/siteroot.resp
Expand Up @@ -13,6 +13,7 @@ Content-Type: application/json
"@id": "http://localhost:55001/plone",
"@type": "Plone Site",
"id": "plone",
"is_folderish": true,
"items": [
{
"@id": "http://localhost:55001/plone/front-page",
Expand Down
4 changes: 4 additions & 0 deletions src/plone/restapi/serializer/atcontent.py
Expand Up @@ -47,6 +47,7 @@ def __call__(self, version=None):
'review_state': self._get_workflow_state(obj),
'UID': obj.UID(),
'layout': self.context.getLayout(),
'is_folderish': False
}

# Insert expandable elements
Expand Down Expand Up @@ -88,6 +89,9 @@ def __call__(self, version=None):
folder_metadata = super(SerializeFolderToJson, self).__call__(
version=version
)

folder_metadata.update({'is_folderish': True})

query = self._build_query()

catalog = getToolByName(self.context, 'portal_catalog')
Expand Down
1 change: 1 addition & 0 deletions src/plone/restapi/serializer/site.py
Expand Up @@ -44,6 +44,7 @@ def __call__(self, version=None):
'@type': 'Plone Site',
'title': self.context.Title(),
'parent': {},
'is_folderish': True
}

# Insert expandable elements
Expand Down
8 changes: 8 additions & 0 deletions src/plone/restapi/tests/test_atcontent_serializer.py
Expand Up @@ -165,3 +165,11 @@ def test_serializer_includes_expansion(self):
obj = self.serialize(self.doc1)
self.assertIn('foo', obj['@components'])
self.assertEqual('collapsed', obj['@components']['foo'])

def test_get_is_folderish_in_folder(self):
self.portal.invokeFactory('Folder', id=u'folder')
serializer = getMultiAdapter((self.portal.folder, self.request),
ISerializeToJson)
obj = serializer()
self.assertIn('is_folderish', obj)
self.assertEquals(True, obj['is_folderish'])
5 changes: 5 additions & 0 deletions src/plone/restapi/tests/test_site_serializer.py
Expand Up @@ -30,3 +30,8 @@ def test_serializer_includes_title(self):
obj = self.serialize()
self.assertIn(u'title', obj)
self.assertEqual(u'Plone site', obj[u'title'])

def test_get_is_folderish(self):
obj = self.serialize()
self.assertIn('is_folderish', obj)
self.assertEquals(True, obj['is_folderish'])

0 comments on commit f2a7128

Please sign in to comment.