有没有办法扩展Plone的灵巧度;这是什么行为?

有没有办法扩展Plone的灵巧度;这是什么行为?,plone,adapter,behavior,dexterity,Plone,Adapter,Behavior,Dexterity,我正在做的项目使用了Plone令人敬畏的灵巧插件。我的两个自定义内容类型具有必须计算的非常特定的名称。我以前完成这项工作的最初方式是,根据手册的说明,在对象的通用设置条目中添加plone.app.content.interfaces.INameFromTitle作为一种行为: <?xml version="1.0"?> <object name="avrc.aeh.cycle" meta_type="Dexterity FTI"> ... <property

我正在做的项目使用了Plone令人敬畏的灵巧插件。我的两个自定义内容类型具有必须计算的非常特定的名称。我以前完成这项工作的最初方式是,根据手册的说明,在对象的通用设置条目中添加plone.app.content.interfaces.INameFromTitle作为一种行为:

<?xml version="1.0"?>
<object name="avrc.aeh.cycle" meta_type="Dexterity FTI">
  ...
  <property name="schema">myproject.mytype.IMyType</property> 
  <property name="klass">plone.dexterity.content.Item</property>
  ...
  <property name="behaviors">
    <element value="plone.app.content.interfaces.INameFromTitle" />
  </property>
  ...
</object>
此方法与本文建议的方法非常相似:

不幸的是,这个方法在plone.app.dexterity测试版之后停止了工作,现在我的内容项没有正确分配名称

有没有人知道如何将Dextrity的INameFromTitle行为扩展到非常特定的命名用例


非常感谢您的帮助,谢谢

您可以尝试以下方法

接口中.py

from plone.app.content.interfaces import INameFromTitle

class INameForMyType(INameFromTitle):

    def title():
        """Return a custom title"""
from myproject.mytype.interfaces import INameForMyType

class NameForMyType(object):
    implements(INameForMyType)

    def __init__(self, context):
        self.context = context

    @property
    def title(self):
        return u"Custom Title %s" % self.context.foo
class INameFromBrandAndModel(Interface):
    """ Interface to adapt to INameFromTitle """

class NameFromBrandAndModel(object):
    """ Adapter to INameFromTitle """
    implements(INameFromTitle)
    adapts(INameFromBrandAndModel)

    def __init__(self, context):
        pass

    def __new__(cls, context):
        brand = context.brand
        model = context.modeltype    
        title = u'%s %s' % (brand,model)
        inst = super(NameFromBrandAndModel, cls).__new__(cls)

        inst.title = title
        context.setTitle(title)

        return inst
行为中.py

from plone.app.content.interfaces import INameFromTitle

class INameForMyType(INameFromTitle):

    def title():
        """Return a custom title"""
from myproject.mytype.interfaces import INameForMyType

class NameForMyType(object):
    implements(INameForMyType)

    def __init__(self, context):
        self.context = context

    @property
    def title(self):
        return u"Custom Title %s" % self.context.foo
class INameFromBrandAndModel(Interface):
    """ Interface to adapt to INameFromTitle """

class NameFromBrandAndModel(object):
    """ Adapter to INameFromTitle """
    implements(INameFromTitle)
    adapts(INameFromBrandAndModel)

    def __init__(self, context):
        pass

    def __new__(cls, context):
        brand = context.brand
        model = context.modeltype    
        title = u'%s %s' % (brand,model)
        inst = super(NameFromBrandAndModel, cls).__new__(cls)

        inst.title = title
        context.setTitle(title)

        return inst
我通常更喜欢使用ZCML定义适配器;在中配置.zcml

<adapter for="myproject.mytype.IMyType"
         factory=".behaviors.NameForMyType"
         provides=".behaviors.INameForMyType"
         />
<plone:behavior

    title="Name from brand and model"
    description="generates a name from brand and model attributes"
    for="plone.dexterity.interfaces.IDexterityContent"
    provides=".behavios.INameFromBrandAndModel"
    />

<adapter factory=".behaviors.NameFromBrandAndModel" />


但是你也可以使用一个grok.global_适配器。

我通过适应INameFromTitle的行为做到了这一点

行为中.py

from plone.app.content.interfaces import INameFromTitle

class INameForMyType(INameFromTitle):

    def title():
        """Return a custom title"""
from myproject.mytype.interfaces import INameForMyType

class NameForMyType(object):
    implements(INameForMyType)

    def __init__(self, context):
        self.context = context

    @property
    def title(self):
        return u"Custom Title %s" % self.context.foo
class INameFromBrandAndModel(Interface):
    """ Interface to adapt to INameFromTitle """

class NameFromBrandAndModel(object):
    """ Adapter to INameFromTitle """
    implements(INameFromTitle)
    adapts(INameFromBrandAndModel)

    def __init__(self, context):
        pass

    def __new__(cls, context):
        brand = context.brand
        model = context.modeltype    
        title = u'%s %s' % (brand,model)
        inst = super(NameFromBrandAndModel, cls).__new__(cls)

        inst.title = title
        context.setTitle(title)

        return inst
行为.zcml配置.zcml

<adapter for="myproject.mytype.IMyType"
         factory=".behaviors.NameForMyType"
         provides=".behaviors.INameForMyType"
         />
<plone:behavior

    title="Name from brand and model"
    description="generates a name from brand and model attributes"
    for="plone.dexterity.interfaces.IDexterityContent"
    provides=".behavios.INameFromBrandAndModel"
    />

<adapter factory=".behaviors.NameFromBrandAndModel" />
以后您可以轻松更改标题。应该在addForm中隐藏标题字段,以避免误解