-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
208 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Breadcrumbs | ||
=========== | ||
|
||
Getting the breadcrumbs for the current page: | ||
|
||
.. http:example:: curl httpie python-requests | ||
:request: _json/breadcrumbs.req | ||
|
||
Example response: | ||
|
||
.. literalinclude:: _json/breadcrumbs.resp | ||
:language: http |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,8 @@ Contents | |
types | ||
users | ||
components | ||
breadcrumbs | ||
navigation | ||
serialization | ||
searching | ||
vocabularies | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Navigation | ||
========== | ||
|
||
Getting the top navigation items: | ||
|
||
.. http:example:: curl httpie python-requests | ||
:request: _json/navigation.req | ||
|
||
Example response: | ||
|
||
.. literalinclude:: _json/navigation.resp | ||
:language: http |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<configure | ||
xmlns="http://namespaces.zope.org/zope" | ||
xmlns:plone="http://namespaces.plone.org/plone"> | ||
|
||
<plone:service | ||
method="GET" | ||
for="zope.interface.Interface" | ||
factory=".get.BreadcrumbsGet" | ||
name="@breadcrumbs" | ||
permission="zope2.View" | ||
/> | ||
|
||
</configure> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# -*- coding: utf-8 -*- | ||
from plone.restapi.services import Service | ||
from zope.component import getMultiAdapter | ||
|
||
|
||
class BreadcrumbsGet(Service): | ||
|
||
def reply(self): | ||
breadcrumbs_view = getMultiAdapter((self.context, self.request), | ||
name="breadcrumbs_view") | ||
result = [] | ||
for crumb in breadcrumbs_view.breadcrumbs(): | ||
result.append({ | ||
'title': crumb['Title'], | ||
'url': crumb['absolute_url'] | ||
}) | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<configure | ||
xmlns="http://namespaces.zope.org/zope" | ||
xmlns:plone="http://namespaces.plone.org/plone"> | ||
|
||
<plone:service | ||
method="GET" | ||
for="zope.interface.Interface" | ||
factory=".get.NavigationGet" | ||
name="@navigation" | ||
permission="zope2.View" | ||
/> | ||
|
||
</configure> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# -*- coding: utf-8 -*- | ||
from plone.restapi.services import Service | ||
from zope.component import getMultiAdapter | ||
|
||
|
||
class NavigationGet(Service): | ||
|
||
def reply(self): | ||
tabs = getMultiAdapter((self.context, self.request), | ||
name="portal_tabs_view") | ||
result = [] | ||
for tab in tabs.topLevelTabs(): | ||
result.append({ | ||
'title': tab.get('title', tab.get('name')), | ||
'url': tab['url'] + '' | ||
}) | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# -*- coding: utf-8 -*- | ||
from plone.app.testing import setRoles | ||
from plone.app.testing import SITE_OWNER_NAME | ||
from plone.app.testing import SITE_OWNER_PASSWORD | ||
from plone.app.testing import TEST_USER_ID | ||
from plone.dexterity.utils import createContentInContainer | ||
from plone.restapi.testing import PLONE_RESTAPI_DX_FUNCTIONAL_TESTING | ||
from plone.restapi.testing import RelativeSession | ||
|
||
import transaction | ||
import unittest | ||
|
||
|
||
class TestServicesBreadcrumbs(unittest.TestCase): | ||
|
||
layer = PLONE_RESTAPI_DX_FUNCTIONAL_TESTING | ||
|
||
def setUp(self): | ||
self.app = self.layer['app'] | ||
self.portal = self.layer['portal'] | ||
self.portal_url = self.portal.absolute_url() | ||
setRoles(self.portal, TEST_USER_ID, ['Manager']) | ||
|
||
self.api_session = RelativeSession(self.portal_url) | ||
self.api_session.headers.update({'Accept': 'application/json'}) | ||
self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) | ||
|
||
self.folder = createContentInContainer( | ||
self.portal, u'Folder', | ||
id=u'folder', | ||
title=u'Some Folder') | ||
createContentInContainer( | ||
self.folder, u'Document', | ||
id=u'doc1', | ||
title=u'A document') | ||
transaction.commit() | ||
|
||
def test_breadcrumbs(self): | ||
response = self.api_session.get('/folder/doc1/@breadcrumbs') | ||
|
||
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' | ||
}] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# -*- coding: utf-8 -*- | ||
from plone.app.testing import setRoles | ||
from plone.app.testing import SITE_OWNER_NAME | ||
from plone.app.testing import SITE_OWNER_PASSWORD | ||
from plone.app.testing import TEST_USER_ID | ||
from plone.dexterity.utils import createContentInContainer | ||
from plone.restapi.testing import PLONE_RESTAPI_DX_FUNCTIONAL_TESTING | ||
from plone.restapi.testing import RelativeSession | ||
|
||
import transaction | ||
import unittest | ||
|
||
|
||
class TestServicesNavigation(unittest.TestCase): | ||
|
||
layer = PLONE_RESTAPI_DX_FUNCTIONAL_TESTING | ||
|
||
def setUp(self): | ||
self.app = self.layer['app'] | ||
self.portal = self.layer['portal'] | ||
self.portal_url = self.portal.absolute_url() | ||
setRoles(self.portal, TEST_USER_ID, ['Manager']) | ||
|
||
self.api_session = RelativeSession(self.portal_url) | ||
self.api_session.headers.update({'Accept': 'application/json'}) | ||
self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) | ||
|
||
self.folder = createContentInContainer( | ||
self.portal, u'Folder', | ||
id=u'folder', | ||
title=u'Some Folder') | ||
createContentInContainer( | ||
self.folder, u'Document', | ||
id=u'doc1', | ||
title=u'A document') | ||
transaction.commit() | ||
|
||
def test_navigation(self): | ||
response = self.api_session.get('/folder/@navigation') | ||
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual( | ||
response.json(), | ||
[ | ||
{ | ||
u'title': u'Home', | ||
u'url': u'http://localhost:55001/plone' | ||
}, | ||
{ | ||
u'title': u'Some Folder', | ||
u'url': u'http://localhost:55001/plone/folder' | ||
} | ||
] | ||
) |