Kotti的设置配置
kotti_controlpanel的Python项目详细描述
您有一个完整的示例,例如在addonkotti_google_analytics中。
设置
要激活kotti站点中的kotti_controlpanel加载项,您需要 在粘贴中的kotti.configurators设置中添加一个条目 部署配置。如果没有kotti.configurators选项, 加一个。您的[app:main](或[app:kotti]中的行,具体取决于 然后,您可以设置fanstatic)部分如下:
kotti.configurators = kotti_controlpanel.kotti_configure
加载项将添加一个新的配置页以保存模块的设置或 跨越不同的模块。它向 菜单点“站点设置”。每个设置集合都显示在一个选项卡中。它 旨在为模块使用一个选项卡,但也可以使用 如果需要更扩展的结构,可以使用多个选项卡。
您可以选择两种模式来设置设置。使用“dict模式” 您有一个非常简单和直接的设置选项。如果你 需要更高级的表单,您可以设置自己的架构。
设置选项卡是用字典设置的。在这里,您定义一个名称和 标签的标题,需要什么。可选参数是成功消息, 设置或架构、架构工厂和使用CSRF令牌。
在字典中定义设置:
TestSettings = { 'name': 'test_settings', 'title': "Testsettings", 'icon': 'myaddon:static/icon.png', 'description': "Some description for my settings", 'success_message': u"Successfully saved test settings.", 'settings': [ {'type': 'String', 'name': 'testsetting_1', 'title': 'Test 1', 'description': 'a test setting', 'default': '', }, {'type': 'Integer', 'name': 'testsetting_2', 'title': 'Test 2', 'description': 'again a test setting', 'default': 23, }]}
使用模式定义设置:
class StringSchemaNode(colander.SchemaNode): name = 'a_string' title = 'hello' default = 'hello world' class RangedIntSchemaNode(colander.SchemaNode): name = 'range_int' validator = colander.Range(0, 10) default = 5 title = 'Ranged Int' class TestSchema(colander.MappingSchema): string = StringSchemaNode(colander.String()) ranged_int = RangedIntSchemaNode(colander.Int()) TestSettings = { 'name': 'test_settings', 'title': "Testsettings", 'description': "Some description for my settings", 'success_message': u"Successfully saved test settings.", 'schema_factory': TestSchema }
若要在kotti_controlpanel内注册配置,请添加 加载项中填充器中的设置。查看kotti文档 获取有关populators的更多信息并查看example。
在populator中添加设置配置,例如在名为populate.py的文件中:
def populate(): from kotti_controlpanel.util import add_settings add_settings(TestSettings)
并将其添加到您的配置中:
def kotti_configure(settings): settings['kotti.populators'] += ' my_addon.populate.populate'
或者直接指向您的ini文件:
kotti.populators = my_addon.populate.populate
要将设置恢复到代码中,请使用以下命令:
from kotti_controlpanel.util import get_setting first_test_setting = get_setting('test_setting_1')
您还可以通过以下方式向主控制面板视图添加有用的链接:
from kotti.util import Link from kotti_controlpanel import CONTROL_PANEL_LINKS def kotti_configure(settings): CONTROL_PANEL_LINKS.append(Link('setup-users', title='User Management'))
事件
在保存设置之前和之后,将触发用于处理更改的事件。认购 对于活动,请使用以下内容:
from pyramid.events import subscriber from kotti_controlpanel.events import SettingsAfterSave @subscriber(SettingsAfterSave) def do_something_when_settings_saved(event): # Check if the settings for this module was saved. if not event.module == __package__: return my_fancy_thing()
默认模式
kotti_controlpanel提供了一些默认模式,您可以直接在代码中使用这些模式 示例目的。目前实现了两个模式,一个用于选择 应显示小部件,并显示另一个小部件以设置小部件的可见性。把它用在你的 在populator中添加如下内容:
from kotti.views.slots import assign_slot from kotti_controlpanel.config import SlotSchemaNode from kotti_controlpanel.config import ShowInContextSchemaNode from kotti_controlpanel.util import add_settings from kotti_controlpanel.util import get_setting from kotti_myaddon import _ class MyWidgetSchema(colander.MappingSchema): slot = SlotSchemaNode(colander.String()) show_in_context = ShowInContextSchemaNode(colander.String()) MyAddonSettings = { 'name': 'myaddon_settings', 'title': _(u'My Addon Settings'), 'description': _(u"Settings for my addon"), 'success_message': _(u"Successfully saved my addon settings."), 'schema_factory': MyAddonSchema, } def populate(): add_settings(MyAddonSettings)
注
这个包是由kotti_settings包嵌入的
历史记录
1.0.8-1.0.9
日期:2017-06-09
- 错误修复
1.0.5-1.0.7
- 错误修复
- 用户界面改进
- 包括kotti_pdf
- 将文件夹内容类型更改为继承自文档内容类型,而不是内容。
1.0.4
- 允许将属性传递到表单元素的架构节点中。
1.0.3
- 修复了查看包设置的问题。
1.0.2
- 修复了“控制面板”页上的重复链接。
1.0.1
- 添加了一个页面以列出所有系统设置。
1.0.0
- 修复了包设置的设置。
- 允许包重写其设置页。
0.0.2
- 允许将链接添加到控制面板
0.0.1-未发布
- 使用pcreate -s kotti kotti_controlpanel创建包。