创建控制面板视图
创建控制面板视图
http://www.315ok.org/blogfolder/280
http://www.315ok.org/logo.png
创建控制面板视图
创建控制面板视图
为了方便地为三方插件设置配置参数,可以为三方插件创建控制面板视图。
基于z3c.form的plone.app.registry包含某些有用的帮助,能够用来方便地构造控制面板表单:
基于z3c.form的plone.app.registry包含某些有用的帮助,能够用来方便地构造控制面板表单:
from plone.z3cform import layout
from plone.app.registry.browser.controlpanel import RegistryEditForm
from plone.app.registry.browser.controlpanel import \
ControlPanelFormWrapper
from optilux.cinemacontent.interfaces import IOptiluxSettings
from optilux.cinemacontent import CinemaMessageFactory as _
class OptiluxControlPanelForm(RegistryEditForm):
schema = IOptiluxSettings
label = _(u"Optilux control panel")
OptiluxControlPanelView = layout.wrap_form(OptiluxControlPanelForm,
ControlPanelFormWrapper)
Here, we are creating a standalone form class and then wrapping it into a browser view. This pattern allows plone.app.registry to control the page template surrounding the form. This view is registered in configure.zcml (there are no standard grokkers for the RegistryEditForm base class):<browser:page
for="plone.app.layout.navigation.interfaces.INavigationRoot"
name="optilux-controlpanel"
class=".controlpanel.OptiluxControlPanelView"
permission="cmf.ManagePortal"
/>
We can install this into the control panel using GenericSetup. In profiles/default/controlpanel.xml, we have:<?xml version="1.0"?>
<object
name="portal_controlpanel"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
i18n:domain="optilux.cinemacontent ">
<configlet
title="Optilux settings"
action_id="optilux"
appId="optilux"
category="Products"
condition_expr=""
url_expr="string:${portal_url}/@@optilux-controlpanel"
icon_expr="string:$portal_url/++resource++film_icon.gif"
visible="True"
i18n:attributes="title">
<permission>Manage portal</permission>
</configlet>
</object>
Notice how we reference the view name in url_expr property. We have also reused the Film type's icon as the control panel's icon.