Skip to content

Commit

Permalink
Merge 5915022 into 6289a71
Browse files Browse the repository at this point in the history
  • Loading branch information
David Glick committed Apr 20, 2019
2 parents 6289a71 + 5915022 commit 0400d9a
Show file tree
Hide file tree
Showing 19 changed files with 334 additions and 278 deletions.
41 changes: 41 additions & 0 deletions CHANGES.rst
@@ -1,6 +1,47 @@
Changelog
=========

3.0.0 (unreleased)
------------------

Breaking Changes:

- `@vocabularies` service:

- No longer returns an ``@id`` for terms.
- Results are batched, and terms are now listed as ``items``
instead of ``terms`` to match other batched responses.
Batch size is 25 by default but can be overridden
using the ``b_size`` parameter.

[davisagli]

- `@types` service:

- Choice fields using named vocabularies are now serialized
with a ``vocabulary`` property giving the URL of the ``@vocabularies``
endpoint for the vocabulary instead of including ``choices``,
``enum`` and ``enumNames`` inline.
- The ``subjects`` field is now serialized as an ``array``
of ``string`` items using the ``plone.app.vocabularies.Keywords`` vocabulary.
[davisagli]
- Serialize widget parameters into a ``widgetOptions`` object
instead of adding them to the top level of the schema property.

[davisagli]

New Features:

- ``@vocabularies`` service: Use ``q`` parameter to filter terms by title
(case-insensitive).
[davisagli]

Bugfixes:

- Avoid calculating batch links for catalog results twice.
[davisagli]


.. You should *NOT* be adding new change log entries to this file.
You should create a file in the news directory instead.
For helpful instructions, please see:
Expand Down
3 changes: 3 additions & 0 deletions docs/source/_json/vocabularies_get_filtered.req
@@ -0,0 +1,3 @@
GET /plone/@vocabularies/plone.app.vocabularies.ReallyUserFriendlyTypes?q=doc HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0
17 changes: 17 additions & 0 deletions docs/source/_json/vocabularies_get_filtered.resp
@@ -0,0 +1,17 @@
HTTP/1.1 200 OK
Content-Type: application/json

{
"@id": "http://localhost:55001/plone/@vocabularies/plone.app.vocabularies.ReallyUserFriendlyTypes?q=doc",
"items": [
{
"title": "DX Test Document",
"token": "DXTestDocument"
},
{
"title": "Test Document",
"token": "ATTestDocument"
}
],
"items_total": 2
}
23 changes: 19 additions & 4 deletions docs/source/vocabularies.rst
Expand Up @@ -27,16 +27,31 @@ vocabularies in Plone.
Get a vocabulary
----------------

To get a particular vocabulary, ``/@vocabularies`` endpoint
To get a particular vocabulary, use the ``/@vocabularies`` endpoint
with the name of the vocabulary, e.g.
``/plone/@vocabularies/plone.app.vocabularies.ReallyUserFriendlyTypes``. The
endpoint can be used with the site root and content objects. The right way is
depending on the implementation of the vocabulary.
endpoint can be used with the site root and content objects.

.. http:example:: curl httpie python-requests
:request: ../../src/plone/restapi/tests/http-examples/vocabularies_get.req

The server will respond with a list of terms. The title is pureley for display purposes. The token is what should be send to the server to retrive the value of the term.
The server will respond with a list of terms. The title is purely for display purposes.
The token is what should be sent to the server to retrieve the value of the term.

.. note::
Vocabulary terms will be **batched** if the size of the
resultset exceeds the batch size. See :doc:`/batching` for more
details on how to work with batched results.

.. literalinclude:: ../../src/plone/restapi/tests/http-examples/vocabularies_get.resp
:language: http

Vocabulary terms can be filtered using a ``q`` parameter
to return only terms with a title that contains the specified text
(case insensitive).

.. http:example:: curl httpie python-requests
:request: _json/vocabularies_get_filtered.req

.. literalinclude:: _json/vocabularies_get_filtered.resp
:language: http
5 changes: 3 additions & 2 deletions src/plone/restapi/serializer/catalog.py
Expand Up @@ -77,8 +77,9 @@ def __call__(self, metadata_fields=(), fullobjects=False):
results = {}
results['@id'] = batch.canonical_url
results['items_total'] = batch.items_total
if batch.links:
results['batching'] = batch.links
links = batch.links
if links:
results['batching'] = links

results['items'] = []
for brain in batch:
Expand Down
29 changes: 22 additions & 7 deletions src/plone/restapi/serializer/vocabularies.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from plone.restapi.batching import HypermediaBatch
from plone.restapi.interfaces import ISerializeToJson
from zope.component import adapter
from zope.component import getMultiAdapter
Expand All @@ -19,16 +20,31 @@ def __init__(self, context, request):

def __call__(self, vocabulary_id):
vocabulary = self.context
serialized_terms = []
query = self.request.form.get('q', '')

