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