source: main/waeup.sirp/trunk/src/waeup/sirp/objecthistory.py @ 6374

Last change on this file since 6374 was 6338, checked in by uli, 13 years ago

Add component to store object related history (shouldnt this be part of logging?) as metadata.

File size: 1.7 KB
Line 
1##
2## objecthistory.py
3## Login : <uli@pu.smp.net>
4## Started on  Fri Jun 10 16:06:02 2011 Uli Fouquet
5## $Id$
6##
7## Copyright (C) 2011 Uli Fouquet
8## This program is free software; you can redistribute it and/or modify
9## it under the terms of the GNU General Public License as published by
10## the Free Software Foundation; either version 2 of the License, or
11## (at your option) any later version.
12##
13## This program is distributed in the hope that it will be useful,
14## but WITHOUT ANY WARRANTY; without even the implied warranty of
15## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16## GNU General Public License for more details.
17##
18## You should have received a copy of the GNU General Public License
19## along with this program; if not, write to the Free Software
20## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21##
22import grok
23from persistent.list import PersistentList
24from zope.annotation.interfaces import IAnnotations
25from waeup.sirp.interfaces import IObjectHistory, IWAeUPObject
26
27class ObjectHistory(grok.Adapter):
28    """A history for objects.
29    """
30    grok.context(IWAeUPObject)
31    grok.provides(IObjectHistory)
32
33    history_key = 'waeup.history'
34
35    def __init__(self, context):
36        from zope.security.proxy import removeSecurityProxy
37        self.context = removeSecurityProxy(context)
38        self._annotations = IAnnotations(self.context)
39
40    def _getMessages(self):
41        return self._annotations.get(self.history_key, PersistentList())
42
43    @property
44    def messages(self):
45        return self._getMessages()
46
47    def addMessage(self, msg):
48        msgs = self._getMessages()
49        msgs.append(msg)
50        self._annotations[self.history_key] = msgs
51        return
Note: See TracBrowser for help on using the repository browser.