Ticket #4167: django-0.91-formfield-list-mutability-fix.patch
File django-0.91-formfield-list-mutability-fix.patch, 12.6 KB (added by , 18 years ago) |
---|
-
django/core/formfields.py
325 325 326 326 class TextField(FormField): 327 327 input_type = "text" 328 def __init__(self, field_name, length=30, maxlength=None, is_required=False, validator_list=[], member_name=None): 328 def __init__(self, field_name, length=30, maxlength=None, is_required=False, validator_list=None, member_name=None): 329 if validator_list is None: validator_list = [] 329 330 self.field_name = field_name 330 331 self.length, self.maxlength = length, maxlength 331 332 self.is_required = is_required … … 362 363 input_type = "password" 363 364 364 365 class LargeTextField(TextField): 365 def __init__(self, field_name, rows=10, cols=40, is_required=False, validator_list=[], maxlength=None): 366 def __init__(self, field_name, rows=10, cols=40, is_required=False, validator_list=None, maxlength=None): 367 if validator_list is None: validator_list = [] 366 368 self.field_name = field_name 367 369 self.rows, self.cols, self.is_required = rows, cols, is_required 368 370 self.validator_list = validator_list[:] … … 380 382 self.field_name, self.rows, self.cols, escape(data)) 381 383 382 384 class HiddenField(FormField): 383 def __init__(self, field_name, is_required=False, validator_list=[]): 385 def __init__(self, field_name, is_required=False, validator_list=None): 386 if validator_list is None: validator_list = [] 384 387 self.field_name, self.is_required = field_name, is_required 385 388 self.validator_list = validator_list[:] 386 389 … … 410 413 html2python = staticmethod(html2python) 411 414 412 415 class SelectField(FormField): 413 def __init__(self, field_name, choices=[], size=1, is_required=False, validator_list=[], member_name=None): 416 def __init__(self, field_name, choices=[], size=1, is_required=False, validator_list=None, member_name=None): 417 if validator_list is None: validator_list = [] 414 418 self.field_name = field_name 415 419 # choices is a list of (value, human-readable key) tuples because order matters 416 420 self.choices, self.size, self.is_required = choices, size, is_required … … 446 450 html2python = staticmethod(html2python) 447 451 448 452 class RadioSelectField(FormField): 449 def __init__(self, field_name, choices=[], ul_class='', is_required=False, validator_list=[], member_name=None): 453 def __init__(self, field_name, choices=[], ul_class='', is_required=False, validator_list=None, member_name=None): 454 if validator_list is None: validator_list = [] 450 455 self.field_name = field_name 451 456 # choices is a list of (value, human-readable key) tuples because order matters 452 457 self.choices, self.is_required = choices, is_required … … 510 515 511 516 class NullBooleanField(SelectField): 512 517 "This SelectField provides 'Yes', 'No' and 'Unknown', mapping results to True, False or None" 513 def __init__(self, field_name, is_required=False, validator_list=[]): 518 def __init__(self, field_name, is_required=False, validator_list=None): 519 if validator_list is None: validator_list = [] 514 520 SelectField.__init__(self, field_name, choices=[('1', 'Unknown'), ('2', 'Yes'), ('3', 'No')], 515 521 is_required=is_required, validator_list=validator_list) 516 522 … … 563 569 back into the single list that validators, renderers and save() expect. 564 570 """ 565 571 requires_data_list = True 566 def __init__(self, field_name, choices=[], validator_list=[]): 572 def __init__(self, field_name, choices=[], validator_list=None): 573 if validator_list is None: validator_list = [] 567 574 SelectMultipleField.__init__(self, field_name, choices, size=1, is_required=False, validator_list=validator_list) 568 575 569 576 def prepare(self, new_data): … … 594 601 #################### 595 602 596 603 class FileUploadField(FormField): 597 def __init__(self, field_name, is_required=False, validator_list=[]): 604 def __init__(self, field_name, is_required=False, validator_list=None): 605 if validator_list is None: validator_list = [] 598 606 self.field_name, self.is_required = field_name, is_required 599 607 self.validator_list = [self.isNonEmptyFile] + validator_list 600 608 … … 629 637 #################### 630 638 631 639 class IntegerField(TextField): 632 def __init__(self, field_name, length=10, maxlength=None, is_required=False, validator_list=[], member_name=None): 640 def __init__(self, field_name, length=10, maxlength=None, is_required=False, validator_list=None, member_name=None): 641 if validator_list is None: validator_list = [] 633 642 validator_list = [self.isInteger] + validator_list 634 643 if member_name is not None: 635 644 self.member_name = member_name … … 648 657 html2python = staticmethod(html2python) 649 658 650 659 class SmallIntegerField(IntegerField): 651 def __init__(self, field_name, length=5, maxlength=5, is_required=False, validator_list=[]): 660 def __init__(self, field_name, length=5, maxlength=5, is_required=False, validator_list=None): 661 if validator_list is None: validator_list = [] 652 662 validator_list = [self.isSmallInteger] + validator_list 653 663 IntegerField.__init__(self, field_name, length, maxlength, is_required, validator_list) 654 664 … … 657 667 raise validators.CriticalValidationError, _("Enter a whole number between -32,768 and 32,767.") 658 668 659 669 class PositiveIntegerField(IntegerField): 660 def __init__(self, field_name, length=10, maxlength=None, is_required=False, validator_list=[]): 670 def __init__(self, field_name, length=10, maxlength=None, is_required=False, validator_list=None): 671 if validator_list is None: validator_list = [] 661 672 validator_list = [self.isPositive] + validator_list 662 673 IntegerField.__init__(self, field_name, length, maxlength, is_required, validator_list) 663 674 … … 666 677 raise validators.CriticalValidationError, _("Enter a positive number.") 667 678 668 679 class PositiveSmallIntegerField(IntegerField): 669 def __init__(self, field_name, length=5, maxlength=None, is_required=False, validator_list=[]): 680 def __init__(self, field_name, length=5, maxlength=None, is_required=False, validator_list=None): 681 if validator_list is None: validator_list = [] 670 682 validator_list = [self.isPositiveSmall] + validator_list 671 683 IntegerField.__init__(self, field_name, length, maxlength, is_required, validator_list) 672 684 … … 675 687 raise validators.CriticalValidationError, _("Enter a whole number between 0 and 32,767.") 676 688 677 689 class FloatField(TextField): 678 def __init__(self, field_name, max_digits, decimal_places, is_required=False, validator_list=[]): 690 def __init__(self, field_name, max_digits, decimal_places, is_required=False, validator_list=None): 691 if validator_list is None: validator_list = [] 679 692 self.max_digits, self.decimal_places = max_digits, decimal_places 680 693 validator_list = [self.isValidFloat] + validator_list 681 694 TextField.__init__(self, field_name, max_digits+1, max_digits+1, is_required, validator_list) … … 700 713 class DatetimeField(TextField): 701 714 """A FormField that automatically converts its data to a datetime.datetime object. 702 715 The data should be in the format YYYY-MM-DD HH:MM:SS.""" 703 def __init__(self, field_name, length=30, maxlength=None, is_required=False, validator_list=[]): 716 def __init__(self, field_name, length=30, maxlength=None, is_required=False, validator_list=None): 717 if validator_list is None: validator_list = [] 704 718 self.field_name = field_name 705 719 self.length, self.maxlength = length, maxlength 706 720 self.is_required = is_required … … 723 737 class DateField(TextField): 724 738 """A FormField that automatically converts its data to a datetime.date object. 725 739 The data should be in the format YYYY-MM-DD.""" 726 def __init__(self, field_name, is_required=False, validator_list=[]): 740 def __init__(self, field_name, is_required=False, validator_list=None): 741 if validator_list is None: validator_list = [] 727 742 validator_list = [self.isValidDate] + validator_list 728 743 TextField.__init__(self, field_name, length=10, maxlength=10, 729 744 is_required=is_required, validator_list=validator_list) … … 747 762 class TimeField(TextField): 748 763 """A FormField that automatically converts its data to a datetime.time object. 749 764 The data should be in the format HH:MM:SS or HH:MM:SS.mmmmmm.""" 750 def __init__(self, field_name, is_required=False, validator_list=[]): 765 def __init__(self, field_name, is_required=False, validator_list=None): 766 if validator_list is None: validator_list = [] 751 767 validator_list = [self.isValidTime] + validator_list 752 768 TextField.__init__(self, field_name, length=8, maxlength=8, 753 769 is_required=is_required, validator_list=validator_list) … … 781 797 782 798 class EmailField(TextField): 783 799 "A convenience FormField for validating e-mail addresses" 784 def __init__(self, field_name, length=50, maxlength=75, is_required=False, validator_list=[]): 800 def __init__(self, field_name, length=50, maxlength=75, is_required=False, validator_list=None): 801 if validator_list is None: validator_list = [] 785 802 validator_list = [self.isValidEmail] + validator_list 786 803 TextField.__init__(self, field_name, length, maxlength=maxlength, 787 804 is_required=is_required, validator_list=validator_list) … … 794 811 795 812 class URLField(TextField): 796 813 "A convenience FormField for validating URLs" 797 def __init__(self, field_name, length=50, is_required=False, validator_list=[]): 814 def __init__(self, field_name, length=50, is_required=False, validator_list=None): 815 if validator_list is None: validator_list = [] 798 816 validator_list = [self.isValidURL] + validator_list 799 817 TextField.__init__(self, field_name, length=length, maxlength=200, 800 818 is_required=is_required, validator_list=validator_list) … … 806 824 raise validators.CriticalValidationError, e.messages 807 825 808 826 class IPAddressField(TextField): 809 def __init__(self, field_name, length=15, maxlength=15, is_required=False, validator_list=[]): 827 def __init__(self, field_name, length=15, maxlength=15, is_required=False, validator_list=None): 828 if validator_list is None: validator_list = [] 810 829 validator_list = [self.isValidIPAddress] + validator_list 811 830 TextField.__init__(self, field_name, length=length, maxlength=maxlength, 812 831 is_required=is_required, validator_list=validator_list) … … 827 846 828 847 class FilePathField(SelectField): 829 848 "A SelectField whose choices are the files in a given directory." 830 def __init__(self, field_name, path, match=None, recursive=False, is_required=False, validator_list=[]): 849 def __init__(self, field_name, path, match=None, recursive=False, is_required=False, validator_list=None): 850 if validator_list is None: validator_list = [] 831 851 import os 832 852 if match is not None: 833 853 import re … … 850 870 851 871 class PhoneNumberField(TextField): 852 872 "A convenience FormField for validating phone numbers (e.g. '630-555-1234')" 853 def __init__(self, field_name, is_required=False, validator_list=[]): 873 def __init__(self, field_name, is_required=False, validator_list=None): 874 if validator_list is None: validator_list = [] 854 875 validator_list = [self.isValidPhone] + validator_list 855 876 TextField.__init__(self, field_name, length=12, maxlength=12, 856 877 is_required=is_required, validator_list=validator_list) … … 863 884 864 885 class USStateField(TextField): 865 886 "A convenience FormField for validating U.S. states (e.g. 'IL')" 866 def __init__(self, field_name, is_required=False, validator_list=[]): 887 def __init__(self, field_name, is_required=False, validator_list=None): 888 if validator_list is None: validator_list = [] 867 889 validator_list = [self.isValidUSState] + validator_list 868 890 TextField.__init__(self, field_name, length=2, maxlength=2, 869 891 is_required=is_required, validator_list=validator_list) … … 883 905 884 906 class CommaSeparatedIntegerField(TextField): 885 907 "A convenience FormField for validating comma-separated integer fields" 886 def __init__(self, field_name, maxlength=None, is_required=False, validator_list=[]): 908 def __init__(self, field_name, maxlength=None, is_required=False, validator_list=None): 909 if validator_list is None: validator_list = [] 887 910 validator_list = [self.isCommaSeparatedIntegerList] + validator_list 888 911 TextField.__init__(self, field_name, length=20, maxlength=maxlength, 889 912 is_required=is_required, validator_list=validator_list)