def get_metadata(): global METADATA_CACHE if METADATA_CACHE is None: mapping = [] for type_name, type_schema in FACTORY_CACHE.items(): mapping.extend( merged_tagged_value_list(type_schema.schema, metadata.key)) for _, utility in get_utilities_for(IBehavior): mapping.extend( merged_tagged_value_list(utility.interface, metadata.key)) METADATA_CACHE = mapping else: METADATA_CACHE return METADATA_CACHE
async def __call__(self, indexes=None, schemas=None): # For each type values = { 'type_name': self.content.type_name, 'tid': self.content.__serial__ } if schemas is None: schemas = iter_schemata(self.content) for schema in schemas: behavior = schema(self.content) loaded = False for field_name, index_data in merged_tagged_value_dict(schema, index.key).items(): index_name = index_data.get('index_name', field_name) if index_name in values or index_name in self.attempts: # you can override indexers so we do not want to index # the same value more than once continue self.attempts.append(index_name) try: # accessors we always reindex since we can't know if updated # from the indexes param--they are "fake" like indexes, not fields if 'accessor' in index_data: if (indexes is None or (len(set(index_data.get('fields', [])) & set(indexes)) > 0)): if not loaded: await self.load_behavior(behavior) loaded = True values[index_name] = await apply_coroutine( index_data['accessor'], behavior) elif (indexes is None or field_name in indexes or isinstance(getattr(type(self.content), field_name, None), property)): if not loaded: await self.load_behavior(behavior) loaded = True # in this case, properties are also dynamic so we have to make sure # to allow for them to be reindexed every time. values[index_name] = self.get_data(behavior, schema, field_name) except NoIndexField: pass for metadata_name in merged_tagged_value_list(schema, metadata.key): if (indexes is not None and metadata_name not in indexes and not isinstance(getattr(type(self.content), metadata_name, None), property)): # in this case, properties are also dynamic so we have to make sure # to allow for them to be reindexed every time. continue # skip if not loaded: await self.load_behavior(behavior) loaded = True try: values[metadata_name] = self.get_data(behavior, schema, metadata_name) except NoIndexField: pass return values
async def __call__(self): # For each type values = {} for schema in iter_schemata_for_type(self.content.portal_type): behavior = schema(self.content) for index_name, index_data in merged_tagged_value_dict( schema, index.key).items(): try: if 'accessor' in index_data: values[index_name] = await apply_coroutine( index_data['accessor'], behavior) else: values[index_name] = self.get_data( behavior, schema, index_name) except NoIndexField: pass for metadata_name in merged_tagged_value_list( schema, metadata.key): values[metadata_name] = self.get_data(behavior, schema, metadata_name) return values
def get_metadata_fields(type_name): fields = [] for schema in get_all_possible_schemas_for_type(type_name): # create mapping for content type fields.extend(merged_tagged_value_list(schema, metadata.key)) return fields
def get_metadata_fields(type_name): fields = [] for schema in get_all_possible_schemas_for_type(type_name): # create mapping for content type fields.extend(merged_tagged_value_list(schema, metadata.key)) return fields