Skip to content

Commit

Permalink
Merge branch 'master' into remove-components
Browse files Browse the repository at this point in the history
  • Loading branch information
tisto committed Apr 17, 2017
2 parents 70481ec + 3b2c9e9 commit 8271e5e
Show file tree
Hide file tree
Showing 24 changed files with 63 additions and 5 deletions.
9 changes: 7 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ New Features:
and breadcrumbs as components.
[timo]

- Add support for setting/modifying 'layout' on DX and AT content endpoints.
[jaroel]

- Add support for getting the defined layouts on the root types endpoint.
[jaroel]

Bugfixes:

- Add the title to the workflow history in the @workflow endpoint. This fixes
#279.
- Add the title to the workflow history in the @workflow endpoint.
This fixes #279.
[sneridagh]

- Don't fetch unnecessary PasswordResetTool in Plone 5.1
Expand Down
1 change: 1 addition & 0 deletions docs/source/_json/collection.resp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Content-Type: application/json
],
"items_total": 3,
"language": "",
"layout": "listing_view",
"limit": 1000,
"modified": "2016-01-21T08:24:11+00:00",
"parent": {
Expand Down
1 change: 1 addition & 0 deletions docs/source/_json/content_get.resp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Content-Type: application/json
"expires": null,
"id": "my-document",
"language": "",
"layout": "document_view",
"modified": "2016-10-21T19:00:00+00:00",
"parent": {
"@id": "http://localhost:55001/plone/folder",
Expand Down
1 change: 1 addition & 0 deletions docs/source/_json/content_post.resp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Location: http://localhost:55001/plone/folder/my-document
"expires": null,
"id": "my-document",
"language": "",
"layout": "document_view",
"modified": "2016-10-21T19:00:00+00:00",
"parent": {
"@id": "http://localhost:55001/plone/folder",
Expand Down
1 change: 1 addition & 0 deletions docs/source/_json/document.resp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Content-Type: application/json
"expires": null,
"id": "front-page",
"language": "",
"layout": "document_view",
"modified": "2016-01-21T01:24:11+00:00",
"parent": {
"@id": "http://localhost:55001/plone",
Expand Down
1 change: 1 addition & 0 deletions docs/source/_json/event.resp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Content-Type: application/json
"expires": null,
"id": "event",
"language": "",
"layout": "event_view",
"location": null,
"modified": "2016-01-21T03:24:11+00:00",
"open_end": null,
Expand Down
1 change: 1 addition & 0 deletions docs/source/_json/file.resp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Content-Type: application/json
},
"id": "file",
"language": "",
"layout": "file_view",
"modified": "2016-01-21T05:24:11+00:00",
"parent": {
"@id": "http://localhost:55001/plone",
Expand Down
1 change: 1 addition & 0 deletions docs/source/_json/folder.resp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Content-Type: application/json
],
"items_total": 2,
"language": "",
"layout": "listing_view",
"modified": "2016-01-21T07:24:11+00:00",
"nextPreviousEnabled": false,
"parent": {
Expand Down
1 change: 1 addition & 0 deletions docs/source/_json/image.resp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Content-Type: application/json
"width": 215
},
"language": "",
"layout": "image_view",
"modified": "2016-01-21T06:24:11+00:00",
"parent": {
"@id": "http://localhost:55001/plone",
Expand Down
1 change: 1 addition & 0 deletions docs/source/_json/link.resp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Content-Type: application/json
"expires": null,
"id": "link",
"language": "",
"layout": "link_redirect_view",
"modified": "2016-01-21T04:24:11+00:00",
"parent": {
"@id": "http://localhost:55001/plone",
Expand Down
1 change: 1 addition & 0 deletions docs/source/_json/newsitem.resp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Content-Type: application/json
},
"image_caption": "This is an image caption.",
"language": "",
"layout": "newsitem_view",
"modified": "2016-01-21T02:24:11+00:00",
"parent": {
"@id": "http://localhost:55001/plone",
Expand Down
3 changes: 3 additions & 0 deletions docs/source/_json/types_document.resp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ Content-Type: application/json+schema
"title": "Ownership"
}
],
"layouts": [
"document_view"
],
"properties": {
"allow_discussion": {
"choices": [
Expand Down
2 changes: 1 addition & 1 deletion docs/source/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Types
.. note::
These docs are generated by code tests, therefore you will see some 'test' contenttypes appear here.

Available content types in a Plone site can be listed and queried by accessing the ``/@types`` endpoint on any context (requires an authenticated user). The 'addable' key specifies if the content type can be added to the current context.
Available content types in a Plone site can be listed and queried by accessing the ``/@types`` endpoint on any context (requires an authenticated user). The 'addable' key specifies if the content type can be added to the current context. The 'layouts' key specifies the defined views.


.. http:example:: curl httpie python-requests
Expand Down
6 changes: 6 additions & 0 deletions src/plone/restapi/deserializer/atcontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ def __call__(self, validate_all=False):
notify(ObjectEditedEvent(obj))
obj.at_post_edit_script()

# We'll set the layout after the validation and and even if there
# are no other changes.
if 'layout' in data:
layout = data['layout']
self.context.setLayout(layout)

return obj

def validate(self):
Expand Down
8 changes: 7 additions & 1 deletion src/plone/restapi/deserializer/dxcontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(self, context, request):
self.sm = getSecurityManager()
self.permission_cache = {}

def __call__(self, validate_all=False):
def __call__(self, validate_all=False): # noqa: ignore=C901
data = json_body(self.request)

modified = False
Expand Down Expand Up @@ -105,6 +105,12 @@ def __call__(self, validate_all=False):
if errors:
raise BadRequest(errors)

# We'll set the layout after the validation and and even if there
# are no other changes.
if 'layout' in data:
layout = data['layout']
self.context.setLayout(layout)

if modified:
notify(ObjectModifiedEvent(self.context))

Expand Down
1 change: 1 addition & 0 deletions src/plone/restapi/serializer/atcontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def __call__(self):
'parent': parent_summary,
'review_state': self._get_workflow_state(),
'UID': self.context.UID(),
'layout': self.context.getLayout(),
}

obj = self.context
Expand Down
1 change: 1 addition & 0 deletions src/plone/restapi/serializer/dxcontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def __call__(self):
'modified': json_compatible(self.context.modified()),
'review_state': self._get_workflow_state(),
'UID': self.context.UID(),
'layout': self.context.getLayout(),
}

for schema in iterSchemata(self.context):
Expand Down
6 changes: 6 additions & 0 deletions src/plone/restapi/tests/test_atcontent_deserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ def __call__(self, request):
self.assertEquals(
'pre_validation_error', cm.exception.message[0]['message'])

def test_set_layout(self):
current_layout = self.doc1.getLayout()
self.assertNotEquals(current_layout, "my_new_layout")
self.deserialize(body='{"layout": "my_new_layout"}')
self.assertEquals('my_new_layout', self.doc1.getLayout())


class TestValidationRequest(unittest.TestCase):

Expand Down
6 changes: 6 additions & 0 deletions src/plone/restapi/tests/test_atcontent_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,9 @@ def test_serializer_orders_folder_items_by_get_object_position_in_parent(self):
'review_state': 'private'
},
])

def test_get_layout(self):
current_layout = self.doc1.getLayout()
obj = self.serialize(self.doc1)
self.assertIn('layout', obj)
self.assertEquals(current_layout, obj['layout'])
6 changes: 6 additions & 0 deletions src/plone/restapi/tests/test_dxcontent_deserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,9 @@ def test_deserializer_passes_validation_with_not_provided_defaults(self):
self.portal.doc1.test_default_value_field)
self.assertEquals(u'DefaultFactory',
self.portal.doc1.test_default_factory_field)

