Changeset 6468 for main/waeup.sirp/trunk
- Timestamp:
- 23 Jun 2011, 10:04:43 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/objecthistory.py
r6338 r6468 21 21 ## 22 22 import grok 23 from datetime import datetime 23 24 from persistent.list import PersistentList 24 25 from zope.annotation.interfaces import IAnnotations 25 26 from waeup.sirp.interfaces import IObjectHistory, IWAeUPObject 27 from waeup.sirp.utils.helpers import get_current_principal 26 28 27 29 class ObjectHistory(grok.Adapter): 28 30 """A history for objects. 31 32 For any object implementing `IWAeUPObject` which is annotatable, 33 we provide histories. A history for such an object can be obtained 34 by adapting it to `IObjectHistory`. 29 35 """ 30 36 grok.context(IWAeUPObject) 31 grok. provides(IObjectHistory)37 grok.implements(IObjectHistory) 32 38 33 39 history_key = 'waeup.history' … … 43 49 @property 44 50 def messages(self): 51 """Get all messages as a persistent list of strings. 52 """ 45 53 return self._getMessages() 46 54 47 55 def addMessage(self, msg): 56 """Add the message (history entry) in msg. 57 58 Any message will be stored with a timestamp and the current 59 user (principal). 60 """ 48 61 msgs = self._getMessages() 62 timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") 63 user = get_current_principal() 64 if user is None: 65 user = 'system' 66 else: 67 user = '%s (%s)' % (user.id, user.title) 68 msg = '%s - %s - %s' % (timestamp, user, msg) 49 69 msgs.append(msg) 50 70 self._annotations[self.history_key] = msgs
Note: See TracChangeset for help on using the changeset viewer.