Plone重写Zope架构字段

2024-09-29 23:21:26 发布

您现在位置:Python中文网/ 问答频道 /正文

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

您可以查看字段/模式是如何定义的here

现在我想通过在我的示例.产品. 在

我认为我不能使用SchemaExtender,因为它们不是原型。我也尝试过按照by this link提供的说明进行操作,但没有效果。我可以重新安装我的产品,但我添加的字段未显示。在

下面是我的代码示例:

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")

有谁能帮助我重写这个特殊的接口吗?在


Tags: thefromimportzope示例定义产品schema
1条回答
网友
1楼 · 发布于 2024-09-29 23:21:26

因为作者(我)并没有让重写变得简单,所以重写会有点复杂。以下步骤是您需要做的。警告,这都是伪代码,所以你可能需要调整一下,让它为你工作。在

首先,通过扩展要自定义的接口来提供自定义接口:

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")

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

^{pr2}$

然后,注册适配器:

<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)

然后,为您的产品创建一个自定义层,扩展documentviewer层。这需要两个步骤。首先,添加层接口:

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

然后用通用设置注册你的图层。添加xml文件,浏览器层.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" />

哇,那太难了。在

相关问题 更多 >

    热门问题