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

Source Code for Module Products.Zuul.routers.nav

  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 Navigation 
 13   
 14  Available at:  /zport/dmd/detailnav_router 
 15  """ 
 16   
 17  import logging 
 18  from Products.ZenUtils.Ext import DirectRouter 
 19  from Products.ZenUtils.extdirect.router import DirectResponse 
 20  from Products.ZenUI3.security.security import permissionsForContext 
 21  from Products.ZenUtils.Utils import zenPath 
 22  # page stats logger 
 23  log = logging.getLogger('zen.pagestats') 
 24  # create file handler which logs even debug messages 
 25  fh = logging.FileHandler(zenPath('log' + '/pagestats.log')) 
 26  # create formatter and add it to the handlers 
 27  formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') 
 28  fh.setFormatter(formatter) 
 29  log.addHandler(fh) 
 30   
 31  # error log logger 
 32  errorlog = logging.getLogger('javascripterrors') 
 33  fh = logging.FileHandler(zenPath('log' + '/javascript_errors.log')) 
 34  # create formatter and add it to the handlers 
 35  formatter = logging.Formatter('%(asctime)s - %(message)s') 
 36  fh.setFormatter(formatter) 
 37  errorlog.addHandler(fh) 
 38   
 39   
40 -class DetailNavRouter(DirectRouter):
41 """ 42 Router to Details navigation for given uid 43 """ 44
45 - def _getLinkMenuItems(self, menuIds, ob):
46 def filterFn(menu): 47 return not menu.isdialog
48 items = filter(filterFn, self._getMenuItems(menuIds, ob)) 49 return items
50
51 - def _getDialogMenuItems(self, menuIds, ob):
52 def filterFn(menu): 53 return menu.isdialog
54 items = filter(filterFn, self._getMenuItems(menuIds, ob)) 55 return items 56
57 - def _getMenuItems(self, menuIds, ob):
58 linkMenus = [] 59 menus = ob.getMenus(menuIds) 60 if menus: 61 if isinstance(menus, list): 62 menus = [menus]; 63 else: 64 menus = menus.values() 65 for menuItems in menus: 66 for menuItem in menuItems: 67 linkMenus.append(menuItem) 68 return linkMenus
69
70 - def getDetailNavConfigs(self, uid=None, menuIds=None):
71 """ 72 return a list of Detail navigation configurations. Can be used to create 73 navigation links. Format is: 74 { 75 id: <id of the configuration>, 76 'viewName': <view to display>, 77 'xtype': <Ext type for the panel>, 78 'text': <display name of the config info> 79 } 80 """ 81 detailItems = [] 82 def convertToDetailNav(tab): 83 return { 84 'id': '%s' % tab['name'].lower(), 85 'xtype': 'backcompat', 86 'viewName': tab['action'], 87 'text': tab['name'] 88 }
89 def menuToNav(menu): 90 return { 91 'id': '%s' % menu.id.lower(), 92 'xtype': 'backcompat', 93 'viewName': menu.action, 94 'text': menu.description 95 } 96 97 if uid: 98 ob = self.context.dmd.unrestrictedTraverse(uid) 99 tabs = ob.zentinelTabs('') 100 detailItems = [ convertToDetailNav(tab) for tab in tabs ] 101 #get menu items that are not dialogs 102 if menuIds: 103 menus = self._getLinkMenuItems(menuIds, ob) 104 if menus: 105 detailItems.extend(menuToNav(menu) for menu in menus) 106 return DirectResponse(detailConfigs=detailItems) 107
108 - def getContextMenus(self, uid=None, menuIds=None):
109 if uid: 110 ob = self.context.dmd.unrestrictedTraverse(uid) 111 menuItems = [] 112 if menuIds: 113 menus = self._getDialogMenuItems(menuIds, ob) 114 def menuToConfig(menu): 115 return { 116 'id': '%s' % menu.id.lower(), 117 'viewName': menu.action, 118 'text': menu.description 119 }
120 if menus: 121 menuItems.extend(menuToConfig(menu) for menu in menus) 122 return DirectResponse(menuItems=menuItems) 123
124 - def getSecurityPermissions(self, uid):
125 """ 126 returns a dictionary of all the permissions a 127 user has on the context 128 """ 129 obj = self.context.dmd.unrestrictedTraverse(uid) 130 permissions = permissionsForContext(obj) 131 return DirectResponse.succeed(data=permissions)
132
133 - def recordPageLoadTime(self, page, time):
134 user = self.context.zport.dmd.ZenUsers.getUserSettings() 135 log.info("PAGELOADTIME: %s %s %s (seconds)", user.id, page, time)
136
137 - def logErrorMessage(self, msg="", url="", file="", lineNumber=""):
138 """ 139 Records an error message from the client. 140 """ 141 user = self.context.zport.dmd.ZenUsers.getUserSettings() 142 errorlog.error("User: %s - %s '%s' at %s line:%s", user.id, url, msg, file, lineNumber)
143