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 _addContent(self, obj): """ Adds any CMF content that is 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. """ ttool = getToolByName(obj, 'portal_types') 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('content', tuple()) prior_ids = [item['id'] for item in prior_content] for item in info.get('content', tuple()): if item['id'] not in prior_ids: ttool.constructContent(item['portal_type'], objmgr, item['id'], title=item['title'])
def removePackage(self, obj): """ See IFeaturelet. """ supporter = IFeatureletSupporter(obj) prior_info = supporter.getFeatureletDescriptor(self.id) if prior_info is None: return self._removeObjects(obj, prior_info, 'objects') if getToolByName is not None: self._removeObjects(obj, prior_info, 'content') self._removeMenuItems(obj, prior_info) if self.installed_marker is not None: directlyProvides(obj, directlyProvidedBy(obj) - self.installed_marker)