terms = []
for term in vocabulary:
if query.lower() not in term.title.lower():
continue
terms.append(term)

batch = HypermediaBatch(self.request, terms)

serialized_terms = []
for term in batch:
serializer = getMultiAdapter((term, self.request),
interface=ISerializeToJson)
serialized_terms.append(serializer(vocabulary_id))
serialized_terms.append(serializer())

return {
'@id': vocabulary_id,
'terms': serialized_terms
result = {
'@id': batch.canonical_url,
'items': serialized_terms,
'items_total': batch.items_total,
}
links = batch.links
if links:
result['batching'] = links
return result


@implementer(ISerializeToJson)
Expand All @@ -39,12 +55,11 @@ def __init__(self, context, request):
self.context = context
self.request = request

def __call__(self, vocabulary_id):
def __call__(self):
term = self.context
token = term.token
title = term.title if ITitledTokenizedTerm.providedBy(term) else token
return {
'@id': '{}/{}'.format(vocabulary_id, token),
'token': token,
'title': title
}
21 changes: 2 additions & 19 deletions src/plone/restapi/tests/http-examples/controlpanels_get_item.resp
Expand Up @@ -48,28 +48,11 @@ Content-Type: application/json
"uniqueItems": false
},
"default_editor": {
"choices": [
[
"TinyMCE",
"TinyMCE"
],
[
"None",
"None"
]
],
"default": "TinyMCE",
"description": "Select the default wysiwyg editor. Users will be able to choose their own or select to use the site default.",
"enum": [
"TinyMCE",
"None"
],
"enumNames": [
"TinyMCE",
"None"
],
"title": "Default editor",
"type": "string"
"type": "string",
"vocabulary": "http://localhost:55001/plone/@vocabularies/plone.app.vocabularies.AvailableEditors"
},
"enable_link_integrity_checks": {
"default": true,
Expand Down
90 changes: 6 additions & 84 deletions src/plone/restapi/tests/http-examples/registry_get_list.resp
Expand Up @@ -188,12 +188,10 @@ Content-Type: application/json
],
"description": "Paths to folders and collections to link to at the portal root.",
"items": {
"choices": [],
"description": "",
"enum": [],
"enumNames": [],
"title": "",
"type": "string"
"type": "string",
"vocabulary": "http://localhost:55001/plone/@vocabularies/plone.app.vocabularies.SyndicatableFeedItems"
},
"title": "Site RSS",
"type": "array",
Expand Down Expand Up @@ -342,75 +340,10 @@ Content-Type: application/json
],
"description": "Select which formats are available for users as alternative to the default format. Note that if new formats are installed, they will be enabled for text fields by default unless explicitly turned off here or by the relevant installer.",
"items": {
"choices": [
[
"text/html",
"text/html"
],
[
"text/plain",
"text/plain"
],
[
"text/plain-pre",
"text/plain-pre"
],
[
"text/restructured",
"text/restructured"
],
[
"text/structured",
"text/structured"
],
[
"text/x-python",
"text/x-python"
],
[
"text/x-rst",
"text/x-rst"
],
[
"text/x-web-intelligent",
"text/x-web-intelligent"
],
[
"text/x-web-markdown",
"text/x-web-markdown"
],
[
"text/x-web-textile",
"text/x-web-textile"
]
],
"description": "",
"enum": [
"text/html",
"text/plain",
"text/plain-pre",
"text/restructured",
"text/structured",
"text/x-python",
"text/x-rst",
"text/x-web-intelligent",
"text/x-web-markdown",
"text/x-web-textile"
],
"enumNames": [
"text/html",
"text/plain",
"text/plain-pre",
"text/restructured",
"text/structured",
"text/x-python",
"text/x-rst",
"text/x-web-intelligent",
"text/x-web-markdown",
"text/x-web-textile"
],
"title": "",
"type": "string"
"type": "string",
"vocabulary": "http://localhost:55001/plone/@vocabularies/plone.app.vocabularies.AllowableContentTypes"
},
"title": "Alternative formats",
"type": "array",
Expand Down Expand Up @@ -462,22 +395,11 @@ Content-Type: application/json
"name": "plone.app.discussion.interfaces.IDiscussionSettings.captcha",
"schema": {
"properties": {
"choices": [
[
"disabled",
"Disabled"
]
],
"default": "disabled",
"description": "Use this setting to enable or disable Captcha validation for comments. Install plone.formwidget.captcha, plone.formwidget.recaptcha, collective.akismet, or collective.z3cform.norobots if there are no options available.",
"enum": [
"disabled"
],
"enumNames": [
"Disabled"
],
"title": "Captcha",
"type": "string"
"type": "string",
"vocabulary": "http://localhost:55001/plone/@vocabularies/plone.app.discussion.vocabularies.CaptchaVocabulary"
}
},
"value": "disabled"
Expand Down

0 comments on commit 0400d9a

Please sign in to comment.