Commit 2d315a81 authored by Jérome Perrin's avatar Jérome Perrin

core: support binary data in ZODB History View

It was failing decoding unicode
parent 388c7230
...@@ -8,7 +8,15 @@ if not getSecurityManager().getUser().has_permission('View History', context): ...@@ -8,7 +8,15 @@ if not getSecurityManager().getUser().has_permission('View History', context):
raise Unauthorized() raise Unauthorized()
def beautifyChange(change_dict): def beautifyChange(change_dict):
return ["%s:%s" % (k,change_dict[k]) for k in sorted(change_dict.keys())] change_list = []
for property_name, property_value in sorted(change_dict.items()):
if isinstance(property_value, basestring):
try:
property_value = unicode(property_value, 'utf8')
except UnicodeDecodeError:
property_value = '(binary)'
change_list.append('%s:%s' % (property_name, property_value))
return change_list
try: try:
history_size = portal.portal_preferences.getPreferredHtmlStyleZodbHistorySize() history_size = portal.portal_preferences.getPreferredHtmlStyleZodbHistorySize()
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
############################################################################## ##############################################################################
import unittest import unittest
import os
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
...@@ -144,6 +145,29 @@ class TestZODBHistory(ERP5TypeTestCase): ...@@ -144,6 +145,29 @@ class TestZODBHistory(ERP5TypeTestCase):
from zExceptions import Unauthorized from zExceptions import Unauthorized
self.assertRaises(Unauthorized, document.Base_viewZODBHistory) self.assertRaises(Unauthorized, document.Base_viewZODBHistory)
def test_ZODBHistoryBinaryData(self):
"""
Make sure ZODB History view works with binary content
"""
self.loginByUserName('tatuya')
document = self.addOrganisation(self.id()).newContent(
portal_type='Embedded File')
document.setFile(
open(os.path.join(
os.path.dirname(__file__),
'test_data',
'images',
'erp5_logo.png')))
self.commit()
# no encoding error
document.Base_viewZODBHistory()
change, = document.Base_getZODBHistoryList()
self.assertIn('data:(binary)', change.getProperty('changes'))
self.assertIn('content_type:image/png', change.getProperty('changes'))
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
......
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