def _moveDevices(self, uids, target): # Resolve target if a path if isinstance(target, basestring): target = self._getObject(target) assert isinstance(target, DeviceOrganizer) devs = (self._getObject(uid) for uid in uids) targetname = target.getOrganizerName() exports = 0 if isinstance(target, DeviceGroup): for dev in devs: paths = set(dev.getDeviceGroupNames()) paths.add(targetname) dev.setGroups(list(paths)) notify(ObjectAddedToOrganizerEvent(dev, target)) elif isinstance(target, System): for dev in devs: paths = set(dev.getSystemNames()) paths.add(targetname) dev.setSystems(list(paths)) notify(ObjectAddedToOrganizerEvent(dev, target)) elif isinstance(target, Location): for dev in devs: if dev.location(): notify(ObjectRemovedFromOrganizerEvent( dev, dev.location())) dev.setLocation(targetname) notify(ObjectAddedToOrganizerEvent(dev, target)) elif isinstance(target, DeviceClass): exports = self._dmd.Devices.moveDevices(targetname, [dev.id for dev in devs]) return exports
def _moveDevices(self, uids, target): # Resolve target if a path if isinstance(target, basestring): target = self._getObject(target) assert isinstance(target, DeviceOrganizer) devs = (self._getObject(uid) for uid in uids) targetname = target.getOrganizerName() moved_devices_count = 0 success = False remodel_required = False if isinstance(target, DeviceGroup): for dev in devs: paths = set(dev.getDeviceGroupNames()) paths.add(targetname) dev.setGroups(list(paths)) notify(ObjectAddedToOrganizerEvent(dev, target)) success = True elif isinstance(target, System): for dev in devs: paths = set(dev.getSystemNames()) paths.add(targetname) dev.setSystems(list(paths)) notify(ObjectAddedToOrganizerEvent(dev, target)) success = True elif isinstance(target, Location): for dev in devs: if dev.location(): notify(ObjectRemovedFromOrganizerEvent( dev, dev.location())) dev.setLocation(targetname) notify(ObjectAddedToOrganizerEvent(dev, target)) success = True elif isinstance(target, DeviceClass): moved_devices_count = self._dmd.Devices.moveDevices( targetname, [dev.id for dev in devs]) success = True remodel_required = True result = { 'success': success, 'message': 'The %s devices have been moved' % moved_devices_count, 'remodel_required': remodel_required } return result