Changeset 270
- Timestamp:
- 12/18/06 01:45:56 (2 years ago)
- Files:
-
- trunk/formal/form.py (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/formal/form.py
r269 r270 18 18 19 19 20 21 # Backwards compatability/workaround until there's nothing left in Formal or 22 # application code that adapts the context to IFormalErrors. 23 def formErrorsFinder(ctx): 24 form = iformal.IForm(ctx) 25 return form.errors 26 27 registerAdapter(formErrorsFinder, context.WovenContext, iformal.IFormErrors) 28 29 30 20 31 def renderForm(name): 21 32 … … 35 46 36 47 # Find errors for *this* form and remember things on the context 37 errors = iformal.IFormErrors(ctx, None) 38 if errors is not None and errors.formName == name: 39 ctx.remember(errors.data, iformal.IFormData) 48 if form.errors: 49 ctx.remember(form.errors.data, iformal.IFormData) 40 50 else: 41 ctx.remember(None, iformal.IFormErrors)42 51 ctx.remember(form.data or {}, iformal.IFormData) 43 52 … … 318 327 self.data = {} 319 328 self.items = FormItems(None) 329 self.errors = FormErrors() 320 330 # Forward to FormItems methods 321 331 self.add = self.items.add … … 335 345 def process(self, ctx): 336 346 337 # Get the request args 338 requestArgs = inevow.IRequest(ctx).args 339 340 # Decode the request arg names 347 request = inevow.IRequest(ctx) 341 348 charset = getPOSTCharset(ctx) 342 args = dict([(k.decode(charset),v) for k,v in requestArgs.iteritems()]) 349 350 # Get the request args and decode the arg names 351 args = dict([(k.decode(charset),v) for k,v in request.args.items()]) 343 352 344 353 # Find the callback to use, defaulting to the form default … … 369 378 self.actions[0].validate 370 379 371 # Store an errors object in the context 372 errors = FormErrors(self.name) 373 errors.data = args 374 ctx.remember(errors, iformal.IFormErrors) 380 # Remember the args in case validation fails. 381 self.errors.data = args 375 382 376 383 # Iterate the items and collect the form data and/or errors. 377 384 for item in self.items: 378 item.process(ctx, self, args, errors)379 380 if errors and validate:381 return errors385 item.process(ctx, self, args, self.errors) 386 387 if self.errors and validate: 388 return self.errors 382 389 383 390 def _clearUpResources( r ): 384 if not errors:391 if not self.errors: 385 392 self.resourceManager.clearUpResources() 386 393 return r … … 394 401 e = failure.value 395 402 failure.trap(validation.FormError, validation.FieldError) 396 errors = iformal.IFormErrors(ctx) 397 errors.add(failure.value) 398 return errors 403 self.errors.add(failure.value) 404 return self.errors 399 405 400 406 … … 443 449 implements( iformal.IFormErrors ) 444 450 445 def __init__(self, formName): 446 self.formName = formName 451 def __init__(self): 447 452 self.errors = [] 448 453 … … 677 682 678 683 def _renderErrors(self, ctx, data): 679 errors = iformal.IFormErrors(ctx, None) 680 if errors is not None: 681 errors = errors.getFormErrors() 682 if not errors: 684 685 if not self.original.errors: 683 686 return '' 687 688 errors = self.original.errors.getFormErrors() 684 689 685 690 errorList = T.ul()
