Changeset 5488 for django/branches/per-object-permissions/docs/forms.txt
- Timestamp:
- 06/17/07 17:18:54 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/per-object-permissions/docs/forms.txt
r4242 r5488 15 15 that document to understand how we're making the switch. 16 16 17 .. _newforms documentation: http://www.djangoproject.com/documentation/newforms/17 .. _newforms documentation: ../newforms/ 18 18 19 19 Introduction … … 174 174 # Check for validation errors 175 175 errors = manipulator.get_validation_errors(new_data) 176 manipulator.do_html2python(new_data) 176 177 if errors: 177 178 return render_to_response('places/errors.html', {'errors': errors}) 178 179 else: 179 manipulator.do_html2python(new_data)180 180 new_place = manipulator.save(new_data) 181 181 return HttpResponse("Place created: %s" % new_place) … … 230 230 # Check for errors. 231 231 errors = manipulator.get_validation_errors(new_data) 232 manipulator.do_html2python(new_data) 232 233 233 234 if not errors: 234 235 # No errors. This means we can save the data! 235 manipulator.do_html2python(new_data)236 236 new_place = manipulator.save(new_data) 237 237 … … 325 325 new_data = request.POST.copy() 326 326 errors = manipulator.get_validation_errors(new_data) 327 manipulator.do_html2python(new_data) 327 328 if not errors: 328 manipulator.do_html2python(new_data)329 329 manipulator.save(new_data) 330 330 … … 407 407 new_data = request.POST.copy() 408 408 errors = manipulator.get_validation_errors(new_data) 409 manipulator.do_html2python(new_data) 409 410 if not errors: 410 manipulator.do_html2python(new_data)411 411 412 412 # Send e-mail using new_data here... … … 417 417 form = forms.FormWrapper(manipulator, new_data, errors) 418 418 return render_to_response('contact_form.html', {'form': form}) 419 420 Implementing ``flatten_data`` for custom manipulators 421 ------------------------------------------------------ 422 423 It is possible (although rarely needed) to replace the default automatically 424 created manipulators on a model with your own custom manipulators. If you do 425 this and you are intending to use those models in generic views, you should 426 also define a ``flatten_data`` method in any ``ChangeManipulator`` replacement. 427 This should act like the default ``flatten_data`` and return a dictionary 428 mapping field names to their values, like so:: 429 430 def flatten_data(self): 431 obj = self.original_object 432 return dict( 433 from = obj.from, 434 subject = obj.subject, 435 ... 436 ) 437 438 In this way, your new change manipulator will act exactly like the default 439 version. 419 440 420 441 ``FileField`` and ``ImageField`` special cases … … 497 518 --------------------------- 498 519 499 After a form has been submitted, Django first checks to see that all the500 required fields are present and non-empty. For each field that passes that 501 test *and if the form submission contained data* for that field, all the 502 validators for that field are called in turn. The emphasized portion in the520 After a form has been submitted, Django validates each field in turn. First, 521 if the field is required, Django checks that it is present and non-empty. Then, 522 if that test passes *and the form submission contained data* for that field, all 523 the validators for that field are called in turn. The emphasized portion in the 503 524 last sentence is important: if a form field is not submitted (because it 504 525 contains no data -- which is normal HTML behavior), the validators are not … … 547 568 * isValidANSITime 548 569 * isValidEmail 570 * isValidFloat 549 571 * isValidImage 550 572 * isValidImageURL … … 595 617 against the current field. 596 618 619 ``RequiredIfOtherFieldGiven`` 620 Takes a field name of the current field is only required if the other 621 field has a value. 622 623 ``RequiredIfOtherFieldsGiven`` 624 Similar to ``RequiredIfOtherFieldGiven``, except that it takes a list of 625 field names and if any one of the supplied fields has a value provided, 626 the current field being validated is required. 627 597 628 ``RequiredIfOtherFieldNotGiven`` 598 629 Takes the name of the other field and this field is only required if the 599 630 other field has no value. 600 601 ``RequiredIfOtherFieldsNotGiven``602 Similar to ``RequiredIfOtherFieldNotGiven``, except that it takes a list603 of field names and if any one of the supplied fields does not have a value604 provided, the field being validated is required.605 631 606 632 ``RequiredIfOtherFieldEquals`` and ``RequiredIfOtherFieldDoesNotEqual`` … … 608 634 order). If the given field does (or does not have, in the latter case) the 609 635 given value, then the current field being validated is required. 636 637 An optional ``other_label`` argument can be passed which, if given, is used 638 in error messages instead of the value. This allows more user friendly error 639 messages if the value itself is not descriptive enough. 610 640 611 641 Note that because validators are called before any ``do_html2python()`` … … 626 656 Takes two boundary numbers, ``lower`` and ``upper``, and checks that the 627 657 field is greater than ``lower`` (if given) and less than ``upper`` (if 628 given). 629 658 given). 659 630 660 Both checks are inclusive. That is, ``NumberIsInRange(10, 20)`` will allow 631 661 values of both 10 and 20. This validator only checks numeric values … … 636 666 field being validated is a power of the integer. 637 667 638 ``IsValid Float``668 ``IsValidDecimal`` 639 669 Takes a maximum number of digits and number of decimal places (in that 640 order) and validates whether the field is a float with lessthan the641 maximum number of digits and decimal place .670 order) and validates whether the field is a decimal with no more than the 671 maximum number of digits and decimal places. 642 672 643 673 ``MatchesRegularExpression`` … … 666 696 document for more details). 667 697 668 .. _`generic views`: http://www.djangoproject.com/documentation/generic_views/669 .. _`models API`: http://www.djangoproject.com/documentation/model_api/670 .. _settings: http://www.djangoproject.com/documentation/settings/698 .. _`generic views`: ../generic_views/ 699 .. _`models API`: ../model-api/ 700 .. _settings: ../settings/
