Changeset 6260 for main/waeup.sirp/trunk/src
- Timestamp:
- 1 Jun 2011, 13:38:51 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/utils/converters.py
r6258 r6260 242 242 from zope.interface import Interface 243 243 from zope.formlib import form 244 from zope.formlib.form import ( 245 _widgetKey, WidgetInputError, ValidationError, InputErrors, expandPrefix) 244 246 from zope.formlib.interfaces import IInputWidget 245 247 from zope.publisher.browser import TestRequest 246 248 249 def getWidgetsData(widgets, form_prefix, data): 250 # from zope.formlib.form 251 errors = [] 252 form_prefix = expandPrefix(form_prefix) 253 254 for input, widget in widgets.__iter_input_and_widget__(): 255 if input and IInputWidget.providedBy(widget): 256 name = _widgetKey(widget, form_prefix) 257 258 if not widget.hasInput(): 259 continue 260 261 try: 262 data[name] = widget.getInputValue() 263 except ValidationError, error: 264 # convert field ValidationError to WidgetInputError 265 error = WidgetInputError(widget.name, widget.label, error) 266 errors.append((name, error)) 267 except InputErrors, error: 268 errors.append((name, error)) 269 270 return errors 271 272 247 273 class DefaultConverter(Converter): 248 274 … … 250 276 grok.provides(ISchemaTypeConverter) 251 277 252 def __init__(self, iface ):278 def __init__(self, iface, form_fields=None): 253 279 self.iface = iface 280 self.form_fields = form_fields 281 if self.form_fields is None: 282 self.form_fields = form.Fields(iface) 283 return 254 284 255 285 def applyRowData(self, data_dict, context): 256 286 request = TestRequest(form={}) 257 form_fields = form.Fields(self.iface) 287 #form_fields = form.Fields(self.iface) 288 form_fields = self.form_fields 258 289 for key, val in data_dict.items(): 259 290 request.form['form.%s' % key] = val 260 291 widgets = form.setUpWidgets( 261 292 form_fields, 'form', context, request) 262 errors = form.getWidgetsData(widgets, 'form', data_dict) 293 #errors = form.getWidgetsData(widgets, 'form', data_dict) 294 errors = getWidgetsData(widgets, 'form', data_dict) 295 if errors: 296 err_message = [] 297 for key, error in errors: 298 message = error[1].args[0] 299 err_message.append((key, message)) 263 300 invariant_errors = form.checkInvariants(form_fields, data_dict) 264 301 if not errors and not invariant_errors:
Note: See TracChangeset for help on using the changeset viewer.