def getWidget(self, prop_name): """ Look up and return a property in this schema """ try: return self._getOb(widgetid_from_propname(prop_name)) except AttributeError: raise KeyError('Property "%s" not found in schema "%s"' \ % (prop_name, self.title_or_id()))
def addWidget(self, name, **kwargs): """ Add a Widget object to this schema """ propdef_id = widgetid_from_propname(name) title = kwargs.get('label', name) widget_id = widget_constructors[kwargs['widget_type']](self, id=propdef_id, title=title) widget = self._getOb(widget_id) # TODO: if there are other names in kwargs, raise a KeyError for name in ['sortorder', 'required', 'localized', 'tinymce', 'data_type', 'visible', 'glossary_id', 'list_id', 'default', 'relative']: if name in kwargs: value = kwargs[name] if name == 'data_type' and value not in DATA_TYPES: raise ValueError('Unknown data format "%s"' % value) widget.manage_changeProperties(**{name: value}) return widget
def addWidget(self, name, **kwargs): """ Add a Widget object to this schema """ propdef_id = widgetid_from_propname(name) title = kwargs.get('label', name) widget_id = widget_constructors[kwargs['widget_type']](self, id=propdef_id, title=title) widget = self._getOb(widget_id) for name, value in kwargs.iteritems(): if name == 'data_type' and value not in DATA_TYPES: raise ValueError('Unknown data format "%s"' % value) elif name == 'default': widget.default = value elif name == 'translation_id': widget.translation_id = value widget._p_changed = True else: widget.manage_changeProperties(**{name: value}) return widget