def _addObjects(self, obj): """ Adds any objects that are specified by the featurelet's info. First checks for a previous installation of this featurelet, skips anything that was previously installed. Raises an error if content of the same id that was NOT a part of a previous installation of this featurelet exists. """ info = self._info supporter = IFeatureletSupporter(obj) objmgr = IObjectManager(obj) prior_ids = tuple() prior_info = supporter.getFeatureletDescriptor(self.id) if prior_info is not None: prior_content = prior_info.get('objects', tuple()) prior_ids = [item['id'] for item in prior_content] for item in info.get('objects', tuple()): iid = item['id'] if iid not in prior_ids: if objmgr.hasObject(iid): msg = "Object with id '%s' already exists." % iid raise zExceptions.BadRequest, msg try: newobj = item['class']() except TypeError: # might need an id passed to the constructor newobj = item['class'](iid) objmgr._setOb(iid, newobj)
def _removeObjects(self, obj, prior_info, info_key): """ Removes any objects that were added to the supporter as a result of a prior installation of this featurelet. Will not touch any objects that were not installed by this featurelet. """ prior_objects = prior_info.get(info_key) if prior_objects is None: return objmgr = IObjectManager(obj) prior_ids = [item['id'] for item in prior_objects] del_ids = [id_ for id_ in prior_ids if objmgr.hasObject(id_)] if del_ids: objmgr.manage_delObjects(ids=del_ids)