diff --git a/CHANGES.rst b/CHANGES.rst index 7643ec0722..318255fd66 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -11,7 +11,8 @@ Changelog 3.6.1 (unreleased) ------------------ -- Nothing changed yet. +- Add values to vocabulary GET responses. + [Rotonen] 3.6.0 (2019-02-16) diff --git a/docs/source/vocabularies.rst b/docs/source/vocabularies.rst index 64d09a426b..fb80a55a73 100644 --- a/docs/source/vocabularies.rst +++ b/docs/source/vocabularies.rst @@ -5,7 +5,7 @@ Vocabularies are utilities containing a list of values grouped by interest or different Plone features. For example, ``plone.app.vocabularies.ReallyUserFriendlyTypes`` will return all the content types registered in Plone. The vocabularies return a list of objects with the -items ``@id``, ``title`` and ``token``. +items ``@id``, ``title``, ``token`` and ``value``. .. note:: These docs are generated by code tests, therefore you will see some 'test' contenttypes appear here. diff --git a/src/plone/restapi/serializer/vocabularies.py b/src/plone/restapi/serializer/vocabularies.py index abf26d2bda..1819df5400 100644 --- a/src/plone/restapi/serializer/vocabularies.py +++ b/src/plone/restapi/serializer/vocabularies.py @@ -43,8 +43,10 @@ def __call__(self, vocabulary_id): term = self.context token = term.token title = term.title if ITitledTokenizedTerm.providedBy(term) else token + value = term.value return { '@id': '{}/{}'.format(vocabulary_id, token), 'token': token, - 'title': title + 'title': title, + 'value': value } diff --git a/src/plone/restapi/tests/http-examples/vocabularies_get.resp b/src/plone/restapi/tests/http-examples/vocabularies_get.resp index 06ecfc17c0..ce1236c89e 100644 --- a/src/plone/restapi/tests/http-examples/vocabularies_get.resp +++ b/src/plone/restapi/tests/http-examples/vocabularies_get.resp @@ -7,62 +7,74 @@ Content-Type: application/json { "@id": "http://localhost:55001/plone/@vocabularies/plone.app.vocabularies.ReallyUserFriendlyTypes/Collection", "title": "Collection", - "token": "Collection" + "token": "Collection", + "value": "Collection" }, { "@id": "http://localhost:55001/plone/@vocabularies/plone.app.vocabularies.ReallyUserFriendlyTypes/Discussion Item", "title": "Comment", - "token": "Discussion Item" + "token": "Discussion Item", + "value": "Discussion Item" }, { "@id": "http://localhost:55001/plone/@vocabularies/plone.app.vocabularies.ReallyUserFriendlyTypes/DXTestDocument", "title": "DX Test Document", - "token": "DXTestDocument" + "token": "DXTestDocument", + "value": "DXTestDocument" }, { "@id": "http://localhost:55001/plone/@vocabularies/plone.app.vocabularies.ReallyUserFriendlyTypes/Event", "title": "Event", - "token": "Event" + "token": "Event", + "value": "Event" }, { "@id": "http://localhost:55001/plone/@vocabularies/plone.app.vocabularies.ReallyUserFriendlyTypes/File", "title": "File", - "token": "File" + "token": "File", + "value": "File" }, { "@id": "http://localhost:55001/plone/@vocabularies/plone.app.vocabularies.ReallyUserFriendlyTypes/Folder", "title": "Folder", - "token": "Folder" + "token": "Folder", + "value": "Folder" }, { "@id": "http://localhost:55001/plone/@vocabularies/plone.app.vocabularies.ReallyUserFriendlyTypes/Image", "title": "Image", - "token": "Image" + "token": "Image", + "value": "Image" }, { "@id": "http://localhost:55001/plone/@vocabularies/plone.app.vocabularies.ReallyUserFriendlyTypes/Link", "title": "Link", - "token": "Link" + "token": "Link", + "value": "Link" }, { "@id": "http://localhost:55001/plone/@vocabularies/plone.app.vocabularies.ReallyUserFriendlyTypes/News Item", "title": "News Item", - "token": "News Item" + "token": "News Item", + "value": "News Item" }, { "@id": "http://localhost:55001/plone/@vocabularies/plone.app.vocabularies.ReallyUserFriendlyTypes/Document", "title": "Page", - "token": "Document" + "token": "Document", + "value": "Document" }, { "@id": "http://localhost:55001/plone/@vocabularies/plone.app.vocabularies.ReallyUserFriendlyTypes/ATTestDocument", "title": "Test Document", - "token": "ATTestDocument" + "token": "ATTestDocument", + "value": "ATTestDocument" }, { "@id": "http://localhost:55001/plone/@vocabularies/plone.app.vocabularies.ReallyUserFriendlyTypes/ATTestFolder", "title": "Test Folder", - "token": "ATTestFolder" + "token": "ATTestFolder", + "value": "ATTestFolder" } ] } \ No newline at end of file diff --git a/src/plone/restapi/tests/test_services_vocabularies.py b/src/plone/restapi/tests/test_services_vocabularies.py index 25b6cf6506..a1190b9cb2 100644 --- a/src/plone/restapi/tests/test_services_vocabularies.py +++ b/src/plone/restapi/tests/test_services_vocabularies.py @@ -66,10 +66,12 @@ def test_get_vocabulary(self): u'terms': [ {u'@id': self.portal_url + u'/@vocabularies/plone.restapi.tests.test_vocabulary/token1', # noqa u'title': u'Title 1', - u'token': u'token1'}, + u'token': u'token1', + u'value': 42}, {u'@id': self.portal_url + u'/@vocabularies/plone.restapi.tests.test_vocabulary/token2', # noqa u'title': u'Title 2', - u'token': u'token2'}]}) + u'token': u'token2', + u'value': 43}]}) def test_get_unknown_vocabulary(self): response = self.api_session.get( @@ -132,10 +134,12 @@ def test_context_vocabulary(self): u'terms': [ {u'@id': self.portal_url + u'/testdoc/@vocabularies/plone.restapi.tests.test_context_vocabulary/id', # noqa u'title': u'testdoc', - u'token': u'id'}, + u'token': u'id', + u'value': u'testdoc'}, {u'@id': self.portal_url + u'/testdoc/@vocabularies/plone.restapi.tests.test_context_vocabulary/title', # noqa u'title': u'Document 1', - u'token': u'title'}] + u'token': u'title', + u'value': u'Document 1'}] }) def tearDown(self):