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

Source Code for Module Products.ZenRelations.RelCopySupport

  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  """MultiCopySupport 
 12   
 13  MultiCopySupport over rides manage_pasteObjects in CopySupport to handle 
 14  cut/past for a MultiItem.  Semantics of cut/paste are to remove time from 
 15  current container and put it in new container but other container mappings 
 16  remain. 
 17   
 18  $Id: RelCopySupport.py,v 1.15 2004/04/13 22:02:18 edahl Exp $""" 
 19   
 20  __version__ = '$Revision: 1.15 $' 
 21   
 22  import sys 
 23  from cgi import escape 
 24   
 25  # base class for RelCopyContainer 
 26  from OFS.ObjectManager import checkValidId 
 27  from OFS.CopySupport import CopyContainer, eNotSupported 
 28   
 29  from webdav.Lockable import ResourceLockedError 
 30   
 31  from Acquisition import aq_base 
 32  from AccessControl import getSecurityManager 
 33   
 34  from OFS import Moniker 
 35  from OFS.CopySupport import CopyError, _cb_decode, eInvalid, eNotFound, eNoData 
 36                               
 37  from App.Dialogs import MessageDialog 
 38   
 39  from Products.ZenRelations.Exceptions import * 
 40   
41 -class RelCopyContainer(CopyContainer):
42
43 - def _checkId(self, new_id):
44 """This method gets called from the new manage_renameObject which 45 seems to be a bug in the Zope code. We add it until the problem is 46 fixed. 47 """ 48 checkValidId(self, new_id)
49 50
51 - def manage_linkObjects(self, ids = None, cb_copy_data=None, REQUEST=None):
52 """link objects to relationship""" 53 try: 54 relName = self._getRelName(ids) 55 oblist = self._getSourceObjects(cb_copy_data, REQUEST) 56 for obj in oblist: 57 self.manage_addRelation(relName, obj) 58 except ZenRelationsError, e: 59 if REQUEST: return MessageDialog(title = "Relationship Link Error", 60 message = str(e), action = "manage_main") 61 else: raise 62 if REQUEST: return self.manage_main(self, REQUEST)
63 64 65
66 - def manage_unlinkObjects(self, ids = None, cb_copy_data=None, REQUEST=None):
67 """unlink objects from relationship""" 68 from Products.ZenUtils.Utils import unused 69 unused(cb_copy_data) 70 try: 71 relName = self._getRelName(ids) 72 self.manage_removeRelation(relName) 73 except ZenRelationsError, e: 74 if REQUEST:return MessageDialog(title = "Relationship Unlink Error", 75 message = str(e), action = "manage_main") 76 else: raise 77 if REQUEST: return self.manage_main(self, REQUEST)
78 79 80
81 - def _verifyObjectPaste(self, object, validate_src=1):
82 """ 83 check to see if this object is allowed to be pasted into this path 84 """ 85 pathres = getattr(object, 'relationshipManagerPathRestriction', None) 86 if (pathres and '/'.join(self.getPhysicalPath()).find(pathres) == -1): 87 raise CopyError, MessageDialog(title='Not Supported', 88 message='The object <EM>%s</EM> can not be pasted into' \ 89 ' the path <EM>%s</EM>' % 90 (object.id, '/'.join(self.getPhysicalPath())), 91 action='manage_main')
92 # We don't need this it checks for meta_type permissions 93 # the check messes up zenhubs ability to rename devices 94 # CopyContainer._verifyObjectPaste(self,object,validate_src) 95 96
97 - def _getRelName(self, ids):
98 """ 99 Return our relationship name from the UI. 100 If there is more than one id defined raise because only one 101 target relationship can be defined. If no ids are defined 102 check to see that we are a ToManyRelationship and return self.id. 103 """ 104 if not ids: 105 if self.meta_type == "ToManyRelationship": 106 return self.getId() 107 else: 108 raise ZenRelationsError("No relation name defined") 109 if isinstance(ids, basestring): return ids 110 if len(ids) > 1: 111 raise ZenRelationsError("You can only link to one relationship!") 112 return ids[0]
113 114 129 130 131 132
133 - def _getSourceObjects(self, cb_copy_data, REQUEST):
134 """get the source objects to link""" 135 cp=None 136 if cb_copy_data is not None: 137 cp=cb_copy_data 138 else: 139 if REQUEST and REQUEST.has_key('__cp'): 140 cp=REQUEST['__cp'] 141 if cp is None: 142 raise CopyError, eNoData 143 144 try: cp=_cb_decode(cp) 145 except: raise CopyError, eInvalid 146 147 oblist=[] 148 app = self.getPhysicalRoot() 149 150 for mdata in cp[1]: 151 m = Moniker.loadMoniker(mdata) 152 try: ob = m.bind(app) 153 except: raise CopyError, eNotFound 154 self._verifyObjectLink() 155 oblist.append(ob) 156 return oblist
157