From 2bdbfc35eff4689c8c285d60b535495c4ed5a1a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Perrin?= Date: Fri, 5 Dec 2014 14:43:10 +0900 Subject: [PATCH 1/3] Enable history page for OFS.Image.File Use the standard history page, enabled using the same condition than the one that enables the text area on edit (ie. the file must be text or javascript and reasonably sized) --- src/OFS/Image.py | 21 ++++++++++++++++++++- src/OFS/tests/testFileAndImage.py | 10 ++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) 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..4f4bf46deb 100644 --- a/src/OFS/tests/testFileAndImage.py +++ b/src/OFS/tests/testFileAndImage.py @@ -302,6 +302,16 @@ 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='a') + getattr(self.app, self.factory)('b', + file='b', content_type='text/plain') + self.file.manage_historyCompare( + self.file, + self.app.b, + self.app.REQUEST) + def test_interfaces(self): from zope.interface.verify import verifyClass from OFS.Image import File From d8b1238427768699b25347c3ce3836535eeb480d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Perrin?= Date: Sat, 17 Nov 2018 04:52:52 +0100 Subject: [PATCH 2/3] fixup! Enable history page for OFS.Image.File add some assertions on the html returned by manage_historyCompare --- src/OFS/tests/testFileAndImage.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/OFS/tests/testFileAndImage.py b/src/OFS/tests/testFileAndImage.py index 4f4bf46deb..0c11764521 100644 --- a/src/OFS/tests/testFileAndImage.py +++ b/src/OFS/tests/testFileAndImage.py @@ -304,13 +304,15 @@ def testFindFile(self): def testHistoryCompare(self): self.file.manage_edit('a', 'text/plain', - filedata='a') + filedata='content_of_a') getattr(self.app, self.factory)('b', - file='b', content_type='text/plain') - self.file.manage_historyCompare( + 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 9616da88f86c02b16e31610bf2a21b13190451fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Perrin?= Date: Sat, 17 Nov 2018 05:18:59 +0100 Subject: [PATCH 3/3] Add changelog entry for #396 --- doc/CHANGES.rst | 3 +++ 1 file changed, 3 insertions(+) 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) --------------------