[Zope3-checkins] CVS: Zope3/src/zope/app/undo - __init__.py:1.1
browser.py:1.1 configure.zcml:1.1 interfaces.py:1.1
undo.py:1.1 undo_log.pt:1.1
Philipp von Weitershausen
philikon at philikon.de
Mon Mar 1 09:16:57 EST 2004
Update of /cvs-repository/Zope3/src/zope/app/undo
In directory cvs.zope.org:/tmp/cvs-serv25659/undo
Added Files:
__init__.py browser.py configure.zcml interfaces.py undo.py
undo_log.pt
Log Message:
Moved all undo-related code to zope.app.undo.
=== Added File Zope3/src/zope/app/undo/__init__.py ===
# make this directory a package
=== Added File Zope3/src/zope/app/undo/browser.py ===
##############################################################################
#
# Copyright (c) 2004 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Undo view
$Id: browser.py,v 1.1 2004/03/01 14:16:56 philikon Exp $
"""
from zope.app import zapi
from zope.app.undo.interfaces import IUndoManager
class UndoView:
"""Undo view
"""
def action(self, id_list):
"""processes undo form and redirects to form again (if possible)"""
utility = zapi.getUtility(self.context, IUndoManager)
utility.undoTransaction(id_list)
self.request.response.redirect('index.html')
def getUndoInfo(self, first=0, last=-20, user_name=None):
utility = zapi.getUtility(self.context, IUndoManager)
info = utility.getUndoInfo(first, last, user_name)
formatter = self.request.locale.dates.getFormatter('dateTime', 'medium')
for entry in info:
entry['datetime'] = formatter.format(entry['datetime'])
return info
=== Added File Zope3/src/zope/app/undo/configure.zcml ===
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:event="http://namespaces.zope.org/event"
>
<event:subscribe
subscriber=".undo.undoSetup"
event_types="zope.app.interfaces.event.IDatabaseOpenedEvent"
/>
<!-- Browser directives -->
<browser:pages
for="*"
permission="zope.ManageContent"
class="zope.app.undo.browser.UndoView"
>
<browser:page name="undoForm.html" template="undo_log.pt" />
<browser:page name="undo.html" attribute="action" />
</browser:pages>
<browser:menuItem
for="*"
menu="zmi_actions"
title="Undo"
action="@@undoForm.html"
/>
</configure>
=== Added File Zope3/src/zope/app/undo/interfaces.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
from zope.interface import Interface
class IUndoManager(Interface):
" Interface for the Undo Manager "
def getUndoInfo(first=0, last=-20, user_name=None):
"""
Gets some undo information. It skips the 'first' most
recent transactions; i.e. if first is N, then the first
transaction returned will be the Nth transaction.
If last is less than zero, then its absolute value is the
maximum number of transactions to return. Otherwise if last
is N, then only the N most recent transactions following start
are considered.
If user_name is not None, only transactions from the given
user_name are returned.
Note: at the moment, doesnt care where called from
returns sequence of mapping objects by date desc
keys of mapping objects:
id -> internal id for zodb
user_name -> name of user that last accessed the file
time -> unix timestamp of last access
datetime -> datetime object of time
description -> transaction description
"""
def undoTransaction(id_list):
"""
id_list will be a list of transaction ids.
iterate over each id in list, and undo
the transaction item.
"""
=== Added File Zope3/src/zope/app/undo/undo.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: undo.py,v 1.1 2004/03/01 14:16:56 philikon Exp $
"""
from datetime import datetime
from zope.interface import implements
from zope.app import zapi
from zope.app.event import function
from zope.app.undo.interfaces import IUndoManager
from zope.app.services.servicenames import Utilities
def undoSetup(event):
# setup undo functionality
svc = zapi.getService(None, Utilities)
svc.provideUtility(IUndoManager, ZODBUndoManager(event.database))
undoSetup = function.Subscriber(undoSetup)
class ZODBUndoManager:
"""Implement the basic undo management api for a single ZODB database."""
implements(IUndoManager)
def __init__(self, db):
self.__db = db
def getUndoInfo(self, first=0, last=-20, user_name=None):
"""See zope.app.undo.interfaces.IUndoManager"""
# Entries are a list of dictionaries, containing
# id -> internal id for zodb
# user_name -> name of user that last accessed the file
# time -> unix timestamp of last access
# description -> transaction description
if user_name is not None:
# !?&%!! The 'user' in the transactions is some combination
# of 'path' and 'user'. 'path' seems to only ever be '/' at
# the moment - I can't find anything that calls it :-(
# At the moment the path is hacked onto the user_name in the
# PageTemplate 'undo_log.pt' (to minimise the nastiness).
specification = {'user_name':user_name}
else:
specification = None
entries = self.__db.undoInfo(first, last, specification)
# We walk through the entries, augmenting the dictionaries
# with some additional items (at the moment, datetime, a useful
# form of the unix timestamp).
for e in entries:
e['datetime'] = datetime.fromtimestamp(e['time'])
return entries
def undoTransaction(self, id_list):
'''See zope.app.undo.interfaces.IUndoManager'''
for id in id_list:
self.__db.undo(id)
=== Added File Zope3/src/zope/app/undo/undo_log.pt ===
<html metal:use-macro="views/standard_macros/page">
<head>
<title i18n:translate="">Undo Title</title>
<link rel="stylesheet" type="text/css" href="/manage_page_style.css" />
</head>
<body>
<div metal:fill-slot="body">
<form action="@@undo.html" method="post"
tal:define="first python:int(request.get('first',0));
all python:request.get('all', None)">
<p class="form-help" i18n:translate="">
This application's transactional feature allows you to easily undo
changes made to the application's settings or data. You can revert the
application to a "snapshot" of it's state at a previous point
in time.
</p>
<p class="form-help" i18n:translate="">
Select one or more transactions below and then click on the
"Undo" button to undo those transactions. Note that even
though a transaction is shown below, you may not be able to undo it if
later transactions modified objects that were modified by a selected
transaction.
</p>
<span tal:condition="all">
<p i18n:translate="">
You are
<span tal:replace="request/user/getId"
i18n:name="username">username</span>,
looking at all transactions. <a href="?">View only your own
transactions</a>.
</p>
<span tal:omit-tag=""
tal:define="global undoInfo python:view.getUndoInfo(first=first)"/>
</span>
<span tal:condition="not:all">
<p i18n:translate="">You are
<span tal:replace="request/user/getId"
i18n:name="username">username</span>,
looking at your own transactions.
<a href="?all=yes">View everyone's transactions</a>.
</p>
<span tal:omit-tag=""
tal:define="global undoInfo python:view.getUndoInfo(first=first,
user_name=request.user.getId())"/>
</span>
<p>
<a tal:attributes="href python:'?first=%s'%(first+20)"
i18n:translate="">View 20 earlier transactions</a>
</p>
<a name="t_list" />
<table width="100%" cellspacing="0" cellpadding="2" border="0" >
<div tal:repeat="undoitem undoInfo">
<span tal:condition="repeat/undoitem/odd" >
<span tal:define="global rowclass string:content odd"/>
</span>
<span tal:condition="repeat/undoitem/even">
<span tal:define="global rowclass string:content even"/>
</span>
<tr tal:attributes="class rowclass">
<td width="16" align="left" valign="top">
<input type="checkbox" name="id_list:list" value="-1"
tal:attributes="value undoitem/id"/>
</td>
<td tal:attributes="class rowclass" align="left" valign="top">
<div class="list-item">
<i tal:condition="not:undoitem/description"
i18n:translate="">
no description available
</i>
<span tal:condition="undoitem/description" tal:omit-tag=""
tal:content="undoitem/description">description goes here</span>
<span tal:condition="undoitem/user_name" tal:omit-tag=""
i18n:translate=""> by
<strong tal:content="undoitem/user_name"
i18n:name="username">user_name</strong>
</span>
</div>
</td>
<td align="right" valign="top" colspan="2" nowrap>
<div class="list-item" tal:content="undoitem/datetime">
blah date
</div>
</td>
</tr>
</div>
<tr>
<td>
<input type="submit" value="Undo"
i18n:attributes="value undo-button"/>
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
More information about the Zope3-Checkins
mailing list