Plone 如何使用灵活类型的属性作为url部分
我正在以灵活的方式编写这样的内容类型:Plone 如何使用灵活类型的属性作为url部分,plone,dexterity,Plone,Dexterity,我正在以灵活的方式编写这样的内容类型: class IArticle(form.Schema): title = schema.TextLine( title=_(u"Name"), ) code = schema.TextLine( title=_(u"Code"), ) 如果某个用户创建了一篇新文章,将“foo”设置为标题,“bar”设置为代码,则标题将为“foo”,文章URL将为“../foo”。如何将内容URL设置为“
class IArticle(form.Schema):
title = schema.TextLine(
title=_(u"Name"),
)
code = schema.TextLine(
title=_(u"Code"),
)
如果某个用户创建了一篇新文章,将“foo”设置为标题,“bar”设置为代码,则标题将为“foo”,文章URL将为“../foo”。如何将内容URL设置为“../bar”创建一个自定义行为以将对象id设置为
code
属性值:
code
属性值:
from plone.app.content.interfaces import INameFromTitle
from zope import interface, component
from ..types.interfaces import IArticle
class INameFromCode(INameFromTitle):
pass
class ArticleCodeAsTitle(object):
component.adapts(IArticle)
interface.implements(INameFromCode)
def __init__(self, context):
self.context = context
@property
def title(self):
return self.context.code
默认名称选择器尝试将要添加的新对象适配到Inamefortle界面,如果成功,将使用.title
属性为对象生成新名称。通过实现该接口的子类作为IArticle
对象的适配器,您可以将标题替换为.code
字段,从而确保将标题替换为新名称
将此注册为:
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:plone="http://namespaces.plone.org/plone"
i18n_domain="your.i18n.domain"
>
<plone:behavior
title="ArticleCode"
description="Use .code as the title when choosing a new object name"
provides=".articlecode.INameFromCode"
factory=".articlecode.ArticleCodeAsTitle"
for="..types.interfaces.IArticle"
/>
</configure>
并将此行为添加到您的
文章
类型定义中,而不是INameFromTitle
行为。您要做的是影响,您可以通过为您的界面添加一个
子类化Inamefitle接口是最简单的:
from plone.app.content.interfaces import INameFromTitle
from zope import interface, component
from ..types.interfaces import IArticle
class INameFromCode(INameFromTitle):
pass
class ArticleCodeAsTitle(object):
component.adapts(IArticle)
interface.implements(INameFromCode)
def __init__(self, context):
self.context = context
@property
def title(self):
return self.context.code
默认名称选择器尝试将要添加的新对象适配到Inamefortle界面,如果成功,将使用.title
属性为对象生成新名称。通过实现该接口的子类作为IArticle
对象的适配器,您可以将标题替换为.code
字段,从而确保将标题替换为新名称
将此注册为:
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:plone="http://namespaces.plone.org/plone"
i18n_domain="your.i18n.domain"
>
<plone:behavior
title="ArticleCode"
description="Use .code as the title when choosing a new object name"
provides=".articlecode.INameFromCode"
factory=".articlecode.ArticleCodeAsTitle"
for="..types.interfaces.IArticle"
/>
</configure>
并将此行为添加到您的文章
类型定义中,而不是INameFromTitle
行为