Package Products :: Package Zuul :: Package routers :: Module messaging
[hide private]
[frames] | no frames]

Source Code for Module Products.Zuul.routers.messaging

 1  ############################################################################## 
 2  #  
 3  # Copyright (C) Zenoss, Inc. 2010, all rights reserved. 
 4  #  
 5  # This content is made available according to terms specified in 
 6  # License.zenoss under the directory where your Zenoss product is installed. 
 7  #  
 8  ############################################################################## 
 9   
10   
11  """ 
12  Operations for Messaging. 
13   
14  Available at:  /zport/dmd/messaging_router 
15  """ 
16  from Persistence import PersistentMapping 
17  from ZODB.transact import transact 
18  from Products.ZenUtils.Ext import DirectRouter 
19  #from Products.ZenModel.ZenossSecurity import * 
20  from Products.ZenWidgets.interfaces import IUserMessages, IBrowserMessages 
21  from Products.ZenWidgets import messaging 
22 23 24 -class MessagingRouter(DirectRouter):
25 """ 26 A JSON/ExtDirect interface to operations on messages 27 """ 28 @transact
29 - def setBrowserState(self, state):
30 """ 31 Save the browser state for the current user. 32 33 @param state: The browser state as a JSON-encoded string 34 @type state: str 35 """ 36 userSettings = self.context.dmd.ZenUsers.getUserSettings() 37 state_container = getattr(userSettings, '_browser_state', None) 38 if isinstance(state_container, basestring) or state_container is None: 39 state_container = PersistentMapping() 40 userSettings._browser_state = state_container 41 if state != state_container.get('state', ''): 42 state_container['state'] = state
43 44
45 - def clearBrowserState(self, user=None):
46 """ 47 Removes all the stored state associated with the current user 48 """ 49 if user: 50 userSettings = self.context.dmd.ZenUsers._getOb(user) 51 else: 52 userSettings = self.context.dmd.ZenUsers.getUserSettings() 53 if getattr(userSettings, '_browser_state', None): 54 del userSettings._browser_state 55 messaging.IMessageSender(self.context).sendToBrowser( 56 'Preferences Reset', 57 'Preferences reset to their default values.', 58 priority=messaging.WARNING 59 )
60
61 - def getUserMessages(self):
62 """ 63 Get the queued messages for the logged in user. 64 65 @rtype: dictionary 66 @return: B{Properties}: 67 - messages: ([string]) A list of queued messages. 68 """ 69 # user messages are stored in the logged in users "usersettings" object 70 # which must be able to access ZenUsers (off of dmd) 71 messages = IUserMessages(self.context.zport.dmd).get_unread() 72 messages.extend(IBrowserMessages(self.context).get_unread()) 73 messages.sort(key=lambda x:x.timestamp) 74 result = [] 75 for message in messages: 76 result.append(dict( 77 sticky = True if message.priority >= messaging.CRITICAL else False, 78 image = message.image, 79 title = message.title, 80 body = message.body, 81 priority = message.priority 82 )) 83 message.mark_as_read() 84 85 return { 86 'messages': result 87 }
88