我有一个Plone自定义控制面板注册表,我正在尝试使用一个众所周知的方法来自定义zope.schema.Text
和zope.schema.TextField
的一些小部件属性。
我通常以这种方式自定义updateWidgets
:
def updateWidgets(self):
super(MyEditForm, self).updateWidgets()
self.widgets['my_text_area'].style = 'width: 100%'
self.widgets['my_text_area'].rows = 7
但是现在我正在处理一个表单,其中字段在两个字段集中分割:
class MySettingsEditForm(controlpanel.RegistryEditForm):
schema = IMySettingsSchema
groups = (Form1, Form2)
# fields = nothing
如果我尝试访问self.widgets['my_text_area']
,我会KeyError
。似乎我没有定义fields
属性,我无法直接访问小部件。
我发现我有groups
所以我可以调用类似self.groups[0].fields['my_text_area']
的内容,但我仍然无法访问组内字段的小部件。
如何在使用群组时自定义窗口小部件属性?
答案 0 :(得分:4)
我认为您需要的是使用widget子窗体,请参阅以下代码:
def fix_table_widget(self, name, widgets):
sub_widgets = widgets[name].widgets
for widget in sub_widgets:
new_label = widget.subform.widgets['weekday'].value
widget.subform.widgets['selected'].items[0]['label'] = new_label
widget.subform.widgets['weekday'].mode = 'hidden'
def schoolrequest_customizations(self):
''' Customizations for the schoolrequest base views
'''
for group in self.groups:
widgets = group.widgets
if 'table_bus_to_school' in widgets:
self.block_widget_table('table_bus_to_school', widgets)
self.fix_table_widget('table_bus_to_school', widgets)
if 'table_bus_to_home' in widgets:
self.block_widget_table('table_bus_to_home', widgets)
self.fix_table_widget('table_bus_to_home', widgets)
def update(self):
super(MyForm, self).update()
self.schoolrequest_customizations()