Ignore:
Timestamp:
23 Jun 2011, 10:04:43 (13 years ago)
Author:
uli
Message:

Let object history add timestamp and current user.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/objecthistory.py

    r6338 r6468  
    2121##
    2222import grok
     23from datetime import datetime
    2324from persistent.list import PersistentList
    2425from zope.annotation.interfaces import IAnnotations
    2526from waeup.sirp.interfaces import IObjectHistory, IWAeUPObject
     27from waeup.sirp.utils.helpers import get_current_principal
    2628
    2729class ObjectHistory(grok.Adapter):
    2830    """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`.
    2935    """
    3036    grok.context(IWAeUPObject)
    31     grok.provides(IObjectHistory)
     37    grok.implements(IObjectHistory)
    3238
    3339    history_key = 'waeup.history'
     
    4349    @property
    4450    def messages(self):
     51        """Get all messages as a persistent list of strings.
     52        """
    4553        return self._getMessages()
    4654
    4755    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        """
    4861        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)
    4969        msgs.append(msg)
    5070        self._annotations[self.history_key] = msgs
Note: See TracChangeset for help on using the changeset viewer.