Skip to content

Commit

Permalink
Merge branch 'master' into linkintegrity-items-total
Browse files Browse the repository at this point in the history
  • Loading branch information
tisto committed Aug 23, 2023
2 parents ff9680f + 47a6402 commit 026f2fc
Show file tree
Hide file tree
Showing 8 changed files with 241 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.. image:: https://github.com/plone/plone.restapi/workflows/Plone%20RESTAPI%20CI/badge.svg
:target: https://github.com/plone/plone.restapi/actions?query=workflow%3A%22Plone+RESTAPI+CI%22
.. image:: https://github.com/plone/plone.restapi/actions/workflows/tests.yml/badge.svg?branch=master
:target: https://github.com/plone/plone.restapi/actions/workflows/tests.yml

.. image:: https://coveralls.io/repos/github/plone/plone.restapi/badge.svg?branch=master
:target: https://coveralls.io/github/plone/plone.restapi?branch=master
Expand Down
30 changes: 28 additions & 2 deletions docs/source/endpoints/translations.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ To unlink the content, issue a `DELETE` request on the `@translations` endpoint
## Creating a translation from an existing content

The `POST` content endpoint to a folder is also capable of linking this new content with an
exising translation using two parameters: `translationOf` and `language`.
existing translation using two parameters: `translationOf` and `language`.

