diff --git a/doc/CHANGES.rst b/doc/CHANGES.rst index 65361a3f40..da1d5d0d4d 100644 --- a/doc/CHANGES.rst +++ b/doc/CHANGES.rst @@ -22,6 +22,9 @@ Features - Add wildcard rewrite to sub host name in virtualHostMonster. (`#317 `_) +- Enable ZMI History tab for ``OFS.Image.File``. + (`#396 `_) + 2.13.28 (2018-04-23) -------------------- diff --git a/src/OFS/Image.py b/src/OFS/Image.py index c6353b6bb2..e493f8583c 100644 --- a/src/OFS/Image.py +++ b/src/OFS/Image.py @@ -44,6 +44,9 @@ from OFS.role import RoleManager from OFS.SimpleItem import Item_w__name__ +from OFS.History import Historical +from OFS.History import html_diff + from zope.event import notify from zope.lifecycleevent import ObjectModifiedEvent from zope.lifecycleevent import ObjectCreatedEvent @@ -87,7 +90,7 @@ def manage_addFile(self, id, file='', title='', precondition='', class File(Persistent, Implicit, PropertyManager, - RoleManager, Item_w__name__, Cacheable): + RoleManager, Item_w__name__, Historical, Cacheable): """A File object is a content object for arbitrary files.""" implements(implementedBy(Persistent), @@ -125,6 +128,7 @@ class File(Persistent, Implicit, PropertyManager, + RoleManager.manage_options + Item_w__name__.manage_options + Cacheable.manage_options + + Historical.manage_options ) _properties=({'id':'title', 'type': 'string'}, @@ -500,6 +504,21 @@ def manage_upload(self,file='',REQUEST=None): message="Saved changes." return self.manage_main(self,REQUEST,manage_tabs_message=message) + def manage_historyCompare(self, rev1, rev2, REQUEST, + historyComparisonResults=''): + if self.content_type and (( + self.content_type.startswith('text') or + self.content_type.endswith('javascript')) + and self.get_size() < 65536): + return File.inheritedAttribute('manage_historyCompare')( + self, rev1, rev2, REQUEST, + historyComparisonResults=html_diff( + str(rev1.data), + str(rev2.data))) + return File.inheritedAttribute('manage_historyCompare')( + self, rev1, rev2, REQUEST, + historyComparisonResults=historyComparisonResults) + def _get_content_type(self, file, body, id, content_type=None): headers=getattr(file, 'headers', None) if headers and 'content-type' in headers: diff --git a/src/OFS/tests/testFileAndImage.py b/src/OFS/tests/testFileAndImage.py index e86ee79f8f..0c11764521 100644 --- a/src/OFS/tests/testFileAndImage.py +++ b/src/OFS/tests/testFileAndImage.py @@ -302,6 +302,18 @@ def testFindFile(self): self.assertEqual(len(results), 1) self.assertEqual(results[0][1], self.file) + def testHistoryCompare(self): + self.file.manage_edit('a', 'text/plain', + filedata='content_of_a') + getattr(self.app, self.factory)('b', + file='content_of_b', content_type='text/plain') + page = self.file.manage_historyCompare( + self.file, + self.app.b, + self.app.REQUEST) + self.assertTrue('content_of_a' in page) + self.assertTrue('content_of_b' in page) + def test_interfaces(self): from zope.interface.verify import verifyClass from OFS.Image import File