仅覆盖Plone标准内容类型的描述字段

仅覆盖Plone标准内容类型的描述字段,plone,archetypes,template-tal,zpt,template-metal,Plone,Archetypes,Template Tal,Zpt,Template Metal,我只想覆盖Plone标准内容类型(文档、文件夹、blablabla)的经典“描述字段”的“视图”,因为我需要使用结构化文本“结构化”此字段的文本,如: 这是我的描述 有许多行 布拉布拉布拉 如果要为所有内容类型自定义描述小部件,可以使用以下方式创建适配器(尤其是ISchemaModifier界面): from my.product.browser.interfaces import IMyProductLayer from my.product.widgets import MyCustomWi

我只想覆盖Plone标准内容类型(文档、文件夹、blablabla)的经典“描述字段”的“视图”,因为我需要使用结构化文本“结构化”此字段的文本,如:

这是我的描述
有许多行
布拉布拉布拉

如果要为所有内容类型自定义描述小部件,可以使用以下方式创建适配器(尤其是ISchemaModifier界面):

from my.product.browser.interfaces import IMyProductLayer
from my.product.widgets import MyCustomWidget
from Products.ATContentTypes.interface.interfaces import IATContentType
from archetypes.schemaextender.interfaces import IBrowserLayerAwareExtender
from archetypes.schemaextender.interfaces import ISchemaModifier

class MyExtender(object):
    # you could choose a more specific interface for a more fine grained override
    adapts(IATContentType)
    implements(IBrowserLayerAwareExtender, ISchemaModifier)
    # this will limit out override to this browserlayer
    layer = IMyProductLayer

    def fiddle(self, schema):
        # if you want to customize just the template of the original widget
        # see links below
        schema['description'].widget=MyCustomWidget(
            label='...',
            ....
        )
        return schema
<adapter
    factory=".extender.MyExtender"
    provides="archetypes.schemaextender.interfaces.ISchemaModifier" />
然后你可以这样注册它:

from my.product.browser.interfaces import IMyProductLayer
from my.product.widgets import MyCustomWidget
from Products.ATContentTypes.interface.interfaces import IATContentType
from archetypes.schemaextender.interfaces import IBrowserLayerAwareExtender
from archetypes.schemaextender.interfaces import ISchemaModifier

class MyExtender(object):
    # you could choose a more specific interface for a more fine grained override
    adapts(IATContentType)
    implements(IBrowserLayerAwareExtender, ISchemaModifier)
    # this will limit out override to this browserlayer
    layer = IMyProductLayer

    def fiddle(self, schema):
        # if you want to customize just the template of the original widget
        # see links below
        schema['description'].widget=MyCustomWidget(
            label='...',
            ....
        )
        return schema
<adapter
    factory=".extender.MyExtender"
    provides="archetypes.schemaextender.interfaces.ISchemaModifier" />
IMyProductLayer或此适配器将永远不会使用

更多信息:

  • (自定义小部件示例)
  • (仅自定义小部件的模板)

您确实不希望在描述字段中使用HTML。此字段用于许多地方,需要纯文本


最好使用上述方法添加具有不同名称的附加字段

更改呈现标准描述字段的模板以将换行符转换为换行符并不困难,但需要注意避免创建安全漏洞

覆盖主题化产品或自定义文件夹中的蒙皮层kss_generic_macros.pt模板

然后,您可以使用Products.PythonScripts.standard.newline\u to\u br将换行符转换为换行符。您需要插入带有“structure”的转换文本,以防止中断符的转义

由于您将使用“structure”,因此在将换行符应用于\br之前,您还必须手动对描述进行html转义(使用标准中的html),否则您将创建XSS攻击的向量

宏的键部分在修复后可能为:

            <div metal:define-macro="description-field-view"
               id="parent-fieldname-description"
               tal:define="kss_class python:getKssClasses('description',
                           templateId='kss_generic_macros', macro='description-field-view');
                           pps modules/Products.PythonScripts.standard"
               tal:condition="context/Description"
               tal:attributes="class string:documentDescription$kss_class;">
               <span metal:define-slot="inside"
                     tal:replace="structure python:pps.newline_to_br(pps.html_quote(context.Description()))">Description</span>
            </div>

描述

这将更改项目本身的视图,但不会更改文件夹列表中的视图。为此,您还需要对默认视图进行成本计算,例如,对于文件夹摘要视图,它将如下所示:

description

如果还想删除上面方法调用中使用的尾随换行符:
context.description().rstrip()
为了灵活性,可以使用: