本文整理汇总了Python中plone.behavior.interfaces.IBehaviorAssignable.enumerateBehaviors方法的典型用法代码示例。如果您正苦于以下问题:Python IBehaviorAssignable.enumerateBehaviors方法的具体用法?Python IBehaviorAssignable.enumerateBehaviors怎么用?Python IBehaviorAssignable.enumerateBehaviors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plone.behavior.interfaces.IBehaviorAssignable
的用法示例。
在下文中一共展示了IBehaviorAssignable.enumerateBehaviors方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: grabDexterityData
# 需要导入模块: from plone.behavior.interfaces import IBehaviorAssignable [as 别名]
# 或者: from plone.behavior.interfaces.IBehaviorAssignable import enumerateBehaviors [as 别名]
def grabDexterityData(self, obj):
"""
Export Dexterity schema data as dictionary object.
Snippets taken from
https://www.andreas-jung.com/contents
"""
data = {}
for key in EXPORT_ATTRIBUTES:
data[key] = getattr(obj, key, None)
from plone.dexterity.interfaces import IDexterityFTI
from plone.behavior.interfaces import IBehaviorAssignable
from zope.component import getUtility
schema = getUtility(IDexterityFTI, name=obj.portal_type).lookupSchema()
fields = [(name, schema, schema[name]) for name in schema]
assignable = IBehaviorAssignable(obj)
for behavior in assignable.enumerateBehaviors():
behavior_schema = behavior.interface
for name in behavior_schema:
fields.append((name, behavior_schema, behavior_schema[name]))
for name, schema_adaptor, field in fields:
source_adapted = schema_adaptor(obj)
data[name] = getattr(source_adapted, field.getName())
return data
示例2: __call__
# 需要导入模块: from plone.behavior.interfaces import IBehaviorAssignable [as 别名]
# 或者: from plone.behavior.interfaces.IBehaviorAssignable import enumerateBehaviors [as 别名]
def __call__(self):
context = aq_inner(self.context)
fieldname = self.request.get('fieldname')
portal_type = self.request.get('portal_type')
fti = zope.component.getUtility(IDexterityFTI, name=portal_type)
schema = fti.lookupSchema()
field = schema.get(fieldname)
if field is None:
# The field might be defined in a behavior schema
behavior_assignable = IBehaviorAssignable(context, None)
for behavior_reg in behavior_assignable.enumerateBehaviors():
behavior_schema = IFormFieldProvider(behavior_reg.interface, None)
if behavior_schema is not None:
field = behavior_schema.get(fieldname)
if field is not None:
break
vname = field.vocabularyName
factory = zope.component.getUtility(IVocabularyFactory, vname)
tree = factory(context)
# XXX: "selected" is not set in input.pt, so does it make sense to check
# for it here? Only if this json view is called elsewhere, which
# doesn't seem to be the case...
selected = self.request.get('selected', '').split('|')
return JSONWriter().write(dict2dynatree(tree, selected, True, False))
示例3: _fields
# 需要导入模块: from plone.behavior.interfaces import IBehaviorAssignable [as 别名]
# 或者: from plone.behavior.interfaces.IBehaviorAssignable import enumerateBehaviors [as 别名]
def _fields(self):
"""
"""
context = self.context
behavior_fields = []
# Stap 1 metadata
behavior_assignable = IBehaviorAssignable(context)
if behavior_assignable:
behaviors = behavior_assignable.enumerateBehaviors()
for behavior in behaviors:
behavior_fields += getFieldsInOrder(behavior.interface)
# Stap 2 eigen velden
fti = context.getTypeInfo()
schema = fti.lookupSchema()
content_fields = getFieldsInOrder(schema)
fields = behavior_fields
fields += content_fields
# for field_info in fields:
# try:
# field_name = field_info[0]
# field = field_info[1]
# print field_info
# print getattr(context, field_name)
# except Exception, e:
# pass
return fields
示例4: get_soundfile_field
# 需要导入模块: from plone.behavior.interfaces import IBehaviorAssignable [as 别名]
# 或者: from plone.behavior.interfaces.IBehaviorAssignable import enumerateBehaviors [as 别名]
def get_soundfile_field(context):
assignable = IBehaviorAssignable(context, None)
if assignable is None:
return
for behavior_registration in assignable.enumerateBehaviors():
schema = behavior_registration.interface
for tgv in mergedTaggedValueList(schema, SOUNDFILE_KEY):
if tgv.soundfile:
return tgv.soundfile
示例5: get_soundcloud_accessors
# 需要导入模块: from plone.behavior.interfaces import IBehaviorAssignable [as 别名]
# 或者: from plone.behavior.interfaces.IBehaviorAssignable import enumerateBehaviors [as 别名]
def get_soundcloud_accessors(context):
accessors = []
assignable = IBehaviorAssignable(context, None)
if assignable is None:
return accessors
for behavior_registration in assignable.enumerateBehaviors():
schema = behavior_registration.interface
for tgv in mergedTaggedValueList(schema, SOUNDCLOUD_KEY):
for accessor in tgv.accessors:
accessors.append((schema, accessor,))
return accessors
示例6: _all_fields
# 需要导入模块: from plone.behavior.interfaces import IBehaviorAssignable [as 别名]
# 或者: from plone.behavior.interfaces.IBehaviorAssignable import enumerateBehaviors [as 别名]
def _all_fields(self):
type_info = self.context.getTypeInfo()
if type_info is None:
return
schema = type_info.lookupSchema()
for field in getFieldsInOrder(schema):
yield field
behavior_assignable = IBehaviorAssignable(self.context)
if behavior_assignable:
for behavior in behavior_assignable.enumerateBehaviors():
for field in getFieldsInOrder(behavior.interface):
yield field
示例7: applyMarkers
# 需要导入模块: from plone.behavior.interfaces import IBehaviorAssignable [as 别名]
# 或者: from plone.behavior.interfaces.IBehaviorAssignable import enumerateBehaviors [as 别名]
def applyMarkers(obj, event):
"""Event handler to apply markers for all behaviors enabled
for the given type.
"""
assignable = IBehaviorAssignable(obj, None)
if assignable is None:
return
for behavior in assignable.enumerateBehaviors():
if behavior.marker is not None:
alsoProvides(obj, behavior.marker)
示例8: get_behaviors
# 需要导入模块: from plone.behavior.interfaces import IBehaviorAssignable [as 别名]
# 或者: from plone.behavior.interfaces.IBehaviorAssignable import enumerateBehaviors [as 别名]
def get_behaviors(self):
""" Iterate over all behaviors that are assigned to the object
Used code from @tisto:
https://github.com/plone/plone.restapi/blob/master/src/plone/restapi/utils.py
"""
out = {}
assignable = IBehaviorAssignable(self.context, None)
if not assignable:
return out
for behavior in assignable.enumerateBehaviors():
for name, field in getFields(behavior.interface).items():
out[name] = field
return out
示例9: _image_field_info
# 需要导入模块: from plone.behavior.interfaces import IBehaviorAssignable [as 别名]
# 或者: from plone.behavior.interfaces.IBehaviorAssignable import enumerateBehaviors [as 别名]
def _image_field_info(self):
type_info = self.context.getTypeInfo()
schema = type_info.lookupSchema()
fields = getFieldsInOrder(schema)
behavior_assignable = IBehaviorAssignable(self.context)
if behavior_assignable:
behaviors = behavior_assignable.enumerateBehaviors()
for behavior in behaviors:
fields += getFieldsInOrder(behavior.interface)
for fieldname, field in fields:
img_field = getattr(self.context, fieldname, None)
if img_field and IImage.providedBy(img_field):
yield (fieldname, img_field)
示例10: getAdditionalSchemata
# 需要导入模块: from plone.behavior.interfaces import IBehaviorAssignable [as 别名]
# 或者: from plone.behavior.interfaces.IBehaviorAssignable import enumerateBehaviors [as 别名]
def getAdditionalSchemata(context=None, portal_type=None):
"""Get additional schemata for this context or this portal_type.
Additional schemata can be defined in behaviors.
Usually either context or portal_type should be set, not both.
The idea is that for edit forms or views you pass in a context
(and we get the portal_type from there) and for add forms you pass
in a portal_type (and the context is irrelevant then). If both
are set, the portal_type might get ignored, depending on which
code path is taken.
"""
log.debug("getAdditionalSchemata with context %r and portal_type %s",
context, portal_type)
if context is None and portal_type is None:
return
if context:
behavior_assignable = IBehaviorAssignable(context, None)
else:
behavior_assignable = None
if behavior_assignable is None:
log.debug("No behavior assignable found, only checking fti.")
# Usually an add-form.
if portal_type is None:
portal_type = context.portal_type
fti = getUtility(IDexterityFTI, name=portal_type)
for behavior_name in fti.behaviors:
behavior_interface = None
behavior_instance = queryUtility(IBehavior, name=behavior_name)
if not behavior_instance:
try:
behavior_interface = resolveDottedName(behavior_name)
except (ValueError, ImportError):
log.warning("Error resolving behaviour %s", behavior_name)
continue
else:
behavior_interface = behavior_instance.interface
if behavior_interface is not None:
behavior_schema = IFormFieldProvider(behavior_interface, None)
if behavior_schema is not None:
yield behavior_schema
else:
log.debug("Behavior assignable found for context.")
for behavior_reg in behavior_assignable.enumerateBehaviors():
behavior_schema = IFormFieldProvider(behavior_reg.interface, None)
if behavior_schema is not None:
yield behavior_schema
示例11: get_all_fields
# 需要导入模块: from plone.behavior.interfaces import IBehaviorAssignable [as 别名]
# 或者: from plone.behavior.interfaces.IBehaviorAssignable import enumerateBehaviors [as 别名]
def get_all_fields(context):
""" Return all fields (including behavior fields) of a context object
as dict fieldname -> field.
"""
schema = zope.component.getUtility(
IDexterityFTI, name=context.portal_type).lookupSchema()
fields = dict((fieldname, schema[fieldname]) for fieldname in schema)
assignable = IBehaviorAssignable(context)
for behavior in assignable.enumerateBehaviors():
behavior_schema = behavior.interface
fields.update((name, behavior_schema[name])
for name in behavior_schema)
return fields
示例12: get_object_schema
# 需要导入模块: from plone.behavior.interfaces import IBehaviorAssignable [as 别名]
# 或者: from plone.behavior.interfaces.IBehaviorAssignable import enumerateBehaviors [as 别名]
def get_object_schema(obj):
object_schema = set()
for iface in providedBy(obj).flattened():
for name, field in getFields(iface).items():
no_underscore_method = not name.startswith('_')
no_manage_method = not name.startswith('manage')
if no_underscore_method and no_manage_method:
if name not in object_schema:
object_schema.add(name)
yield name, field
assignable = IBehaviorAssignable(obj, None)
if assignable:
for behavior in assignable.enumerateBehaviors():
for name, field in getFields(behavior.interface).items():
if name not in object_schema:
object_schema.add(name)
yield name, field
示例13: get_behaviors
# 需要导入模块: from plone.behavior.interfaces import IBehaviorAssignable [as 别名]
# 或者: from plone.behavior.interfaces.IBehaviorAssignable import enumerateBehaviors [as 别名]
def get_behaviors(brain_or_object):
"""Iterate over all behaviors that are assigned to the object
:param brain_or_object: A single catalog brain or content object
:type brain_or_object: ATContentType/DexterityContentType/CatalogBrain
:returns: Behaviors
:rtype: list
"""
obj = get_object(brain_or_object)
if not is_dexterity_content(obj):
fail(400, "Only Dexterity contents can have assigned behaviors")
assignable = IBehaviorAssignable(obj, None)
if not assignable:
return {}
out = {}
for behavior in assignable.enumerateBehaviors():
for name, field in getFields(behavior.interface).items():
out[name] = field
return out
示例14: fieldFilter
# 需要导入模块: from plone.behavior.interfaces import IBehaviorAssignable [as 别名]
# 或者: from plone.behavior.interfaces.IBehaviorAssignable import enumerateBehaviors [as 别名]
def fieldFilter():
portal_type = self.context.getPortalTypeName()
fti = getUtility(IDexterityFTI, name=portal_type)
schema = fti.lookupSchema()
fields = getFieldsInOrder(schema)
assignable = IBehaviorAssignable(self.context, None)
for behavior in assignable.enumerateBehaviors():
if behavior.marker:
new_fields = getFieldsInOrder(behavior.marker)
if len(new_fields) > 0:
fields = fields + new_fields
obj_fields = []
for key, value in fields:
is_image = INamedImageField.providedBy(value)
is_file = INamedBlobFileField.providedBy(value)
if is_image or is_file:
obj_fields.append(value)
return obj_fields
示例15: extract_relations
# 需要导入模块: from plone.behavior.interfaces import IBehaviorAssignable [as 别名]
# 或者: from plone.behavior.interfaces.IBehaviorAssignable import enumerateBehaviors [as 别名]
def extract_relations(obj):
assignable = IBehaviorAssignable(obj, None)
if assignable is None:
return
for behavior in assignable.enumerateBehaviors():
if behavior.marker != behavior.interface:
for name, field in getFields(behavior.interface).items():
if IRelation.providedBy(field):
try:
relation = getattr(behavior.interface(obj), name)
except AttributeError:
continue
yield behavior.interface, name, relation
if IRelationList.providedBy(field):
try:
l = getattr(behavior.interface(obj), name)
except AttributeError:
continue
if l is not None:
for relation in l:
yield behavior.interface, name, relation