当前位置: 首页>>代码示例>>Python>>正文


Python IBehaviorAssignable.enumerateBehaviors方法代码示例

本文整理汇总了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
开发者ID:richarsi,项目名称:copsclub,代码行数:28,代码来源:migrator.py

示例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))
开发者ID:codesyntax,项目名称:collective.dynatree,代码行数:29,代码来源:widget.py

示例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
开发者ID:OpenBfS,项目名称:dokpool-plone,代码行数:32,代码来源:dexterity.py

示例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
开发者ID:collective,项目名称:collective.soundcloud,代码行数:11,代码来源:directives.py

示例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
开发者ID:collective,项目名称:collective.soundcloud,代码行数:13,代码来源:directives.py

示例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
开发者ID:collective,项目名称:plone.app.imagecropping,代码行数:14,代码来源:dx.py

示例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)
开发者ID:Vinsurya,项目名称:Plone,代码行数:14,代码来源:markers.py

示例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
开发者ID:witekdev,项目名称:plone.jsonapi.routes,代码行数:15,代码来源:datamanagers.py

示例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)
开发者ID:dimiro1,项目名称:plone.app.imagecropping,代码行数:17,代码来源:utils.py

示例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
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:50,代码来源:utils.py

示例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
开发者ID:vangheem,项目名称:xmldirector.plonecore,代码行数:18,代码来源:xpath_field.py

示例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
开发者ID:tisto,项目名称:plone.restapi,代码行数:20,代码来源:utils.py

示例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
开发者ID:andersonsmith,项目名称:bika.lims,代码行数:21,代码来源:api.py

示例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
开发者ID:IMIO,项目名称:cpskin.caching,代码行数:21,代码来源:purge.py

示例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
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:23,代码来源:event.py


注:本文中的plone.behavior.interfaces.IBehaviorAssignable.enumerateBehaviors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。