plone.restapi/plone-only-login: Refactor @breadcrumbs view to return a single object with th

Timo Stollenwerk <jenkins-z4DKO/[email protected]>
Newsgroups gmane.comp.web.zope.plone.cvs
Message-ID <[email protected]>
Repository: plone.restapi
Branch: refs/heads/plone-only-login
Date: 2017-07-14T18:23:32+02:00
Author: Timo Stollenwerk (tisto) <[email protected]>
Commit: https://github.com/plone/plone.restapi/commit/dfc3e51f5fa01b9d30b9370988b750441e4f6630

Refactor @breadcrumbs view to return a single object with the @id attr.

Files changed:
M src/plone/restapi/services/breadcrumbs/get.py
M src/plone/restapi/tests/test_services_breadcrumbs.py

diff --git a/src/plone/restapi/services/breadcrumbs/get.py b/src/plone/restapi/services/breadcrumbs/get.py
index b8d9b97a..8bfbe701 100644
--- a/src/plone/restapi/services/breadcrumbs/get.py
+++ b/src/plone/restapi/services/breadcrumbs/get.py
@@ -8,9 +8,14 @@ class BreadcrumbsGet(Service):
     def reply(self):
         breadcrumbs_view = getMultiAdapter((self.context, self.request),
                                            name="breadcrumbs_view")
-        result = []
+        result = {
+            '@id': '{}/@breadcrumbs'.format(
+                self.context.absolute_url()
+            ),
+            'items': []
+        }
         for crumb in breadcrumbs_view.breadcrumbs():
-            result.append({
+            result['items'].append({
                 'title': crumb['Title'],
                 'url': crumb['absolute_url']
             })
diff --git a/src/plone/restapi/tests/test_services_breadcrumbs.py b/src/plone/restapi/tests/test_services_breadcrumbs.py
index 59dfc008..3f0e3fb0 100644
--- a/src/plone/restapi/tests/test_services_breadcrumbs.py
+++ b/src/plone/restapi/tests/test_services_breadcrumbs.py
@@ -41,11 +41,16 @@ def test_breadcrumbs(self):
         self.assertEqual(response.status_code, 200)
         self.assertEqual(
             response.json(),
-            [{
-                u'url': u'http://localhost:55001/plone/folder',
-                u'title': u'Some Folder'
-            }, {
-                u'url': u'http://localhost:55001/plone/folder/doc1',
-                u'title': u'A document'
-            }]
+            {
+                '@id': 'http://localhost:55001/plone/folder/doc1/@breadcrumbs',
+                'items': [
+                    {
+                        u'url': u'http://localhost:55001/plone/folder',
+                        u'title': u'Some Folder'
+                    }, {
+                        u'url': u'http://localhost:55001/plone/folder/doc1',
+                        u'title': u'A document'
+                    }
+                ]
+            }
         )



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.