Package ZenRelations :: Module RelCopySupport
[hide private]
[frames] | no frames]

Source Code for Module ZenRelations.RelCopySupport

  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   
 14  """MultiCopySupport 
 15   
 16  MultiCopySupport over rides manage_pasteObjects in CopySupport to handle 
 17  cut/past for a MultiItem.  Semantics of cut/paste are to remove time from 
 18  current container and put it in new container but other container mappings 
 19  remain. 
 20   
 21  $Id: RelCopySupport.py,v 1.15 2004/04/13 22:02:18 edahl Exp $""" 
 22   
 23  __version__ = '$Revision: 1.15 $' 
 24   
 25  import sys 
 26  import types 
 27   
 28  # base class for RelCopyContainer 
 29  from OFS.ObjectManager import checkValidId 
 30  from OFS.CopySupport import CopyContainer 
 31   
 32  from Acquisition import aq_base 
 33  from AccessControl import getSecurityManager 
 34   
 35  from OFS import Moniker 
 36  from OFS.CopySupport import CopyError, _cb_decode, eInvalid, eNotFound, eNoData 
 37                               
 38  from App.Dialogs import MessageDialog 
 39   
 40  from Products.ZenRelations.Exceptions import * 
 41   
42 -class RelCopyContainer(CopyContainer):
43
44 - def manage_renameObject(self, id, new_id, REQUEST=None):
45 """Rename a particular sub-object""" 46 try: checkValidId(self, new_id) 47 except: raise CopyError, MessageDialog( 48 title='Invalid Id', 49 message=sys.exc_info()[1], 50 action ='manage_main') 51 ob=self._getOb(id) 52 if ob.wl_isLocked(): 53 raise ResourceLockedError( 54 'Object "%s" is locked via WebDAV' % ob.getId()) 55 if not ob.cb_isMoveable(): 56 raise CopyError, eNotSupported % escape(id) 57 self._verifyObjectPaste(ob) 58 try: ob._notifyOfCopyTo(self, op=2) # -EAD add rename to semantics 59 except: raise CopyError, MessageDialog( 60 title='Rename Error', 61 message=sys.exc_info()[1], 62 action ='manage_main') 63 self._delObject(id) 64 ob = aq_base(ob) 65 ob._setId(new_id) 66 67 # Note - because a rename always keeps the same context, we 68 # can just leave the ownership info unchanged. 69 self._setObject(new_id, ob, set_owner=0) 70 ob = self._getOb(new_id) 71 ob._postCopy(self, op=1) 72 73 if REQUEST is not None: 74 return self.manage_main(self, REQUEST, update_menu=1) 75 return None
76 77
78 - def manage_linkObjects(self, ids = None, cb_copy_data=None, REQUEST=None):
79 """link objects to relationship""" 80 try: 81 relName = self._getRelName(ids) 82 oblist = self._getSourceObjects(cb_copy_data, REQUEST) 83 for obj in oblist: 84 self.manage_addRelation(relName, obj) 85 except ZenRelationsError, e: 86 if REQUEST: return MessageDialog(title = "Relationship Link Error", 87 message = str(e), action = "manage_main") 88 else: raise 89 if REQUEST: return self.manage_main(self, REQUEST)
90 91 92
93 - def manage_unlinkObjects(self, ids = None, cb_copy_data=None, REQUEST=None):
94 """unlink objects from relationship""" 95 try: 96 relName = self._getRelName(ids) 97 self.manage_removeRelation(relName) 98 except ZenRelationsError, e: 99 if REQUEST:return MessageDialog(title = "Relationship Unlink Error", 100 message = str(e), action = "manage_main") 101 else: raise 102 if REQUEST: return self.manage_main(self, REQUEST)
103 104 105
106 - def _verifyObjectPaste(self, object, validate_src=1):
107 """ 108 check to see if this object is allowed to be pasted into this path 109 """ 110 pathres = getattr(object, 'relationshipManagerPathRestriction', None) 111 if (pathres and '/'.join(self.getPhysicalPath()).find(pathres) == -1): 112 raise CopyError, MessageDialog(title='Not Supported', 113 message='The object <EM>%s</EM> can not be pasted into' \ 114 ' the path <EM>%s</EM>' % 115 (object.id, '/'.join(self.getPhysicalPath())), 116 action='manage_main') 117 CopyContainer._verifyObjectPaste(self,object,validate_src)
118 119
120 - def _getRelName(self, ids):
121 """ 122 Return our relationship name from the UI. 123 If there is more than one id defined raise because only one 124 target relationship can be defined. If no ids are defined 125 check to see that we are a ToManyRelationship and return self.id. 126 """ 127 if not ids: 128 if self.meta_type == "ToManyRelationship": 129 return self.getId() 130 else: 131 raise ZenRelationsError("No relation name defined") 132 if type(ids) == types.StringType: return ids 133 if len(ids) > 1: 134 raise ZenRelationsError("You can only link to one relationship!") 135 return ids[0]
136 137 152 153 154 155
156 - def _getSourceObjects(self, cb_copy_data, REQUEST):
157 """get the source objects to link""" 158 cp=None 159 if cb_copy_data is not None: 160 cp=cb_copy_data 161 else: 162 if REQUEST and REQUEST.has_key('__cp'): 163 cp=REQUEST['__cp'] 164 if cp is None: 165 raise CopyError, eNoData 166 167 try: cp=_cb_decode(cp) 168 except: raise CopyError, eInvalid 169 170 oblist=[] 171 op=cp[0] 172 app = self.getPhysicalRoot() 173 174 for mdata in cp[1]: 175 m = Moniker.loadMoniker(mdata) 176 try: ob = m.bind(app) 177 except: raise CopyError, eNotFound 178 self._verifyObjectLink() 179 oblist.append(ob) 180 return oblist
181