Package Products :: Package ZenModel :: Module Location
[hide private]
[frames] | no frames]

Source Code for Module Products.ZenModel.Location

  1  ############################################################################## 
  2  #  
  3  # Copyright (C) Zenoss, Inc. 2007, 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  __doc__="""Location 
 12   
 13  $Id: Location.py,v 1.12 2004/04/22 19:08:47 edahl Exp $""" 
 14   
 15  __version__ = "$Revision: 1.12 $"[11:-2] 
 16   
 17  from Globals import InitializeClass 
 18  from Globals import DTMLFile 
 19   
 20  from AccessControl import ClassSecurityInfo 
 21   
 22  from AccessControl import Permissions as permissions 
 23   
 24  from Products.ZenRelations.RelSchema import * 
 25   
 26  from DeviceOrganizer import DeviceOrganizer 
 27  from ZenPackable import ZenPackable 
 28   
 29  from Products.ZenUtils.jsonutils import json 
30 31 -def manage_addLocation(context, id, description = "", 32 address="", REQUEST = None):
33 """make a Location""" 34 loc = Location(id, description) 35 context._setObject(id, loc) 36 loc.description = description 37 loc.address = address 38 if REQUEST is not None: 39 REQUEST['RESPONSE'].redirect(context.absolute_url() +'/manage_main')
40 41 42 addLocation = DTMLFile('dtml/addLocation',globals())
43 44 45 -class Location(DeviceOrganizer, ZenPackable):
46 """ 47 Location is a DeviceGroup Organizer that manages physical device Locations. 48 """ 49 50 # Organizer configuration 51 dmdRootName = "Locations" 52 53 address = '' 54 55 portal_type = meta_type = event_key = 'Location' 56 57 _properties = DeviceOrganizer._properties + ( 58 {'id':'address','type':'string','mode':'w'}, 59 ) 60 61 _relations = DeviceOrganizer._relations + ZenPackable._relations + ( 62 ("devices", ToMany(ToOne,"Products.ZenModel.Device","location")), 63 ("networks", ToMany(ToOne,"Products.ZenModel.IpNetwork","location")), 64 ) 65 66 # Screen action bindings (and tab definitions) 67 factory_type_information = ( 68 { 69 'immediate_view' : 'deviceOrganizerStatus', 70 'actions' : 71 ( 72 { 'id' : 'status' 73 , 'name' : 'Status' 74 , 'action' : 'deviceOrganizerStatus' 75 , 'permissions' : (permissions.view,) 76 }, 77 { 'id' : 'events' 78 , 'name' : 'Events' 79 , 'action' : 'viewEvents' 80 , 'permissions' : (permissions.view,) 81 }, 82 # { 'id' : 'historyEvents' 83 # , 'name' : 'History' 84 # , 'action' : 'viewHistoryEvents' 85 # , 'permissions' : (permissions.view,) 86 # }, 87 { 'id' : 'manage' 88 , 'name' : 'Administration' 89 , 'action' : 'deviceOrganizerManage' 90 , 'permissions' : ('Manage DMD',) 91 }, 92 { 'id' : 'geomap' 93 , 'name' : 'Map' 94 , 'action' : 'locationGeoMap' 95 , 'permissions' : (permissions.view,) 96 }, 97 ) 98 }, 99 ) 100 101 security = ClassSecurityInfo() 102
103 - def __init__(self, id, description = '', address=''):
104 super(Location, self).__init__(id, description) 105 self.address = address
106 107
108 - def setAddress(self, address):
109 """Sets the mailing address for this location""" 110 self.address = address
111 115
116 - def numMappableChildren(self):
117 children = self.children() 118 return len( 119 filter(lambda x:getattr(x, 'address', None), children) 120 )
121
122 - def getGeomapData(self):
123 """ 124 Gather data for Google Maps. This is not a JSON method; it must be put 125 into a data structure appropriate for JS consumption by another method 126 (specifically, getChildGeomapData, below). 127 """ 128 worstSeverity = self.getWorstEventSeverity() 129 colors = 'red orange yellow green green'.split() 130 colors.reverse() 131 color = 'green' 132 if worstSeverity: 133 try: 134 color = colors[worstSeverity - 1] 135 except IndexError: 136 # show green rather than error 137 pass 138 link = self.absolute_url_path() 139 linkToMap = self.numMappableChildren() 140 if linkToMap: 141 link+='/locationGeoMap' 142 summarytext = self.mapTooltip() # mapTooltip is a page template 143 return [self.address, color, link, summarytext]
144 145 @json
146 - def getChildGeomapData(self):
147 """ 148 Return info ready for Google Maps. 149 """ 150 allnodes = [] 151 data = [] 152 children = self.children() 153 allnodes.extend(children) 154 data = [x.getGeomapData() for x in allnodes if x.address] 155 if not data: data = [self.getGeomapData()] 156 return data
157
158 - def getSecondaryNodes(self):
159 """ Returns geomap info on cousin nodes that should be 160 included in the view due to outside linking. 161 """ 162 data = [] 163 # Short-circuit the method for now 164 return data
165 166 InitializeClass(Location) 167