本文整理汇总了Python中ggrc.models.reflection.AttributeInfo.gather_attrs方法的典型用法代码示例。如果您正苦于以下问题:Python AttributeInfo.gather_attrs方法的具体用法?Python AttributeInfo.gather_attrs怎么用?Python AttributeInfo.gather_attrs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ggrc.models.reflection.AttributeInfo
的用法示例。
在下文中一共展示了AttributeInfo.gather_attrs方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_properties
# 需要导入模块: from ggrc.models.reflection import AttributeInfo [as 别名]
# 或者: from ggrc.models.reflection.AttributeInfo import gather_attrs [as 别名]
def _get_properties(self, obj):
"""Get indexable properties and values.
Properties should be returned in the following format:
{
property1: {
subproperty1: value1,
subproperty2: value2,
...
},
...
}
If there is no subproperty - empty string is used as a key
"""
if obj.type == "Snapshot":
# Snapshots do not have any indexable content. The object content for
# snapshots is stored in the revision. Snapshots can also be made for
# different models so we have to get fulltext attrs for the actual child
# that was snapshotted and get data for those from the revision content.
tgt_class = getattr(ggrc.models.all_models, obj.child_type, None)
if not tgt_class:
return {}
attrs = AttributeInfo.gather_attrs(tgt_class, '_fulltext_attrs')
return {attr: {"": obj.revision.content.get(attr)} for attr in attrs}
return {attr: {"": getattr(obj, attr)} for attr in self._fulltext_attrs}
示例2: _get_model_properties
# 需要导入模块: from ggrc.models.reflection import AttributeInfo [as 别名]
# 或者: from ggrc.models.reflection.AttributeInfo import gather_attrs [as 别名]
def _get_model_properties():
"""Get indexable properties for all snapshottable objects
Args:
None
Returns:
tuple(class_properties dict, custom_attribute_definitions dict) - Tuple of
dictionaries, first one representing a list of searchable attributes
for every model and second one representing dictionary of custom
attribute definition attributes.
"""
# pylint: disable=protected-access
from ggrc.models import all_models
class_properties = dict()
klass_names = Types.all
cadef_klass_names = {
getattr(all_models, klass)._inflector.table_singular
for klass in klass_names
}
cad_query = db.session.query(
models.CustomAttributeDefinition.id,
models.CustomAttributeDefinition.title,
).filter(
models.CustomAttributeDefinition.definition_type.in_(cadef_klass_names)
)
for klass_name in klass_names:
model_attributes = AttributeInfo.gather_attrs(
getattr(all_models, klass_name), '_fulltext_attrs')
class_properties[klass_name] = model_attributes
return class_properties, cad_query.all()
示例3: get_fulltext_attrs
# 需要导入模块: from ggrc.models.reflection import AttributeInfo [as 别名]
# 或者: from ggrc.models.reflection.AttributeInfo import gather_attrs [as 别名]
def get_fulltext_attrs(cls):
# type: () -> Dict[unicode, fulltext.attributes.FullTextAttr]
"""Get all fulltext attributes represented as FullTextAttribute objects """
raw_attrs = AttributeInfo.gather_attrs(cls, '_fulltext_attrs')
# Convert attrs represented as string into FullTextAttr objects
attrs = [attr if isinstance(attr, fulltext.attributes.FullTextAttr) else
fulltext.attributes.FullTextAttr(attr, attr)
for attr in raw_attrs]
return attrs
示例4: get_fulltext_parsed_value
# 需要导入模块: from ggrc.models.reflection import AttributeInfo [as 别名]
# 或者: from ggrc.models.reflection.AttributeInfo import gather_attrs [as 别名]
def get_fulltext_parsed_value(klass, key):
"""Get fulltext parser if it's exists """
attrs = AttributeInfo.gather_attrs(klass, '_fulltext_attrs')
if not issubclass(klass, Indexed):
return
for attr in attrs:
if isinstance(attr, FullTextAttr) and attr.with_template:
attr_key = klass.PROPERTY_TEMPLATE.format(attr.alias)
elif isinstance(attr, FullTextAttr):
attr_key = attr.alias
else:
attr_key = klass.PROPERTY_TEMPLATE.format(attr)
attr = FullTextAttr(key, key)
if attr_key == key:
return attr
示例5: _get_class_properties
# 需要导入模块: from ggrc.models.reflection import AttributeInfo [as 别名]
# 或者: from ggrc.models.reflection.AttributeInfo import gather_attrs [as 别名]
def _get_class_properties():
"""Get indexable properties for all models
Args:
None
Returns:
class_properties dict - representing a list of searchable attributes
for every model
"""
class_properties = defaultdict(list)
for klass_name in Types.all:
full_text_attrs = AttributeInfo.gather_attrs(
getattr(all_models, klass_name), '_fulltext_attrs'
)
for attr in full_text_attrs:
if not isinstance(attr, FullTextAttr):
attr = FullTextAttr(attr, attr)
class_properties[klass_name].append(attr)
return class_properties
示例6: __table_args__
# 需要导入模块: from ggrc.models.reflection import AttributeInfo [as 别名]
# 或者: from ggrc.models.reflection.AttributeInfo import gather_attrs [as 别名]
def __table_args__(cls): # pylint: disable=no-self-argument
extra_table_args = AttributeInfo.gather_attrs(cls, '_extra_table_args')
table_args = []
table_dict = {}
for table_arg in extra_table_args:
if callable(table_arg):
table_arg = table_arg()
if isinstance(table_arg, (list, tuple, set)):
if isinstance(table_arg[-1], (dict,)):
table_dict.update(table_arg[-1])
table_args.extend(table_arg[:-1])
else:
table_args.extend(table_arg)
elif isinstance(table_arg, (dict,)):
table_dict.update(table_arg)
else:
table_args.append(table_arg)
if len(table_dict) > 0:
table_args.append(table_dict)
return tuple(table_args,)
示例7: _get_properties
# 需要导入模块: from ggrc.models.reflection import AttributeInfo [as 别名]
# 或者: from ggrc.models.reflection.AttributeInfo import gather_attrs [as 别名]
def _get_properties(self, obj):
"""Get indexable properties and values.
Properties should be returned in the following format:
{
property1: {
subproperty1: value1,
subproperty2: value2,
...
},
...
}
If there is no subproperty - empty string is used as a key
"""
if obj.type == "Snapshot":
# Snapshots do not have any indexable content. The object content for
# snapshots is stored in the revision. Snapshots can also be made for
# different models so we have to get fulltext attrs for the actual child
# that was snapshotted and get data for those from the revision content.
tgt_class = getattr(all_models, obj.child_type, None)
if not tgt_class:
return {}
attrs = AttributeInfo.gather_attrs(tgt_class, '_fulltext_attrs')
return {attr: {"": obj.revision.content.get(attr)} for attr in attrs}
if isinstance(obj, Indexed):
property_tmpl = obj.PROPERTY_TEMPLATE
else:
property_tmpl = u"{}"
properties = {}
for attr in self._fulltext_attrs:
if isinstance(attr, basestring):
properties[property_tmpl.format(attr)] = {"": getattr(obj, attr)}
elif isinstance(attr, FullTextAttr):
properties.update(attr.get_property_for(obj))
return properties
示例8: __init__
# 需要导入模块: from ggrc.models.reflection import AttributeInfo [as 别名]
# 或者: from ggrc.models.reflection.AttributeInfo import gather_attrs [as 别名]
def __init__(self, tgt_class, indexer):
self._fulltext_attrs = AttributeInfo.gather_attrs(
tgt_class, '_fulltext_attrs')
self.indexer = indexer
示例9: model_is_indexed
# 需要导入模块: from ggrc.models.reflection import AttributeInfo [as 别名]
# 或者: from ggrc.models.reflection.AttributeInfo import gather_attrs [as 别名]
def model_is_indexed(tgt_class):
fulltext_attrs = AttributeInfo.gather_attrs(tgt_class, '_fulltext_attrs')
return len(fulltext_attrs) > 0