1

我有一个 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']但我仍然找不到访问组内字段的小部件的方法。

使用组时如何自定义小部件属性?

4

1 回答 1

4

我认为您需要的是使用小部件子表单,请参阅以下代码:

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()
于 2015-09-01T17:11:04.280 回答