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


Python interfaces.IBehaviorAssignable类代码示例

本文整理汇总了Python中plone.behavior.interfaces.IBehaviorAssignable的典型用法代码示例。如果您正苦于以下问题:Python IBehaviorAssignable类的具体用法?Python IBehaviorAssignable怎么用?Python IBehaviorAssignable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了IBehaviorAssignable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: grabDexterityData

    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,代码行数:26,代码来源:migrator.py

示例2: __call__

    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,代码行数:27,代码来源:widget.py

示例3: _fields

    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,代码行数:30,代码来源:dexterity.py

示例4: dx_feed_indexer

 def dx_feed_indexer(context):
     assignable = IBehaviorAssignable(context, None)
     if assignable is not None:
         if assignable.supports(IFeedControl):
             try:
                 return tuple(context.feeds)
             except TypeError:
                 return tuple()
开发者ID:kingel,项目名称:collective.chimpfeed,代码行数:8,代码来源:schema.py

示例5: get_soundfile_field

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,代码行数:9,代码来源:directives.py

示例6: test_member_behavior_blacklist

 def test_member_behavior_blacklist(self):
     # Some behaviors should definitely NOT be provided.
     black_list = [metadata.IDublinCore, metadata.IBasic]
     # Note that we would want INameFromTitle in the black list as
     # well, but it cannot be, as it gets pulled in as base class
     # of INameFromFullName.
     member = self._createType(self.layer["portal"], "dexterity.membrane.organizationmember", "les")
     assignable = IBehaviorAssignable(member)
     for b in black_list:
         self.assertFalse(assignable.supports(b), "member type should NOT support %s behavior" % b)
开发者ID:adam139,项目名称:emc.policy,代码行数:10,代码来源:test_dexmember.py

示例7: test_member_behaviors

 def test_member_behaviors(self):
     behaviors = [INameFromFullName, IReferenceable,
                  metadata.ICategorization, metadata.IPublication,
                  metadata.IOwnership, IMembraneUser, IProvidePasswords]
     member = self._createType(
         self.layer['portal'], 'dexterity.membrane.member', 'les')
     assignable = IBehaviorAssignable(member)
     for b in behaviors:
         self.assertTrue(assignable.supports(b),
                         "member type should support %s behavior" % b)
开发者ID:jean,项目名称:dexterity.membrane,代码行数:10,代码来源:test_member.py

示例8: get_soundcloud_accessors

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,代码行数:11,代码来源:directives.py

示例9: applyMarkers

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,代码行数:12,代码来源:markers.py

示例10: _all_fields

 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,代码行数:12,代码来源:dx.py

示例11: __call__

 def __call__(self, context):
     assignable = IBehaviorAssignable(context, None)
     if assignable is None:
         return None
     if not assignable.supports(self.behavior.interface):
         return None
     if self.behavior.factory is not None:
         adapted = self.behavior.factory(context)
     else:
         # When no factory is specified the object should provide the
         # behavior directly
         adapted = context
     return adapted
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:13,代码来源:factory.py

示例12: get_behaviors

 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,代码行数:13,代码来源:datamanagers.py

示例13: _image_field_info

        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,代码行数:15,代码来源:utils.py

示例14: getAdditionalSchemata

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,代码行数:48,代码来源:utils.py

示例15: get_all_fields

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,代码行数:16,代码来源:xpath_field.py


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