Skip to content

Commit

Permalink
Merge pull request #540 from plone/issue-337-translated-titles-in-types
Browse files Browse the repository at this point in the history
Translate the fti title in @types endpoint
  • Loading branch information
tisto committed Jun 23, 2018
2 parents 6df9f76 + 47255db commit 2fd577b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Expand Up @@ -12,6 +12,9 @@ Changelog

New Features:

- Translate FTI titles on `@types` endpoint. Fixes #337.
[erral]

- Include translated role title in `@roles` GET.
[lgraf]

Expand Down
5 changes: 3 additions & 2 deletions src/plone/restapi/services/types/get.py
Expand Up @@ -4,8 +4,9 @@
from Products.CMFCore.interfaces import IFolderish
from Products.CMFCore.utils import getToolByName
from zExceptions import Unauthorized
from zope.component import getUtility
from zope.component import getMultiAdapter
from zope.component import getUtility
from zope.i18n import translate
from zope.interface import implements
from zope.publisher.interfaces import IPublishTraverse
from zope.schema.interfaces import IVocabularyFactory
Expand Down Expand Up @@ -85,7 +86,7 @@ def reply(self):
return [
{
'@id': '{}/@types/{}'.format(portal_url, fti.getId()),
'title': fti.Title(),
'title': translate(fti.Title(), context=self.request),
'addable': fti.getId() in allowed_types if can_add else False,
} for fti in ftis
]
43 changes: 40 additions & 3 deletions src/plone/restapi/tests/test_services_types.py
@@ -1,11 +1,12 @@
# -*- coding: utf-8 -*-
from plone import api
from plone.restapi.testing import PLONE_RESTAPI_DX_FUNCTIONAL_TESTING
from plone.restapi.testing import RelativeSession
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
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.restapi.testing import PLONE_RESTAPI_DX_FUNCTIONAL_TESTING
from plone.restapi.testing import RelativeSession


import transaction
import unittest
Expand Down Expand Up @@ -165,3 +166,39 @@ def test_addable_types_for_non_manager_user(self):

self.assertEquals(
len([a for a in response if a['addable']]), 0)


class TestServicesTypesTranslatedTitles(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.headers.update({'Accept-Language': 'es'})
self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD)

transaction.commit()

def test_get_types_translated(self):
response = self.api_session.get(
'{}/@types'.format(self.portal.absolute_url())
)

self.assertEqual(response.status_code, 200)

self.assertItemsEqual([
u'Archivo',
u'Carpeta',
u'Colección',
u'DX Test Document',
u'Enlace',
u'Evento',
u'Imagen',
u'Noticia',
u'Página'],
[item['title'] for item in response.json()])

0 comments on commit 2fd577b

Please sign in to comment.