Skip to content

Commit

Permalink
Copy parts of plone.app.textfield.transform to our own code, so we ca…
Browse files Browse the repository at this point in the history
…n work with the raw version of our RichTextValue directly
  • Loading branch information
Peter Uittenbroek committed Mar 5, 2015
1 parent 1112f8a commit b49b419
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
13 changes: 12 additions & 1 deletion src/collective/cover/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +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.dexterity.content import Item
from plone.indexer import indexer
from plone.registry.interfaces import IRegistry
Expand Down Expand Up @@ -149,10 +150,20 @@ 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)
for t in obj.list_tiles('collective.cover.richtext'):
tile = obj.restrictedTraverse(
'@@collective.cover.richtext/{0}'.format(str(t)))
tiles_text += tile.data['text'].output
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)
if data:
tiles_text += data.getData()

searchable_text = [safe_unicode(entry) for entry in (
obj.id,
Expand Down
19 changes: 1 addition & 18 deletions src/collective/cover/tests/test_cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ def test_searchabletext_indexer(self):
from collective.cover.content import searchableText
from plone.app.textfield.value import RichTextValue
from plone.tiles.interfaces import ITileDataManager
from plone.app.textfield.interfaces import ITransformer
self.cover.title = u'Lorem ipsum'
self.cover.description = u'Neque porro'
# set up a simple layout with a couple of RichText tiles
Expand Down Expand Up @@ -131,26 +130,10 @@ def test_searchabletext_indexer(self):
outputMimeType='text/x-html-safe')
data_mgr.set({'text': value2})

transformer = ITransformer(self.cover)
output1 = transformer(value1, 'text/plain')
# The following two assertion are NotEqual to show the problem.
# Due to the way we construct the RichtTextValue we get this
# (swallowed) exception:
# No transform path found from 'text/x-html-safe' to 'text/plain'.
# Which results in the the outputs being empty
# And these assertions being true.
self.assertEqual(
output1,
u'')
output2 = transformer(value2, 'text/plain')

self.assertEqual(
output2,
u'')
# indexer should contain id, title, description and text in tiles
self.assertEqual(
searchableText(self.cover)(),
u'c1 Lorem ipsum Neque porro 01234 56789'
u'c1 Lorem ipsum Neque porro 01234 56789 '
)

# TODO: add test for plone.app.relationfield.behavior.IRelatedItems
Expand Down

0 comments on commit b49b419

Please sign in to comment.