Ticket #1633 (new defect)

Opened 14 years ago

Last modified 10 years ago

Widget should have at least one field.

Reported by: tracguest Owned by: fguillaume
Priority: P1 Milestone: CPS 3.5.7
Component: CPSSchemas Version: unspecified
Severity: normal Keywords:
Cc:

Description

Hello,

CPS 3.4 returns an error like this when there's no field specified in the "Fields" property of a widget.

######################################################################

File "/root/instances/zope2.9/innovaDes/Products/CPSSchemas/BasicWidgets.py", line 1133, in prepare

datastructure[self.getWidgetId()] = bool(datamodel[self.fields[0]])

IndexError?: tuple index out of range

/root/instances/zope2.9/innovaDes/Products/CPSSchemas/BasicWidgets.py(1133)prepare()

-> datastructure[self.getWidgetId()] = bool(datamodel[self.fields[0]]) ######################################################################

I propose to control the exception and raise a message, the method (for CPSBooleanWidget) would be:

def prepare(self, datastructure, **kw):
        """Prepare datastructure from datamodel."""
        datamodel = datastructure.getDataModel()
        if len(self.fields) > 0:
            datastructure[self.getWidgetId()] = bool(datamodel[self.fields[0]])
        else:
            raise RuntimeError("You should specify at least one field for the widget %s" % self.getWidgetId())

Thank you very much.

Change History

comment:1 Changed 13 years ago by sfermigier

  • Milestone changed from CPS 3.4.1 to CPS 3.4.2

comment:2 Changed 10 years ago by gracinet

  • Milestone changed from CPS 3.5.0 to CPS 3.5.2

Will do, in the base class.

Note: See TracTickets for help on using tickets.