def test_set_layout(self):
current_layout = self.portal.doc1.getLayout()
self.assertNotEquals(current_layout, "my_new_layout")
self.deserialize(body='{"layout": "my_new_layout"}')
self.assertEquals('my_new_layout', self.portal.doc1.getLayout())
6 changes: 6 additions & 0 deletions src/plone/restapi/tests/test_dxcontent_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,9 @@ def test_serializer_includes_field_with_read_permission(self):
obj = self.serialize()
self.assertIn(u'test_read_permission_field', obj)
self.assertEqual(u'Secret Stuff', obj[u'test_read_permission_field'])

def test_get_layout(self):
current_layout = self.portal.doc1.getLayout()
obj = self.serialize()
self.assertIn('layout', obj)
self.assertEquals(current_layout, obj['layout'])
1 change: 1 addition & 0 deletions src/plone/restapi/tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def test_get_jsonschema_for_fti(self):
self.assertIn('title', jsonschema['required'])
self.assertEquals('default', jsonschema['fieldsets'][0]['id'])
self.assertIn('title', jsonschema['fieldsets'][0]['fields'])
self.assertIn('layouts', jsonschema)

jsonschema = get_jsonschema_for_fti(
ttool['Document'],
Expand Down
1 change: 1 addition & 0 deletions src/plone/restapi/types/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def get_jsonschema_for_fti(fti, context, request, excluded_fields=None):
'properties': properties,
'required': required,
'fieldsets': get_fieldset_infos(fieldsets),
'layouts': getattr(fti, 'view_methods', []),
}


Expand Down
2 changes: 1 addition & 1 deletion test-no-uncommitted-doc-changes.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if [ "$PLONE_VERSION" = "5.0.x" ]; then
exit 0
fi

changes=$(git diff --exit-code $DUMPS_DIR)
changes=$(git diff --ignore-space-at-eol --exit-code $DUMPS_DIR)
if [ $? -ne 0 ]; then
red "ERROR: There are modified files in $DUMPS_DIR after running test_documentation.py!"
red
Expand Down

0 comments on commit 8271e5e

Please sign in to comment.