Commit d863acaf authored by Stefan H. Holek's avatar Stefan H. Holek

Collector #533: ZMI Find now searches in text Files.

parent d16f0c50
......@@ -105,7 +105,7 @@ class File(Persistent, Implicit, PropertyManager,
('manage_edit','manage_upload','PUT')),
('View',
('index_html', 'view_image_or_file', 'get_size',
'getContentType', '')),
'getContentType', 'PrincipiaSearchSource', '')),
('FTP access',
('manage_FTPstat','manage_FTPget','manage_FTPlist')),
('Delete objects',
......@@ -413,6 +413,13 @@ class File(Persistent, Implicit, PropertyManager,
"""
raise Redirect, URL1
def PrincipiaSearchSource(self):
""" Allow file objects to be searched.
"""
if self.content_type.startswith('text/'):
return str(self.data)
return ''
# private
update_data__roles__=()
def update_data(self, data, content_type=None, size=None):
......
import Testing
import Zope
Zope.startup()
import os, sys
import unittest
import time
......@@ -219,6 +223,25 @@ class FileTests(unittest.TestCase):
def testStr(self):
self.assertEqual(str(self.file), self.data)
def testFindSupport_not_text(self):
self.file.manage_edit('foobar', 'application/octet-stream',
filedata=''.join([chr(x) for x in range(256)]))
self.assertEqual(self.file.PrincipiaSearchSource(), '')
def testFindSupport_text(self):
self.file.manage_edit('foobar', 'text/plain',
filedata='Now is the time for all good men to '
'come to the aid of the Party.')
self.failUnless('Party' in self.file.PrincipiaSearchSource())
def testFindFile(self):
self.file.manage_edit('foobar', 'text/plain',
filedata='Now is the time for all good men to '
'come to the aid of the Party.')
results = self.app.ZopeFind(self.app, obj_searchterm='Party')
self.assertEqual(len(results), 1)
self.assertEqual(results[0][1], self.file)
class ImageTests(FileTests):
data = open(filedata, 'rb').read()
content_type = 'image/gif'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment