Package Products :: Package ZenWidgets :: Module PersistentMessage |
[hide private]
[frames] | no frames]

# Source Code for Module Products.ZenWidgets.PersistentMessage

     1  ###########################################################################
     2  #
     3  # This program is part of Zenoss Core, an open source monitoring platform.
     4  # Copyright (C) 2007, Zenoss Inc.
     5  #
     6  # This program is free software; you can redistribute it and/or modify it
     7  # under the terms of the GNU General Public License version 2 as published by
     8  # the Free Software Foundation.
     9  #
    10  # For complete information please visit: http://www.zenoss.com/oss/
    11  #
    12  ###########################################################################
    13  __doc__ = """
    14  This is in a separate module to prevent recursive import.
    15  """
    16
    17  import time
    18  from zope.interface import implements
    19
    20  from Products.ZenModel.ZenModelRM import ZenModelRM
    21  from Products.ZenRelations.RelSchema import *
    22  from Products.ZenWidgets.interfaces import IMessage
    23  from Products.ZenWidgets.messaging import INFO
    24
    25 -class PersistentMessage(ZenModelRM):
    26      """
    27      A single message. Messages are stored as relations on UserSettings and in
    28      the session object.
    29      """
    30      implements(IMessage)
    31
    32      _relations = (("messageQueue", ToOne(
    33        ToManyCont, "Products.ZenModel.UserSettings.UserSettings", "messageQueue")
    34      ),)
    35
    36      title = None
    37      body = None
    38      timestamp = None
    39      priority = None
    40      _read = False
    41
    42 -    def __init__(self, id, title, body, priority=INFO, image=None):
    43          """
    44          Initialization method.
    45
    46          @param title: The message title
    47          @type title: str
    48          @param body: The body of the message
    49          @type body: str
    50          @param priority: Message priority; one of INFO, WARNING, CRITICAL
    51          @type priority: int
    52          @param image: Optional URL of an image to be displayed in the message
    53          @type image: str
    54          """
    55          super(PersistentMessage, self).__init__(id)
    56          self.title = title
    57          self.body = body
    58          self.priority = priority
    59          self.image = image
    60          self.timestamp = time.time()
    61
    62 -    def mark_as_read(self):
    63          """
    64          Mark this message as read.
    65          """
    66          self._read = True
    67
    68 -    def delete(self):
    69          """
    70          Delete this message from the system.
    71          """
    72          self.__primary_parent__._delObject(self.id)
    73