plone - 有没有办法扩展 Plone Dexterity 的 INameFromTitle 行为?

标签 plone adapter behavior dexterity

我正在做的项目使用了 Plone 很棒的 Dexterity 插件。我的一些自定义内容类型具有必须计算的非常具体的名称。我之前最初完成此操作的方法是按照手册的说明在对象的通用设置条目中添加 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>

然后我创建了一个可以提供 INameFromTitle 的适配器:
from five import grok
from zope.interface import Interface
import zope.schema
from plone.app.content.interfaces import INameFromTitle

class IMyType(Interface):

    foo = zope.schema.TextLine(
        title=u'Foo'
        )

class NameForMyType(grok.Adapter):
    grok.context(IMyType)
    grok.provides(INameFromTitle)

    @property
    def title(self):
        return u'Custom Title %s' % self.context.foo

此方法与此博客文章中建议的方法非常相似:

http://davidjb.com/blog/2010/04/plone-and-dexterity-working-with-computed-fields

不幸的是,这种方法在 plone.app.dexterity beta 之后停止工作,现在我的内容项没有正确分配它们的名称。

有人会碰巧知道如何为非常具体的命名用例扩展 Dexterity 的 INameFromTitle 行为吗?

非常感谢您的帮助,谢谢!

最佳答案

您可以尝试以下方法。

接口(interface).py

from plone.app.content.interfaces import INameFromTitle

class INameForMyType(INameFromTitle):

    def title():
        """Return a custom title"""

行为.py
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

我通常更喜欢使用 ZCML 定义我的适配器;在 配置.zcml
<adapter for="myproject.mytype.IMyType"
         factory=".behaviors.NameForMyType"
         provides=".behaviors.INameForMyType"
         />

但您也可以使用 grok.global_adapter。

关于plone - 有没有办法扩展 Plone Dexterity 的 INameFromTitle 行为?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7974285/

相关文章:

python - 如何从实例内部获取 Zope 安装的位置?

android - 在android自定义 ListView 中向右滑动显示按钮

java - 在 Wicket 中提交表单后的 AjaxFormComponentUpdatingBehaviour 问题

python - 使用数据创建安装到另一台服务器上的 plone 副本

plone - 使用 TAL 语言在 Plone 中按用户查找信息

Plone 门户转换过时了?

android - 如何使用 ListView 适配器中的单击按钮打开菜单上下文 Android?

java - 从 recyclerview 和 firebase 数据库中删除显示错误的项目

c# - 使用 IParameterInspector.BeforeCall(string operationName, object[] inputs) 中止调用

c# - 如何将java嵌入到C#中