Commit 34e6f304 authored by Hanno Schlichting's avatar Hanno Schlichting

Drop `OFS.History` functionality.

parent 96a15021
...@@ -28,6 +28,8 @@ Features Added ...@@ -28,6 +28,8 @@ Features Added
Restructuring Restructuring
+++++++++++++ +++++++++++++
- Drop `OFS.History` functionality.
- Removed ZMI export/import feature. - Removed ZMI export/import feature.
- Drop ZopeUndo dependency and move undo management to the control panel. - Drop ZopeUndo dependency and move undo management to the control panel.
......
...@@ -33,8 +33,6 @@ from DocumentTemplate.permissions import change_dtml_methods ...@@ -33,8 +33,6 @@ from DocumentTemplate.permissions import change_dtml_methods
from DocumentTemplate.security import RestrictedDTML from DocumentTemplate.security import RestrictedDTML
from OFS import bbb from OFS import bbb
from OFS.Cache import Cacheable from OFS.Cache import Cacheable
from OFS.History import Historical
from OFS.History import html_diff
from OFS.role import RoleManager from OFS.role import RoleManager
from OFS.SimpleItem import Item_w__name__ from OFS.SimpleItem import Item_w__name__
from zExceptions import Forbidden, ResourceLockedError from zExceptions import Forbidden, ResourceLockedError
...@@ -53,7 +51,6 @@ class DTMLMethod(RestrictedDTML, ...@@ -53,7 +51,6 @@ class DTMLMethod(RestrictedDTML,
Implicit, Implicit,
RoleManager, RoleManager,
Item_w__name__, Item_w__name__,
Historical,
Cacheable): Cacheable):
""" DocumentTemplate.HTML objects that act as methods of their containers. """ DocumentTemplate.HTML objects that act as methods of their containers.
""" """
...@@ -78,18 +75,11 @@ class DTMLMethod(RestrictedDTML, ...@@ -78,18 +75,11 @@ class DTMLMethod(RestrictedDTML,
{'label': 'View', 'action': ''}, {'label': 'View', 'action': ''},
{'label': 'Proxy', 'action': 'manage_proxyForm'}, {'label': 'Proxy', 'action': 'manage_proxyForm'},
) + ) +
Historical.manage_options +
RoleManager.manage_options + RoleManager.manage_options +
Item_w__name__.manage_options + Item_w__name__.manage_options +
Cacheable.manage_options Cacheable.manage_options
) )
# Careful in permission changes--used by DTMLDocument!
security.declareProtected(change_dtml_methods, 'manage_historyCopy')
security.declareProtected(change_dtml_methods, 'manage_beforeHistoryCopy')
security.declareProtected(change_dtml_methods, 'manage_afterHistoryCopy')
# More reasonable default for content-type for http HEAD requests. # More reasonable default for content-type for http HEAD requests.
default_content_type = 'text/html' default_content_type = 'text/html'
...@@ -390,12 +380,6 @@ class DTMLMethod(RestrictedDTML, ...@@ -390,12 +380,6 @@ class DTMLMethod(RestrictedDTML,
""" """
return self.read() return self.read()
def manage_historyCompare(self, rev1, rev2, REQUEST,
historyComparisonResults=''):
return DTMLMethod.inheritedAttribute('manage_historyCompare')(
self, rev1, rev2, REQUEST,
historyComparisonResults=html_diff(rev1.read(), rev2.read()))
InitializeClass(DTMLMethod) InitializeClass(DTMLMethod)
token = "[a-zA-Z0-9!#$%&'*+\-.\\\\^_`|~]+" token = "[a-zA-Z0-9!#$%&'*+\-.\\\\^_`|~]+"
......
...@@ -10,252 +10,13 @@ ...@@ -10,252 +10,13 @@
# FOR A PARTICULAR PURPOSE # FOR A PARTICULAR PURPOSE
# #
############################################################################## ##############################################################################
"""Object Histories # BBB Zope 5.0
"""
from cgi import escape
import difflib
from struct import pack, unpack
from AccessControl.class_init import InitializeClass class Historical(object):
from AccessControl.Permissions import view_history
from AccessControl.SecurityInfo import ClassSecurityInfo
from Acquisition import aq_base
from Acquisition import Implicit
from App.special_dtml import DTMLFile
from DateTime.DateTime import DateTime
from ExtensionClass import Base
from zExceptions import Redirect
manage_options = tuple()
class TemporalParadox(Exception):
pass
class HistorySelectionError(Exception):
pass
class HystoryJar:
"""A ZODB Connection-like object that provides access to data
but prevents history from being changed."""
def __init__(self, base):
self.__base__ = base
def __getattr__(self, name):
return getattr(self.__base__, name)
def commit(self, object, transaction):
if object._p_changed:
raise TemporalParadox("You can't change history!")
def abort(*args, **kw):
pass
tpc_begin = tpc_finish = abort
def historicalRevision(self, serial):
state = self._p_jar.oldstate(self, serial)
rev = self.__class__.__basicnew__()
rev._p_jar = HystoryJar(self._p_jar)
rev._p_oid = self._p_oid
rev._p_serial = serial
rev.__setstate__(state)
rev._p_changed = 0
return rev
class Historian(Implicit):
"""An Historian's job is to find hysterical revisions of
objects, given a time."""
def __getitem__(self, key):
self = self.aq_parent
serial = pack(*('>HHHH',) + tuple(map(int, key.split('.'))))
if serial == self._p_serial:
return self
rev = historicalRevision(self, serial)
return rev.__of__(self.aq_parent)
def manage_workspace(self, REQUEST):
"We aren't real, so we delegate to that that spawned us!"
raise Redirect(REQUEST['URL2'] + '/manage_change_history_page')
class Historical(Base):
"""Mix-in class to provide a veiw that shows hystorical changes
The display is similar to that used for undo, except that the transactions
are limited to those that effect the displayed object and that the
interface doesn't provide an undo capability.
This interface is generally *only* interesting for objects, such
as methods, and documents, that are self-contained, meaning that
they don't have persistent sub-objects.
"""
security = ClassSecurityInfo()
HistoricalRevisions = Historian()
manage_options = (
{'label': 'History', 'action': 'manage_change_history_page'},
)
security.declareProtected(view_history, 'manage_change_history_page')
manage_change_history_page = DTMLFile(
'dtml/history', globals(),
HistoryBatchSize=20,
first_transaction=0, last_transaction=20)
security.declareProtected(view_history, 'manage_change_history')
def manage_change_history(self):
first = 0
last = 20
request = getattr(self, 'REQUEST', None)
if request is not None:
first = request.get('first_transaction', first)
last = request.get('last_transaction', last)
r = self._p_jar.db().history(self._p_oid, size=last)
if r is None:
# storage doesn't support history
return ()
r = r[first:]
for d in r:
d['time'] = DateTime(d['time'])
d['key'] = '.'.join(map(str, unpack(">HHHH", d['tid'])))
return r
def manage_beforeHistoryCopy(self):
pass # ? (Hook)
def manage_historyCopy(self, keys=[], RESPONSE=None, URL1=None):
"Copy a selected revision to the present"
if not keys:
raise HistorySelectionError(
"No historical revision was selected.<p>")
if len(keys) > 1:
raise HistorySelectionError(
"Only one historical revision can be "
"copied to the present.<p>")
key = keys[0]
serial = pack(*('>HHHH',) + tuple(map(int, key.split('.'))))
if serial != self._p_serial:
self.manage_beforeHistoryCopy()
state = self._p_jar.oldstate(self, serial)
base = aq_base(self)
base._p_activate() # make sure we're not a ghost
base.__setstate__(state) # change the state
base._p_changed = True # mark object as dirty
self.manage_afterHistoryCopy()
if RESPONSE is not None and URL1 is not None:
RESPONSE.redirect(URL1 + '/manage_workspace')
def manage_afterHistoryCopy(self):
pass # ? (Hook)
_manage_historyComparePage = DTMLFile(
'dtml/historyCompare', globals(), management_view='History')
security.declareProtected(view_history, 'manage_historyCompare')
def manage_historyCompare(self, rev1, rev2, REQUEST,
historyComparisonResults=''):
dt1 = DateTime(rev1._p_mtime)
dt2 = DateTime(rev2._p_mtime)
return self._manage_historyComparePage(
self, REQUEST,
dt1=dt1, dt2=dt2,
historyComparisonResults=historyComparisonResults)
security.declareProtected(view_history, 'manage_historicalComparison')
def manage_historicalComparison(self, REQUEST, keys=[]):
"Compare two selected revisions"
if not keys:
raise HistorySelectionError(
"No historical revision was selected.<p>")
if len(keys) > 2:
raise HistorySelectionError(
"Only two historical revision can be compared<p>")
serial = pack(*('>HHHH',) + tuple(map(int, keys[-1].split('.'))))
rev1 = historicalRevision(self, serial)
if len(keys) == 2:
serial = pack(*('>HHHH',) + tuple(map(int, keys[0].split('.'))))
rev2 = historicalRevision(self, serial)
else:
rev2 = self
return self.manage_historyCompare(rev1, rev2, REQUEST)
InitializeClass(Historical)
def dump(tag, x, lo, hi, r):
r1 = []
r2 = []
for i in range(lo, hi):
r1.append(tag)
r2.append(x[i])
r.append("<tr>\n"
"<td><pre>\n%s\n</pre></td>\n"
"<td><pre>\n%s\n</pre></td>\n"
"</tr>\n"
% ('\n'.join(r1), escape('\n'.join(r2))))
def replace(x, xlo, xhi, y, ylo, yhi, r):
rx1 = []
rx2 = []
for i in range(xlo, xhi):
rx1.append('-')
rx2.append(x[i])
ry1 = []
ry2 = []
for i in range(ylo, yhi):
ry1.append('+')
ry2.append(y[i])
r.append("<tr>\n"
"<td><pre>\n%s\n%s\n</pre></td>\n"
"<td><pre>\n%s\n%s\n</pre></td>\n"
"</tr>\n"
% ('\n'.join(rx1), '\n'.join(ry1),
escape('\n'.join(rx2)), escape('\n'.join(ry2))))
def html_diff(s1, s2): def html_diff(s1, s2):
a = s1.split('\n') raise NotImplementedError()
b = s2.split('\n')
cruncher = difflib.SequenceMatcher()
cruncher.set_seqs(a, b)
r = ['<table border=1>']
for tag, alo, ahi, blo, bhi in cruncher.get_opcodes():
if tag == 'replace':
replace(a, alo, ahi, b, blo, bhi, r)
elif tag == 'delete':
dump('-', a, alo, ahi, r)
elif tag == 'insert':
dump('+', b, blo, bhi, r)
elif tag == 'equal':
dump(' ', a, alo, ahi, r)
else:
raise ValueError('unknown tag %r' % tag)
r.append('</table>')
return '\n'.join(r)
<dtml-var manage_page_header>
<dtml-var manage_tabs>
<dtml-if manage_change_history>
<form action="<dtml-var "REQUEST.URL1" html_quote>" method="POST">
<table width="100%" cellspacing="0" cellpadding="2" border="0">
<tr class="list-header">
<td width="50%" align="left" valign="top">
<div class="list-nav">
<dtml-if first_transaction>
<dtml-with expr="_(next=first_transaction*2-last_transaction)">
<a href="<dtml-var "REQUEST.URL" html_quote>?first_transaction:int=&dtml.-next;&last_transaction:int=&dtml.-first_transaction;&HistoryBatchSize:int=&dtml.-HistoryBatchSize;">&lt; Later Revisions</a>
</dtml-with>
<dtml-else>
&nbsp;
</dtml-if>
</div>
</td>
<td width="50%" align="right" valign="top">
<div class="list-nav">
<dtml-if expr="_.len(manage_change_history) == HistoryBatchSize">
<dtml-with expr="_(last=last_transaction+HistoryBatchSize)">
<a href="<dtml-var "REQUEST.URL" html_quote>?first_transaction:int=&dtml.-last_transaction;&last_transaction:int=&dtml.-last;&HistoryBatchSize:int=&dtml.-HistoryBatchSize;">Earlier Revisions &gt;</a>
</dtml-with>
<dtml-else>
&nbsp;
</dtml-if>
</div>
</td>
</tr>
</table>
<table width="100%" cellspacing="0" cellpadding="2" border="0">
<dtml-in manage_change_history mapping>
<dtml-if sequence-odd>
<tr class="row-normal">
<dtml-else>
<tr class="row-hilite">
</dtml-if>
<td align="left" valign="top">
<input type="checkbox" value="&dtml-key;" name="keys:list">
</td>
<td align="left" valign="top">
<div class="list-item">
<a href="&dtml-absolute_url;/HistoricalRevisions/&dtml-key;/manage_workspace"><dtml-var time fmt="%Y-%m-%d %H:%M"><dtml-if
user_name> (&dtml-user_name;)</dtml-if></a>
<br><dtml-var description html_quote newline_to_br>
<dtml-if revision>
<br>revision: <em>&dtml-revision;</em>
</dtml-if>
</div>
</td>
</tr>
</dtml-in>
<tr>
<td></td>
<td align="left" valign="top">
<div class="form-element">
<input class="form-element" type="submit"
name="manage_historyCopy:method"
value="Copy to present">
<input class="form-element" type="submit"
name="manage_historicalComparison:method"
value="Compare">
</div>
</td>
</tr>
</table>
</form>
<dtml-else>
<p class="form-text">
No change history is available for this object.
</p>
</dtml-if>
<dtml-var manage_page_footer>
import os
import shutil
import time
import tempfile
import unittest
import transaction
import ZODB
from ZODB.FileStorage import FileStorage
from OFS.Application import Application
from OFS.History import Historical
from OFS.SimpleItem import SimpleItem
import Zope2
Zope2.startup_wsgi()
class HistoryItem(SimpleItem, Historical):
pass
class HistoryTests(unittest.TestCase):
def setUp(self):
# set up a zodb
# we can't use DemoStorage here 'cos it doesn't support History
self.dir = tempfile.mkdtemp()
fs_path = os.path.join(self.dir, 'testHistory.fs')
self.s = FileStorage(fs_path, create=True)
self.connection = ZODB.DB(self.s).open()
r = self.connection.root()
a = Application()
r['Application'] = a
self.root = a
# create a python script
a['test'] = HistoryItem()
self.hi = hi = a.test
# commit some changes
hi.title = 'First title'
t = transaction.get()
# undo note made by Application instantiation above.
t.description = None
t.note('Change 1')
t.commit()
time.sleep(0.02) # wait at least one Windows clock tick
hi.title = 'Second title'
t = transaction.get()
t.note('Change 2')
t.commit()
time.sleep(0.02) # wait at least one Windows clock tick
hi.title = 'Third title'
t = transaction.get()
t.note('Change 3')
t.commit()
def tearDown(self):
# get rid of ZODB
transaction.abort()
self.connection.close()
self.s.close()
del self.root
del self.connection
del self.s
shutil.rmtree(self.dir)
def test_manage_change_history(self):
r = self.hi.manage_change_history()
self.assertEqual(len(r), 3) # three transactions
for i in range(3):
entry = r[i]
# check no new keys show up without testing
self.assertEqual(len(entry.keys()), 6)
# the transactions are in newest-first order
self.assertEqual(entry['description'], 'Change %i' % (3 - i))
self.assertTrue('key' in entry)
# lets not assume the size will stay the same forever
self.assertTrue('size' in entry)
self.assertTrue('tid' in entry)
self.assertTrue('time' in entry)
if i:
# check times are increasing
self.assertTrue(entry['time'] < r[i - 1]['time'])
self.assertEqual(entry['user_name'], '')
def test_manage_historyCopy(self):
# we assume this works 'cos it's tested above
r = self.hi.manage_change_history()
# now we do the copy
self.hi.manage_historyCopy(keys=[r[2]['key']])
# do a commit, just like ZPublisher would
transaction.commit()
# check the body is as it should be, we assume
# (hopefully not foolishly)
# that all other attributes will behave the same
self.assertEqual(self.hi.title,
'First title')
...@@ -30,7 +30,6 @@ from App.Common import package_home ...@@ -30,7 +30,6 @@ from App.Common import package_home
from DateTime.DateTime import DateTime from DateTime.DateTime import DateTime
from OFS.Cache import Cacheable from OFS.Cache import Cacheable
from OFS.SimpleItem import SimpleItem from OFS.SimpleItem import SimpleItem
from OFS.History import Historical, html_diff
from OFS.PropertyManager import PropertyManager from OFS.PropertyManager import PropertyManager
from OFS.Traversable import Traversable from OFS.Traversable import Traversable
from Shared.DC.Scripts.Script import Script from Shared.DC.Scripts.Script import Script
...@@ -74,7 +73,7 @@ class Src(Explicit): ...@@ -74,7 +73,7 @@ class Src(Explicit):
InitializeClass(Src) InitializeClass(Src)
class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable, class ZopePageTemplate(Script, PageTemplate, Cacheable,
Traversable, PropertyManager): Traversable, PropertyManager):
"Zope wrapper for Page Template using TAL, TALES, and METAL" "Zope wrapper for Page Template using TAL, TALES, and METAL"
...@@ -92,7 +91,6 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable, ...@@ -92,7 +91,6 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
{'label': 'Edit', 'action': 'pt_editForm'}, {'label': 'Edit', 'action': 'pt_editForm'},
{'label': 'Test', 'action': 'ZScriptHTML_tryForm'}, {'label': 'Test', 'action': 'ZScriptHTML_tryForm'},
) + PropertyManager.manage_options \ ) + PropertyManager.manage_options \
+ Historical.manage_options \
+ SimpleItem.manage_options \ + SimpleItem.manage_options \
+ Cacheable.manage_options + Cacheable.manage_options
...@@ -265,13 +263,6 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable, ...@@ -265,13 +263,6 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
"""Parameters to test the script with.""" """Parameters to test the script with."""
return [] return []
def manage_historyCompare(self, rev1, rev2, REQUEST,
historyComparisonResults=''):
return ZopePageTemplate.inheritedAttribute(
'manage_historyCompare')(
self, rev1, rev2, REQUEST,
historyComparisonResults=html_diff(rev1._text, rev2._text))
def pt_getContext(self, *args, **kw): def pt_getContext(self, *args, **kw):
root = None root = None
meth = aq_get(self, 'getPhysicalRoot', None) meth = aq_get(self, 'getPhysicalRoot', None)
...@@ -339,12 +330,6 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable, ...@@ -339,12 +330,6 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
finally: finally:
security.removeContext(self) security.removeContext(self)
security.declareProtected(
change_page_templates,
'manage_historyCopy',
'manage_beforeHistoryCopy',
'manage_afterHistoryCopy')
if bbb.HAS_ZSERVER: if bbb.HAS_ZSERVER:
security.declareProtected(change_page_templates, 'PUT') security.declareProtected(change_page_templates, 'PUT')
def PUT(self, REQUEST, RESPONSE): def PUT(self, REQUEST, RESPONSE):
......
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