```{eval-rst}
.. http:example:: curl httpie python-requests
Expand Down Expand Up @@ -125,6 +125,32 @@ This endpoint returns the proper placement for the newly created translation:

## Expansion

This endpoint can be used with the {doc}`../usage/expansion` mechanism which allows getting additional information about a content item in one query, avoiding unnecessary requests.
This service can be used with the {doc}`../usage/expansion` mechanism which allows getting additional information about a content item in one query, avoiding additional requests.

Translation information can be provided by the API expansion for translatable content items.
A content type is translatable if it has the `plone.translatable` behavior enabled.
`plone.app.multilingual` enables this behavior for all content types at the time that it is installed.
For other content types added later, it would be necessary to enable the behavior for them also.

If a simple `GET` request is done on the content item, a new entry will be shown on the `@components` entry, with the URL of the `@translations` endpoint:

```{eval-rst}
.. http:example:: curl httpie python-requests
:request: ../../../src/plone/restapi/tests/http-examples/translations_unexpanded_get.req
```

```{literalinclude} ../../../src/plone/restapi/tests/http-examples/translations_unexpanded_get.resp
:language: http
```

In order to expand and embed the translations component, use the GET parameter `expand` with the value `translations`.

```{eval-rst}
.. http:example:: curl httpie python-requests
:request: ../../../src/plone/restapi/tests/http-examples/translations_expand_get.req
```

```{literalinclude} ../../../src/plone/restapi/tests/http-examples/translations_expand_get.resp
:language: http
```

1 change: 1 addition & 0 deletions news/1374.documentation
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added translation code through expansion. @Akshat2Jain
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
GET /plone/en/test-document?expand=translations HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0
100 changes: 100 additions & 0 deletions src/plone/restapi/tests/http-examples/translations_expand_get.resp
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
HTTP/1.1 200 OK
Content-Type: application/json

{
"@components": {
"actions": {
"@id": "http://localhost:55001/plone/en/test-document/@actions"
},
"aliases": {
"@id": "http://localhost:55001/plone/en/test-document/@aliases"
},
"breadcrumbs": {
"@id": "http://localhost:55001/plone/en/test-document/@breadcrumbs"
},
"contextnavigation": {
"@id": "http://localhost:55001/plone/en/test-document/@contextnavigation"
},
"navigation": {
"@id": "http://localhost:55001/plone/en/test-document/@navigation"
},
"navroot": {
"@id": "http://localhost:55001/plone/en/test-document/@navroot"
},
"translations": {
"@id": "http://localhost:55001/plone/en/test-document/@translations",
"items": [
{
"@id": "http://localhost:55001/plone/es/test-document",
"language": "es"
}
],
"root": {
"de": "http://localhost:55001/plone/de",
"en": "http://localhost:55001/plone/en",
"es": "http://localhost:55001/plone/es",
"fr": "http://localhost:55001/plone/fr"
}
},
"types": {
"@id": "http://localhost:55001/plone/en/test-document/@types"
},
"workflow": {
"@id": "http://localhost:55001/plone/en/test-document/@workflow"
}
},
"@id": "http://localhost:55001/plone/en/test-document",
"@type": "Document",
"UID": "SomeUUID000000000000000000000001",
"allow_discussion": false,
"changeNote": "",
"contributors": [],
"created": "1995-07-31T13:45:00+00:00",
"creators": [
"test_user_1_"
],
"description": "",
"effective": null,
"exclude_from_nav": false,
"expires": null,
"id": "test-document",
"is_folderish": false,
"language": {
"title": "English",
"token": "en"
},
"layout": "document_view",
"lock": {
"locked": false,
"stealable": true
},
"modified": "1995-07-31T17:30:00+00:00",
"next_item": {},
"parent": {
"@id": "http://localhost:55001/plone/en",
"@type": "LRF",
"description": "",
"review_state": "published",
"title": "English",
"type_title": "Language Root Folder"
},
"previous_item": {
"@id": "http://localhost:55001/plone/en/assets",
"@type": "LIF",
"description": "",
"title": "Assets",
"type_title": "Language Independent Folder"
},
"relatedItems": [],
"review_state": "private",
"rights": "",
"subjects": [],
"table_of_contents": null,
"text": null,
"title": "Test document",
"type_title": "Page",
"version": "current",
"versioning_enabled": true,
"working_copy": null,
"working_copy_of": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
GET /plone/en/test-document HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
HTTP/1.1 200 OK
Content-Type: application/json

{
"@components": {
"actions": {
"@id": "http://localhost:55001/plone/en/test-document/@actions"
},
"aliases": {
"@id": "http://localhost:55001/plone/en/test-document/@aliases"
},
"breadcrumbs": {
"@id": "http://localhost:55001/plone/en/test-document/@breadcrumbs"
},
"contextnavigation": {
"@id": "http://localhost:55001/plone/en/test-document/@contextnavigation"
},
"navigation": {
"@id": "http://localhost:55001/plone/en/test-document/@navigation"
},
"navroot": {
"@id": "http://localhost:55001/plone/en/test-document/@navroot"
},
"translations": {
"@id": "http://localhost:55001/plone/en/test-document/@translations"
},
"types": {
"@id": "http://localhost:55001/plone/en/test-document/@types"
},
"workflow": {
"@id": "http://localhost:55001/plone/en/test-document/@workflow"
}
},
"@id": "http://localhost:55001/plone/en/test-document",
"@type": "Document",
"UID": "SomeUUID000000000000000000000001",
"allow_discussion": false,
"changeNote": "",
"contributors": [],
"created": "1995-07-31T13:45:00+00:00",
"creators": [
"test_user_1_"
],
"description": "",
"effective": null,
"exclude_from_nav": false,
"expires": null,
"id": "test-document",
"is_folderish": false,
"language": {
"title": "English",
"token": "en"
},
"layout": "document_view",
"lock": {
"locked": false,
"stealable": true
},
"modified": "1995-07-31T17:30:00+00:00",
"next_item": {},
"parent": {
"@id": "http://localhost:55001/plone/en",
"@type": "LRF",
"description": "",
"review_state": "published",
"title": "English",
"type_title": "Language Root Folder"
},
"previous_item": {
"@id": "http://localhost:55001/plone/en/assets",
"@type": "LIF",
"description": "",
"title": "Assets",
"type_title": "Language Independent Folder"
},
"relatedItems": [],
"review_state": "private",
"rights": "",
"subjects": [],
"table_of_contents": null,
"text": null,
"title": "Test document",
"type_title": "Page",
"version": "current",
"versioning_enabled": true,
"working_copy": null,
"working_copy_of": null
}
16 changes: 16 additions & 0 deletions src/plone/restapi/tests/test_documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2271,6 +2271,22 @@ def test_documentation_translation_locator(self):
)
save_request_and_response_for_docs("translation_locator", response)

def test_documentation_translations_unexpanded_get(self):
response = self.api_session.get(
f"{self.en_content.absolute_url()}",
)
save_request_and_response_for_docs("translations_unexpanded_get", response)

def test_documentation_translations_expand_get(self):
self.api_session.post(
f"{self.en_content.absolute_url()}/@translations",
json={"id": self.es_content.absolute_url()},
)
response = self.api_session.get(
f"{self.en_content.absolute_url()}?expand=translations",
)
save_request_and_response_for_docs("translations_expand_get", response)

def test_site_navroot_get(self):
response = self.api_session.get("/@navroot")
save_request_and_response_for_docs("navroot_site_get", response)
Expand Down

0 comments on commit 026f2fc

Please sign in to comment.