1

在使用 Plone 时,我已将DocumentViewer 产品集成到我的 Plone 应用程序中,以帮助查看 PDF 文件。文档查看器附加产品定义了一组模式/字段,可以在控制面板设置中查看,即站点设置->文档查看器设置

您可以在此处查看字段/模式的定义方式

IGlobalDocumentViewerSettings现在我想通过在我的 example.product 中覆盖它来向界面添加另一个字段。

我认为我不能使用SchemaExtender,因为它们不是原型。我也尝试按照此链接提供的说明进行操作,但无济于事。我可以重新安装我的产品,但未显示我添加的字段。

这是我的代码示例:

from collective.documentviewer.interfaces import IGlobalDocumentViewerSettings
from collective.documentviewer.interfaces import IDocumentViewerSettings
from zope import schema
from zope.interface import implements

class DocViewerSchemaProvider(object):
    implements(IGlobalDocumentViewerSettings)

    def getSchema(self):
        """
        """
        return IEnhancedDocumentViewerSchema

class IEnhancedDocumentViewerSchema(IDocumentViewerSettings):
    """ 
    Use all the fields from the default schema, and add various extra fields.
    """

    folder_location = schema.TextLine(
        title=u"Default folder location",
        description=u'This folder will be created in the Plone root folder. '
                    u'Plone client must have write access to directory.',
        default=u"files_folder")

谁能帮助我如何覆盖这个特定的界面?

4

1 回答 1

3

由于作者(我)没有让覆盖它变得简单,所以覆盖它会有点复杂。以下步骤是您需要执行的操作。警告,这都是伪代码,所以你可能需要调整以使其适合你。

首先,通过扩展您要自定义的界面来提供您的自定义界面:

class IEnhancedDocumentViewerSchema(IGlobalDocumentViewerSettings):
    """ 
    Use all the fields from the default schema, and add various extra fields.
    """

    folder_location = schema.TextLine(
        title=u"Default folder location",
        description=u'This folder will be created in the Plone root folder. '
                    u'Plone client must have write access to directory.',
        default=u"files_folder")

然后,创建用于存储和检索架构设置的设置适配器:

from collective.documentviewer.settings import Base
class CustomSettings(Base):
    implements(IEnhancedDocumentViewerSchema)
    use_interface = IEnhancedDocumentViewerSchema

然后,注册您的适配器::

<adapter 
    for="Products.CMFPlone.interfaces.IPloneSiteRoot"
    provides="my.product.interfaces.IEnhancedDocumentViewerSchema"
    factory=".somewhere.CustomSettings" />

然后,使用您的自定义架构创建一个表单::

from z3c.form import field
from plone.app.z3cform.layout import wrap_form
from collective.documentviewer.views import GlobalSettingsForm
class CustomGlobalSettingsForm(GlobalSettingsForm):
    fields = field.Fields(IEnhancedDocumentViewerSchema)
CustomGlobalSettingsFormView = wrap_form(CustomGlobalSettingsForm)

然后,为您的产品创建一个自定义层,扩展文档查看器层。这将需要 2 个步骤。首先,添加图层接口::

from collective.documentviewer.interfaces import ILayer as IDocumentViewerLayer
class ICustomLayer(IDocumentViewerLayer):
    """
    custom layer class
    """

并使用通用设置注册您的图层。使用以下内容将 xml 文件 browserlayer.xml 添加到您的配置文件中(确保重新安装产品以便注册该层)::

<?xml version="1.0"?>
<layers name="" meta_type="ComponentRegistry">
    <layer name="my.product" 
           interface="my.product.interfaces.ICustomLayer" />
</layers>

最后,使用您为您的产品注册的层使用您的自定义表单覆盖全局设置视图:

<browser:page
    name="global-documentviewer-settings"
    for="Products.CMFPlone.interfaces.IPloneSiteRoot"
    class=".somewhere.CustomGlobalSettingsFormView"
    layer=".interfaces.ICustomLayer"
    permission="cmf.ManagePortal" />

哇,那太难了。

于 2013-01-30T21:22:04.903 回答