def updateReferenceableTypes(self, updates={}, reset=False): """ Update InnerProxy referenceables types structure. This structure is a dict: {'PloneArticle': { 'files': ['File'], 'images': ['Image', 'News Item'], 'links': ['Favorite', 'Link'] }, 'ContentUsingInnerFields': {...}, } Without any param, this method will update this mapping, detecting new types/fields and preserving existing entries. @param updates: a dict like referenceable_types. Its entries will override default values (i.e constrain allowed types). Unsupported types for reference by the proxy will be ignored. @param reset: reset all mapping, allowing to reference all types supported by InnerProxies. If reset, the param 'updates' is ignored. """ at = getToolByName(self, 'archetype_tool') ref_types_info = self.referenceable_types registered_types = at.listRegisteredTypes() registered_portal_types = [i['portal_type'] for i in registered_types] pa_types = at.listPortalTypesWithInterfaces([IPloneArticle,]) proxy_types = at.listPortalTypesWithInterfaces([IBaseInnerContentProxy,]) proxy_types = [fti.getId() for fti in proxy_types] for fti in pa_types: portal_type = fti.getId() idx = registered_portal_types.index(portal_type) #ValueError no idx ## this is the schema of the PA like object schema = registered_types[idx]['schema'] if portal_type not in ref_types_info: ## this is the case when a new PA like type has just been installed ref_types_info[portal_type] = {} pti = ref_types_info[portal_type] pt_update = updates.get(portal_type, {}) for field in schema.fields(): field_name = field.getName() field_update = pt_update.get(field_name) ## I the two next tests, we will skip if field is not ## updated or reset if not isinstance(field, BaseInnerContentField): ## this field is just a simple field, not a proxy, so no update continue if ( not field_update ## we have no reference in the update table and pti.has_key(field_name) ## a field already exist and not reset ## we don't want to reset ): continue ## we look for interfaces of inner types inner_pt = field.inner_portal_type inner_class_idx = registered_portal_types.index(inner_pt) inner_class = registered_types[inner_class_idx]['klass'] ct = utils.getAllAvailableReferenceableTypes(self, inner_class) ## here we keep the old ones if reset is not wanted if field_update and not reset: new_ct = [pt for pt in ct if pt in field_update] ct = new_ct pti[field_name] = ct return
def getAllAvailableReferenceableLinkTypes(self): from Products.PloneArticle.proxy.linkinnercontent import LinkInnerContentProxy return utils.getAllAvailableReferenceableTypes(self, LinkInnerContentProxy)
def getAllAvailableReferenceableAttachmentTypes(self): from Products.PloneArticle.proxy.fileinnercontent import FileInnerContentProxy return utils.getAllAvailableReferenceableTypes(self, FileInnerContentProxy)
def updateReferenceableTypes(self, updates={}, reset=False): """ Update InnerProxy referenceables types structure. This structure is a dict: {'PloneArticle': { 'files': ['File'], 'images': ['Image', 'News Item'], 'links': ['Favorite', 'Link'] }, 'ContentUsingInnerFields': {...}, } Without any param, this method will update this mapping, detecting new types/fields and preserving existing entries. @param updates: a dict like referenceable_types. Its entries will override default values (i.e constrain allowed types). Unsupported types for reference by the proxy will be ignored. @param reset: reset all mapping, allowing to reference all types supported by InnerProxies. If reset, the param 'updates' is ignored. """ at = getToolByName(self, 'archetype_tool') ref_types_info = self.referenceable_types registered_types = at.listRegisteredTypes() registered_portal_types = [i['portal_type'] for i in registered_types] pa_types = at.listPortalTypesWithInterfaces([ IPloneArticle, ]) proxy_types = at.listPortalTypesWithInterfaces([ IBaseInnerContentProxy, ]) proxy_types = [fti.getId() for fti in proxy_types] for fti in pa_types: portal_type = fti.getId() idx = registered_portal_types.index( portal_type) #ValueError no idx ## this is the schema of the PA like object schema = registered_types[idx]['schema'] if portal_type not in ref_types_info: ## this is the case when a new PA like type has just been installed ref_types_info[portal_type] = {} pti = ref_types_info[portal_type] pt_update = updates.get(portal_type, {}) for field in schema.fields(): field_name = field.getName() field_update = pt_update.get(field_name) ## I the two next tests, we will skip if field is not ## updated or reset if not isinstance(field, BaseInnerContentField): ## this field is just a simple field, not a proxy, so no update continue if (not field_update ## we have no reference in the update table and pti.has_key(field_name) ## a field already exist and not reset ## we don't want to reset ): continue ## we look for interfaces of inner types inner_pt = field.inner_portal_type inner_class_idx = registered_portal_types.index(inner_pt) inner_class = registered_types[inner_class_idx]['klass'] ct = utils.getAllAvailableReferenceableTypes(self, inner_class) ## here we keep the old ones if reset is not wanted if field_update and not reset: new_ct = [pt for pt in ct if pt in field_update] ct = new_ct pti[field_name] = ct return
def getAllAvailableReferenceableImageTypes(self): from Products.PloneArticle.proxy.imageinnercontent import ImageInnerContentProxy return utils.getAllAvailableReferenceableTypes(self, ImageInnerContentProxy)
def getAllAvailableReferenceableLinkTypes(self): from Products.PloneArticle.proxy.linkinnercontent import LinkInnerContentProxy return utils.getAllAvailableReferenceableTypes(self, LinkInnerContentProxy)
def getAllAvailableReferenceableAttachmentTypes(self): from Products.PloneArticle.proxy.fileinnercontent import FileInnerContentProxy return utils.getAllAvailableReferenceableTypes(self, FileInnerContentProxy)
def getAvailableReferenceableLinkTypes(self): return utils.getAllAvailableReferenceableTypes(self, LinkInnerContentProxy)
def getAllAvailableReferenceableImageTypes(self): from Products.PloneArticle.proxy.imageinnercontent import ImageInnerContentProxy return utils.getAllAvailableReferenceableTypes(self, ImageInnerContentProxy)
def getAvailableReferenceableImageTypes(self): return utils.getAllAvailableReferenceableTypes(self, ImageInnerContentProxy)
def getAvailableReferenceableAttachmentTypes(self): return utils.getAllAvailableReferenceableTypes(self, FileInnerContentProxy)
def getAvailableReferenceableLinkTypes(self): return utils.getAllAvailableReferenceableTypes(self, LinkInnerContentProxy)
def getAvailableReferenceableImageTypes(self): return utils.getAllAvailableReferenceableTypes(self, ImageInnerContentProxy)
def getAvailableReferenceableAttachmentTypes(self): return utils.getAllAvailableReferenceableTypes(self, FileInnerContentProxy)