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

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