Skip to content

Commit

Permalink
Apply 'Breakin lines convention'. Use plone.api
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Uittenbroek committed Mar 6, 2015
1 parent b49b419 commit e5f2dc3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 27 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -5,6 +5,8 @@ There's a frood who really knows where his towel is.

1.0a10 (unreleased)
^^^^^^^^^^^^^^^^^^^
- Fix the indexing of richtext tiles by manually transform the text/html to text/plain
[puittenbroek]

- Fix modification time disappearing from context data and handling missing value (fixes `#449`_).
[mhora]
Expand Down
19 changes: 10 additions & 9 deletions src/collective/cover/content.py
Expand Up @@ -5,7 +5,7 @@
from collective.cover.interfaces import ICover
from collective.cover.utils import assign_tile_ids
from five import grok
from Products.CMFCore.utils import getToolByName
from plone import api
from plone.dexterity.content import Item
from plone.indexer import indexer
from plone.registry.interfaces import IRegistry
Expand Down Expand Up @@ -150,18 +150,19 @@ def searchableText(obj):
"""Return searchable text to be used as indexer. Includes id, title,
description and text from Rich Text tiles."""
tiles_text = ''
transforms = getToolByName(obj, 'portal_transforms', None)
transforms = api.portal.get_tool('portal_transforms')
for t in obj.list_tiles('collective.cover.richtext'):
tile = obj.restrictedTraverse(
'@@collective.cover.richtext/{0}'.format(str(t)))
value = tile.data['text']
data = transforms.convertTo('text/plain',
value.raw_encoded,
mimetype='text/html',
context=obj,
# portal_transforms caches on this
object=value._raw_holder,
encoding=value.encoding)
data = transforms.convertTo(
'text/plain',
value.raw_encoded,
mimetype='text/html',
context=obj,
# portal_transforms caches on this
object=value._raw_holder,
encoding=value.encoding)
if data:
tiles_text += data.getData()

Expand Down
40 changes: 22 additions & 18 deletions src/collective/cover/tests/test_cover.py
Expand Up @@ -100,34 +100,38 @@ def test_searchabletext_indexer(self):
from plone.tiles.interfaces import ITileDataManager
self.cover.title = u'Lorem ipsum'
self.cover.description = u'Neque porro'
# set up a simple layout with a couple of RichText tiles
# set up a simple layout with a two RichText tiles
self.cover.cover_layout = u"""
[{"children": [{"children": [{"class": "tile",
"id": "test1",
"tile-type": "collective.cover.richtext",
"type": "tile"},
{"class": "tile",
"id": "test2",
"tile-type": "collective.cover.richtext",
"type": "tile"}],
[{"children":
[{"children": [
{"class": "tile",
"id": "test1",
"tile-type": "collective.cover.richtext",
"type": "tile"},
{"class": "tile",
"id": "test2",
"tile-type": "collective.cover.richtext",
"type": "tile"}],
"data": {"column-size": 8, "layout-type": "column"},
"id": "group1",
"roles": ["Manager"],
"type": "group"}],
"class": "row",
"type": "row"}]
"""
"class": "row",
"type": "row"}]
"""
tile = self.cover.restrictedTraverse('collective.cover.richtext/test1')
value1 = RichTextValue(raw=u'<p>01234</p>',
mimeType='text/x-html-safe',
outputMimeType='text/x-html-safe')
value1 = RichTextValue(
raw=u'<p>01234</p>',
mimeType='text/x-html-safe',
outputMimeType='text/x-html-safe')
data_mgr = ITileDataManager(tile)
data_mgr.set({'text': value1})
tile = self.cover.restrictedTraverse('collective.cover.richtext/test2')
data_mgr = ITileDataManager(tile)
value2 = RichTextValue(raw=u'<p>56789</p>',
mimeType='text/x-html-safe',
outputMimeType='text/x-html-safe')
value2 = RichTextValue(
raw=u'<p>56789</p>',
mimeType='text/x-html-safe',
outputMimeType='text/x-html-safe')
data_mgr.set({'text': value2})

# indexer should contain id, title, description and text in tiles
Expand Down

0 comments on commit e5f2dc3

Please sign in to comment.