Commit fb840ce9 authored by Jérome Perrin's avatar Jérome Perrin Committed by GitHub

Merge pull request #396 from perrinjerome/feat/history_tab_for_ofs_file-2.13

Enable history page for OFS.Image.File
parents dc14c564 9616da88
......@@ -22,6 +22,9 @@ Features
- Add wildcard rewrite to sub host name in virtualHostMonster.
(`#317 <https://github.com/zopefoundation/Zope/issues/317>`_)
- Enable ZMI History tab for ``OFS.Image.File``.
(`#396 <https://github.com/zopefoundation/Zope/pull/396>`_)
2.13.28 (2018-04-23)
--------------------
......
......@@ -44,6 +44,9 @@ from OFS.PropertyManager import PropertyManager
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 @@ class File(Persistent, Implicit, PropertyManager,
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:
......
......@@ -302,6 +302,18 @@ class FileTests(unittest.TestCase):
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
......
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