-
diff --git a/django/contrib/localflavor/ar/forms.py b/django/contrib/localflavor/ar/forms.py
index 6374a48..a348a35 100644
a
|
b
|
class ARPostalCodeField(RegexField):
|
32 | 32 | super(ARPostalCodeField, self).__init__(r'^\d{4}$|^[A-HJ-NP-Za-hj-np-z]\d{4}\D{3}$', |
33 | 33 | min_length=4, max_length=8, *args, **kwargs) |
34 | 34 | |
35 | | def clean(self, value): |
36 | | value = super(ARPostalCodeField, self).clean(value) |
| 35 | def clean(self, value, initial=None): |
| 36 | value = super(ARPostalCodeField, self).clean(value, initial) |
37 | 37 | if value in EMPTY_VALUES: |
38 | 38 | return u'' |
39 | 39 | if len(value) not in (4, 8): |
… |
… |
class ARDNIField(CharField):
|
55 | 55 | super(ARDNIField, self).__init__(max_length=10, min_length=7, *args, |
56 | 56 | **kwargs) |
57 | 57 | |
58 | | def clean(self, value): |
| 58 | def clean(self, value, initial=None): |
59 | 59 | """ |
60 | 60 | Value can be a string either in the [X]X.XXX.XXX or [X]XXXXXXX formats. |
61 | 61 | """ |
62 | | value = super(ARDNIField, self).clean(value) |
| 62 | value = super(ARDNIField, self).clean(value, initial) |
63 | 63 | if value in EMPTY_VALUES: |
64 | 64 | return u'' |
65 | 65 | if not value.isdigit(): |
… |
… |
class ARCUITField(RegexField):
|
85 | 85 | super(ARCUITField, self).__init__(r'^\d{2}-?\d{8}-?\d$', |
86 | 86 | *args, **kwargs) |
87 | 87 | |
88 | | def clean(self, value): |
| 88 | def clean(self, value, initial=None): |
89 | 89 | """ |
90 | 90 | Value can be either a string in the format XX-XXXXXXXX-X or an |
91 | 91 | 11-digit number. |
92 | 92 | """ |
93 | | value = super(ARCUITField, self).clean(value) |
| 93 | value = super(ARCUITField, self).clean(value, initial) |
94 | 94 | if value in EMPTY_VALUES: |
95 | 95 | return u'' |
96 | 96 | value, cd = self._canon(value) |
-
diff --git a/django/contrib/localflavor/au/forms.py b/django/contrib/localflavor/au/forms.py
index ada27b6..ed3665c 100644
a
|
b
|
class AUPhoneNumberField(Field):
|
26 | 26 | 'invalid': u'Phone numbers must contain 10 digits.', |
27 | 27 | } |
28 | 28 | |
29 | | def clean(self, value): |
| 29 | def clean(self, value, initial=None): |
30 | 30 | """ |
31 | 31 | Validate a phone number. Strips parentheses, whitespace and hyphens. |
32 | 32 | """ |
33 | | super(AUPhoneNumberField, self).clean(value) |
| 33 | super(AUPhoneNumberField, self).clean(value, initial) |
34 | 34 | if value in EMPTY_VALUES: |
35 | 35 | return u'' |
36 | 36 | value = re.sub('(\(|\)|\s+|-)', '', smart_unicode(value)) |
-
diff --git a/django/contrib/localflavor/br/forms.py b/django/contrib/localflavor/br/forms.py
index aa7e3b2..32a6dd2 100644
a
|
b
|
class BRPhoneNumberField(Field):
|
30 | 30 | 'invalid': _('Phone numbers must be in XX-XXXX-XXXX format.'), |
31 | 31 | } |
32 | 32 | |
33 | | def clean(self, value): |
34 | | super(BRPhoneNumberField, self).clean(value) |
| 33 | def clean(self, value, initial=None): |
| 34 | super(BRPhoneNumberField, self).clean(value, initial) |
35 | 35 | if value in EMPTY_VALUES: |
36 | 36 | return u'' |
37 | 37 | value = re.sub('(\(|\)|\s+)', '', smart_unicode(value)) |
… |
… |
class BRStateChoiceField(Field):
|
65 | 65 | from br_states import STATE_CHOICES |
66 | 66 | self.widget.choices = STATE_CHOICES |
67 | 67 | |
68 | | def clean(self, value): |
69 | | value = super(BRStateChoiceField, self).clean(value) |
| 68 | def clean(self, value, initial=None): |
| 69 | value = super(BRStateChoiceField, self).clean(value, initial) |
70 | 70 | if value in EMPTY_VALUES: |
71 | 71 | value = u'' |
72 | 72 | value = smart_unicode(value) |
… |
… |
class BRCPFField(CharField):
|
99 | 99 | def __init__(self, *args, **kwargs): |
100 | 100 | super(BRCPFField, self).__init__(max_length=14, min_length=11, *args, **kwargs) |
101 | 101 | |
102 | | def clean(self, value): |
| 102 | def clean(self, value, initial=None): |
103 | 103 | """ |
104 | 104 | Value can be either a string in the format XXX.XXX.XXX-XX or an |
105 | 105 | 11-digit number. |
106 | 106 | """ |
107 | | value = super(BRCPFField, self).clean(value) |
| 107 | value = super(BRCPFField, self).clean(value, initial) |
108 | 108 | if value in EMPTY_VALUES: |
109 | 109 | return u'' |
110 | 110 | orig_value = value[:] |
… |
… |
class BRCNPJField(Field):
|
136 | 136 | 'max_digits': _("This field requires at least 14 digits"), |
137 | 137 | } |
138 | 138 | |
139 | | def clean(self, value): |
| 139 | def clean(self, value, initial=None): |
140 | 140 | """ |
141 | 141 | Value can be either a string in the format XX.XXX.XXX/XXXX-XX or a |
142 | 142 | group of 14 characters. |
143 | 143 | """ |
144 | | value = super(BRCNPJField, self).clean(value) |
| 144 | value = super(BRCNPJField, self).clean(value, initial) |
145 | 145 | if value in EMPTY_VALUES: |
146 | 146 | return u'' |
147 | 147 | orig_value = value[:] |
-
diff --git a/django/contrib/localflavor/ca/forms.py b/django/contrib/localflavor/ca/forms.py
index b40dba8..fb9e986 100644
a
|
b
|
class CAPhoneNumberField(Field):
|
27 | 27 | 'invalid': u'Phone numbers must be in XXX-XXX-XXXX format.', |
28 | 28 | } |
29 | 29 | |
30 | | def clean(self, value): |
| 30 | def clean(self, value, initial=None): |
31 | 31 | """Validate a phone number. |
32 | 32 | """ |
33 | | super(CAPhoneNumberField, self).clean(value) |
| 33 | super(CAPhoneNumberField, self).clean(value, initial) |
34 | 34 | if value in EMPTY_VALUES: |
35 | 35 | return u'' |
36 | 36 | value = re.sub('(\(|\)|\s+)', '', smart_unicode(value)) |
… |
… |
class CAProvinceField(Field):
|
49 | 49 | 'invalid': u'Enter a Canadian province or territory.', |
50 | 50 | } |
51 | 51 | |
52 | | def clean(self, value): |
| 52 | def clean(self, value, initial=None): |
53 | 53 | from ca_provinces import PROVINCES_NORMALIZED |
54 | | super(CAProvinceField, self).clean(value) |
| 54 | super(CAProvinceField, self).clean(value, initial) |
55 | 55 | if value in EMPTY_VALUES: |
56 | 56 | return u'' |
57 | 57 | try: |
… |
… |
class CASocialInsuranceNumberField(Field):
|
88 | 88 | 'invalid': ugettext('Enter a valid Canadian Social Insurance number in XXX-XXX-XXX format.'), |
89 | 89 | } |
90 | 90 | |
91 | | def clean(self, value): |
92 | | super(CASocialInsuranceNumberField, self).clean(value) |
| 91 | def clean(self, value, initial=None): |
| 92 | super(CASocialInsuranceNumberField, self).clean(value, initial) |
93 | 93 | if value in EMPTY_VALUES: |
94 | 94 | return u'' |
95 | 95 | |
-
diff --git a/django/contrib/localflavor/ch/forms.py b/django/contrib/localflavor/ch/forms.py
index 2158fba..884392b 100644
a
|
b
|
class CHPhoneNumberField(Field):
|
31 | 31 | 'invalid': 'Phone numbers must be in 0XX XXX XX XX format.', |
32 | 32 | } |
33 | 33 | |
34 | | def clean(self, value): |
35 | | super(CHPhoneNumberField, self).clean(value) |
| 34 | def clean(self, value, initial=None): |
| 35 | super(CHPhoneNumberField, self).clean(value, initial) |
36 | 36 | if value in EMPTY_VALUES: |
37 | 37 | return u'' |
38 | 38 | value = re.sub('(\.|\s|/|-)', '', smart_unicode(value)) |
… |
… |
class CHIdentityCardNumberField(Field):
|
95 | 95 | |
96 | 96 | return str(calculated_checksum)[-1] == given_checksum |
97 | 97 | |
98 | | def clean(self, value): |
99 | | super(CHIdentityCardNumberField, self).clean(value) |
| 98 | def clean(self, value, initial=None): |
| 99 | super(CHIdentityCardNumberField, self).clean(value, initial) |
100 | 100 | if value in EMPTY_VALUES: |
101 | 101 | return u'' |
102 | 102 | |
-
diff --git a/django/contrib/localflavor/cl/forms.py b/django/contrib/localflavor/cl/forms.py
index 2f5ac29..89f4daa 100644
a
|
b
|
class CLRutField(RegexField):
|
41 | 41 | # the real world. |
42 | 42 | super(CLRutField, self).__init__(r'^[\d\.]{1,11}-?[\dkK]$', *args, **kwargs) |
43 | 43 | |
44 | | def clean(self, value): |
| 44 | def clean(self, value, initial=None): |
45 | 45 | """ |
46 | 46 | Check and clean the Chilean RUT. |
47 | 47 | """ |
48 | | super(CLRutField, self).clean(value) |
| 48 | super(CLRutField, self).clean(value, initial) |
49 | 49 | if value in EMPTY_VALUES: |
50 | 50 | return u'' |
51 | 51 | rut, verificador = self._canonify(value) |
-
diff --git a/django/contrib/localflavor/de/forms.py b/django/contrib/localflavor/de/forms.py
index 76ce215..0658d25 100644
a
|
b
|
class DEIdentityCardNumberField(Field):
|
60 | 60 | |
61 | 61 | return str(calculated_checksum)[-1] == given_checksum |
62 | 62 | |
63 | | def clean(self, value): |
64 | | super(DEIdentityCardNumberField, self).clean(value) |
| 63 | def clean(self, value, initial=None): |
| 64 | super(DEIdentityCardNumberField, self).clean(value, initial) |
65 | 65 | if value in EMPTY_VALUES: |
66 | 66 | return u'' |
67 | 67 | match = re.match(id_re, value) |
-
diff --git a/django/contrib/localflavor/es/forms.py b/django/contrib/localflavor/es/forms.py
index 81186f8..aeb96de 100644
a
|
b
|
class ESIdentityCardNumberField(RegexField):
|
81 | 81 | error_message=self.default_error_messages['invalid%s' % (self.only_nif and '_only_nif' or '')], |
82 | 82 | *args, **kwargs) |
83 | 83 | |
84 | | def clean(self, value): |
85 | | super(ESIdentityCardNumberField, self).clean(value) |
| 84 | def clean(self, value, initial=None): |
| 85 | super(ESIdentityCardNumberField, self).clean(value, initial) |
86 | 86 | if value in EMPTY_VALUES: |
87 | 87 | return u'' |
88 | 88 | nif_get_checksum = lambda d: self.nif_control[int(d)%23] |
… |
… |
class ESCCCField(RegexField):
|
147 | 147 | super(ESCCCField, self).__init__(r'^\d{4}[ -]?\d{4}[ -]?\d{2}[ -]?\d{10}$', |
148 | 148 | max_length=None, min_length=None, *args, **kwargs) |
149 | 149 | |
150 | | def clean(self, value): |
151 | | super(ESCCCField, self).clean(value) |
| 150 | def clean(self, value, initial=None): |
| 151 | super(ESCCCField, self).clean(value, initial) |
152 | 152 | if value in EMPTY_VALUES: |
153 | 153 | return u'' |
154 | 154 | control_str = [1, 2, 4, 8, 5, 10, 9, 7, 3, 6] |
-
diff --git a/django/contrib/localflavor/fi/forms.py b/django/contrib/localflavor/fi/forms.py
index a0274da..4c0c57a 100644
a
|
b
|
class FISocialSecurityNumber(Field):
|
28 | 28 | 'invalid': ugettext('Enter a valid Finnish social security number.'), |
29 | 29 | } |
30 | 30 | |
31 | | def clean(self, value): |
32 | | super(FISocialSecurityNumber, self).clean(value) |
| 31 | def clean(self, value, initial=None): |
| 32 | super(FISocialSecurityNumber, self).clean(value, initial) |
33 | 33 | if value in EMPTY_VALUES: |
34 | 34 | return u'' |
35 | 35 | |
-
diff --git a/django/contrib/localflavor/fr/forms.py b/django/contrib/localflavor/fr/forms.py
index 635b62e..7408deb 100644
a
|
b
|
class FRPhoneNumberField(Field):
|
30 | 30 | 'invalid': u'Phone numbers must be in 0X XX XX XX XX format.', |
31 | 31 | } |
32 | 32 | |
33 | | def clean(self, value): |
34 | | super(FRPhoneNumberField, self).clean(value) |
| 33 | def clean(self, value, initial=None): |
| 34 | super(FRPhoneNumberField, self).clean(value, initial) |
35 | 35 | if value in EMPTY_VALUES: |
36 | 36 | return u'' |
37 | 37 | value = re.sub('(\.|\s)', '', smart_unicode(value)) |
-
diff --git a/django/contrib/localflavor/in_/forms.py b/django/contrib/localflavor/in_/forms.py
index 1cb303d..c323366 100644
a
|
b
|
class INStateField(Field):
|
28 | 28 | 'invalid': u'Enter a Indian state or territory.', |
29 | 29 | } |
30 | 30 | |
31 | | def clean(self, value): |
| 31 | def clean(self, value, initial=None): |
32 | 32 | from in_states import STATES_NORMALIZED |
33 | | super(INStateField, self).clean(value) |
| 33 | super(INStateField, self).clean(value, initial) |
34 | 34 | if value in EMPTY_VALUES: |
35 | 35 | return u'' |
36 | 36 | try: |
-
diff --git a/django/contrib/localflavor/is_/forms.py b/django/contrib/localflavor/is_/forms.py
index ea7a1e0..e7bba15 100644
a
|
b
|
class ISIdNumberField(RegexField):
|
22 | 22 | kwargs['min_length'],kwargs['max_length'] = 10,11 |
23 | 23 | super(ISIdNumberField, self).__init__(r'^\d{6}(-| )?\d{4}$', *args, **kwargs) |
24 | 24 | |
25 | | def clean(self, value): |
26 | | value = super(ISIdNumberField, self).clean(value) |
| 25 | def clean(self, value, initial=None): |
| 26 | value = super(ISIdNumberField, self).clean(value, initial) |
27 | 27 | |
28 | 28 | if value in EMPTY_VALUES: |
29 | 29 | return u'' |
… |
… |
class ISPhoneNumberField(RegexField):
|
64 | 64 | kwargs['min_length'], kwargs['max_length'] = 7,8 |
65 | 65 | super(ISPhoneNumberField, self).__init__(r'^\d{3}(-| )?\d{4}$', *args, **kwargs) |
66 | 66 | |
67 | | def clean(self, value): |
68 | | value = super(ISPhoneNumberField, self).clean(value) |
| 67 | def clean(self, value, initial=None): |
| 68 | value = super(ISPhoneNumberField, self).clean(value, initial) |
69 | 69 | |
70 | 70 | if value in EMPTY_VALUES: |
71 | 71 | return u'' |
-
diff --git a/django/contrib/localflavor/it/forms.py b/django/contrib/localflavor/it/forms.py
index 88e6573..6d53780 100644
a
|
b
|
class ITSocialSecurityNumberField(RegexField):
|
47 | 47 | super(ITSocialSecurityNumberField, self).__init__(r'^\w{3}\s*\w{3}\s*\w{5}\s*\w{5}$', |
48 | 48 | max_length=None, min_length=None, *args, **kwargs) |
49 | 49 | |
50 | | def clean(self, value): |
51 | | value = super(ITSocialSecurityNumberField, self).clean(value) |
| 50 | def clean(self, value, initial=None): |
| 51 | value = super(ITSocialSecurityNumberField, self).clean(value, initial) |
52 | 52 | if value == u'': |
53 | 53 | return value |
54 | 54 | value = re.sub('\s', u'', value).upper() |
… |
… |
class ITVatNumberField(Field):
|
68 | 68 | 'invalid': ugettext(u'Enter a valid VAT number.'), |
69 | 69 | } |
70 | 70 | |
71 | | def clean(self, value): |
72 | | value = super(ITVatNumberField, self).clean(value) |
| 71 | def clean(self, value, initial=None): |
| 72 | value = super(ITVatNumberField, self).clean(value, initial) |
73 | 73 | if value == u'': |
74 | 74 | return value |
75 | 75 | try: |
-
diff --git a/django/contrib/localflavor/jp/forms.py b/django/contrib/localflavor/jp/forms.py
index 13083aa..e856260 100644
a
|
b
|
class JPPostalCodeField(RegexField):
|
23 | 23 | super(JPPostalCodeField, self).__init__(r'^\d{3}-\d{4}$|^\d{7}$', |
24 | 24 | max_length=None, min_length=None, *args, **kwargs) |
25 | 25 | |
26 | | def clean(self, value): |
| 26 | def clean(self, value, initial=None): |
27 | 27 | """ |
28 | 28 | Validates the input and returns a string that contains only numbers. |
29 | 29 | Returns an empty string for empty values. |
30 | 30 | """ |
31 | | v = super(JPPostalCodeField, self).clean(value) |
| 31 | v = super(JPPostalCodeField, self).clean(value, initial) |
32 | 32 | return v.replace('-', '') |
33 | 33 | |
34 | 34 | class JPPrefectureSelect(Select): |
-
diff --git a/django/contrib/localflavor/nl/forms.py b/django/contrib/localflavor/nl/forms.py
index 7484849..7bb1a30 100644
a
|
b
|
class NLZipCodeField(Field):
|
21 | 21 | 'invalid': _('Enter a valid postal code'), |
22 | 22 | } |
23 | 23 | |
24 | | def clean(self, value): |
25 | | super(NLZipCodeField, self).clean(value) |
| 24 | def clean(self, value, initial=None): |
| 25 | super(NLZipCodeField, self).clean(value, initial) |
26 | 26 | if value in EMPTY_VALUES: |
27 | 27 | return u'' |
28 | 28 | |
… |
… |
class NLPhoneNumberField(Field):
|
52 | 52 | 'invalid': _('Enter a valid phone number'), |
53 | 53 | } |
54 | 54 | |
55 | | def clean(self, value): |
56 | | super(NLPhoneNumberField, self).clean(value) |
| 55 | def clean(self, value, initial=None): |
| 56 | super(NLPhoneNumberField, self).clean(value, initial) |
57 | 57 | if value in EMPTY_VALUES: |
58 | 58 | return u'' |
59 | 59 | |
… |
… |
class NLSoFiNumberField(Field):
|
78 | 78 | 'invalid': _('Enter a valid SoFi number'), |
79 | 79 | } |
80 | 80 | |
81 | | def clean(self, value): |
82 | | super(NLSoFiNumberField, self).clean(value) |
| 81 | def clean(self, value, initial=None): |
| 82 | super(NLSoFiNumberField, self).clean(value, initial) |
83 | 83 | if value in EMPTY_VALUES: |
84 | 84 | return u'' |
85 | 85 | |
-
diff --git a/django/contrib/localflavor/no/forms.py b/django/contrib/localflavor/no/forms.py
index 8dc0019..94e039f 100644
a
|
b
|
class NOSocialSecurityNumber(Field):
|
33 | 33 | 'invalid': ugettext(u'Enter a valid Norwegian social security number.'), |
34 | 34 | } |
35 | 35 | |
36 | | def clean(self, value): |
37 | | super(NOSocialSecurityNumber, self).clean(value) |
| 36 | def clean(self, value, initial=None): |
| 37 | super(NOSocialSecurityNumber, self).clean(value, initial) |
38 | 38 | if value in EMPTY_VALUES: |
39 | 39 | return u'' |
40 | 40 | |
-
diff --git a/django/contrib/localflavor/pe/forms.py b/django/contrib/localflavor/pe/forms.py
index 57c9d44..4b86eee 100644
a
|
b
|
class PEDNIField(CharField):
|
28 | 28 | super(PEDNIField, self).__init__(max_length=8, min_length=8, *args, |
29 | 29 | **kwargs) |
30 | 30 | |
31 | | def clean(self, value): |
| 31 | def clean(self, value, initial=None): |
32 | 32 | """ |
33 | 33 | Value must be a string in the XXXXXXXX formats. |
34 | 34 | """ |
35 | | value = super(PEDNIField, self).clean(value) |
| 35 | value = super(PEDNIField, self).clean(value, initial) |
36 | 36 | if value in EMPTY_VALUES: |
37 | 37 | return u'' |
38 | 38 | if not value.isdigit(): |
… |
… |
class PERUCField(RegexField):
|
56 | 56 | super(PERUCField, self).__init__(max_length=11, min_length=11, *args, |
57 | 57 | **kwargs) |
58 | 58 | |
59 | | def clean(self, value): |
| 59 | def clean(self, value, initial=None): |
60 | 60 | """ |
61 | 61 | Value must be an 11-digit number. |
62 | 62 | """ |
63 | | value = super(PERUCField, self).clean(value) |
| 63 | value = super(PERUCField, self).clean(value, initial) |
64 | 64 | if value in EMPTY_VALUES: |
65 | 65 | return u'' |
66 | 66 | if not value.isdigit(): |
-
diff --git a/django/contrib/localflavor/pl/forms.py b/django/contrib/localflavor/pl/forms.py
index b02dad7..3b0d9c3 100644
a
|
b
|
class PLNationalIdentificationNumberField(RegexField):
|
44 | 44 | super(PLNationalIdentificationNumberField, self).__init__(r'^\d{11}$', |
45 | 45 | max_length=None, min_length=None, *args, **kwargs) |
46 | 46 | |
47 | | def clean(self,value): |
48 | | super(PLNationalIdentificationNumberField, self).clean(value) |
| 47 | def clean(self, value, initial=None): |
| 48 | super(PLNationalIdentificationNumberField, self).clean(value, initial) |
49 | 49 | if not self.has_valid_checksum(value): |
50 | 50 | raise ValidationError(self.error_messages['checksum']) |
51 | 51 | return u'%s' % value |
… |
… |
class PLTaxNumberField(RegexField):
|
77 | 77 | super(PLTaxNumberField, self).__init__(r'^\d{3}-\d{3}-\d{2}-\d{2}$|^\d{2}-\d{2}-\d{3}-\d{3}$', |
78 | 78 | max_length=None, min_length=None, *args, **kwargs) |
79 | 79 | |
80 | | def clean(self,value): |
81 | | super(PLTaxNumberField, self).clean(value) |
| 80 | def clean(self, value, initial=None): |
| 81 | super(PLTaxNumberField, self).clean(value, initial) |
82 | 82 | value = re.sub("[-]", "", value) |
83 | 83 | if not self.has_valid_checksum(value): |
84 | 84 | raise ValidationError(self.error_messages['checksum']) |
… |
… |
class PLNationalBusinessRegisterField(RegexField):
|
117 | 117 | super(PLNationalBusinessRegisterField, self).__init__(r'^\d{7,9}$', |
118 | 118 | max_length=None, min_length=None, *args, **kwargs) |
119 | 119 | |
120 | | def clean(self,value): |
121 | | super(PLNationalBusinessRegisterField, self).clean(value) |
| 120 | def clean(self, value, initial=None): |
| 121 | super(PLNationalBusinessRegisterField, self).clean(value, initial) |
122 | 122 | if not self.has_valid_checksum(value): |
123 | 123 | raise ValidationError(self.error_messages['checksum']) |
124 | 124 | return u'%s' % value |
-
diff --git a/django/contrib/localflavor/sk/forms.py b/django/contrib/localflavor/sk/forms.py
index 711d70f..127238d 100644
a
|
b
|
class SKPostalCodeField(RegexField):
|
34 | 34 | super(SKPostalCodeField, self).__init__(r'^\d{5}$|^\d{3} \d{2}$', |
35 | 35 | max_length=None, min_length=None, *args, **kwargs) |
36 | 36 | |
37 | | def clean(self, value): |
| 37 | def clean(self, value, initial=None): |
38 | 38 | """ |
39 | 39 | Validates the input and returns a string that contains only numbers. |
40 | 40 | Returns an empty string for empty values. |
41 | 41 | """ |
42 | | v = super(SKPostalCodeField, self).clean(value) |
| 42 | v = super(SKPostalCodeField, self).clean(value, initial) |
43 | 43 | return v.replace(' ', '') |
-
diff --git a/django/contrib/localflavor/uk/forms.py b/django/contrib/localflavor/uk/forms.py
index 52cd7ad..603e5bd 100644
a
|
b
|
class UKPostcodeField(CharField):
|
25 | 25 | postcode_regex = re.compile(r'^(GIR 0AA|%s %s)$' % (outcode_pattern, incode_pattern)) |
26 | 26 | space_regex = re.compile(r' *(%s)$' % incode_pattern) |
27 | 27 | |
28 | | def clean(self, value): |
29 | | value = super(UKPostcodeField, self).clean(value) |
| 28 | def clean(self, value, initial=None): |
| 29 | value = super(UKPostcodeField, self).clean(value, initial) |
30 | 30 | if value == u'': |
31 | 31 | return value |
32 | 32 | postcode = value.upper().strip() |
-
diff --git a/django/contrib/localflavor/us/forms.py b/django/contrib/localflavor/us/forms.py
index d6aa684..721f819 100644
a
|
b
|
class USPhoneNumberField(Field):
|
25 | 25 | 'invalid': u'Phone numbers must be in XXX-XXX-XXXX format.', |
26 | 26 | } |
27 | 27 | |
28 | | def clean(self, value): |
29 | | super(USPhoneNumberField, self).clean(value) |
| 28 | def clean(self, value, initial=None): |
| 29 | super(USPhoneNumberField, self).clean(value, initial) |
30 | 30 | if value in EMPTY_VALUES: |
31 | 31 | return u'' |
32 | 32 | value = re.sub('(\(|\)|\s+)', '', smart_unicode(value)) |
… |
… |
class USSocialSecurityNumberField(Field):
|
54 | 54 | 'invalid': ugettext('Enter a valid U.S. Social Security number in XXX-XX-XXXX format.'), |
55 | 55 | } |
56 | 56 | |
57 | | def clean(self, value): |
58 | | super(USSocialSecurityNumberField, self).clean(value) |
| 57 | def clean(self, value, initial=None): |
| 58 | super(USSocialSecurityNumberField, self).clean(value, initial) |
59 | 59 | if value in EMPTY_VALUES: |
60 | 60 | return u'' |
61 | 61 | match = re.match(ssn_re, value) |
… |
… |
class USStateField(Field):
|
87 | 87 | 'invalid': u'Enter a U.S. state or territory.', |
88 | 88 | } |
89 | 89 | |
90 | | def clean(self, value): |
| 90 | def clean(self, value, initial=None): |
91 | 91 | from us_states import STATES_NORMALIZED |
92 | | super(USStateField, self).clean(value) |
| 92 | super(USStateField, self).clean(value, initial) |
93 | 93 | if value in EMPTY_VALUES: |
94 | 94 | return u'' |
95 | 95 | try: |
-
diff --git a/django/contrib/localflavor/za/forms.py b/django/contrib/localflavor/za/forms.py
index b3613b5..f01c9c3 100644
a
|
b
|
class ZAIDField(Field):
|
20 | 20 | 'invalid': _(u'Enter a valid South African ID number'), |
21 | 21 | } |
22 | 22 | |
23 | | def clean(self, value): |
| 23 | def clean(self, value, initial=None): |
24 | 24 | # strip spaces and dashes |
25 | 25 | value = value.strip().replace(' ', '').replace('-', '') |
26 | 26 | |
27 | | super(ZAIDField, self).clean(value) |
| 27 | super(ZAIDField, self).clean(value, initial) |
28 | 28 | |
29 | 29 | if value in EMPTY_VALUES: |
30 | 30 | return u'' |
-
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index 139a096..7bc6c58 100644
a
|
b
|
class FileField(Field):
|
797 | 797 | return os.path.normpath(f) |
798 | 798 | |
799 | 799 | def save_form_data(self, instance, data): |
800 | | if data: |
| 800 | from django.newforms.fields import UploadedFile |
| 801 | if data and isinstance(data, UploadedFile): |
801 | 802 | getattr(instance, "save_%s_file" % self.name)(data.filename, data.content, save=False) |
802 | 803 | |
803 | 804 | def formfield(self, **kwargs): |
804 | 805 | defaults = {'form_class': forms.FileField} |
805 | | # If a file has been provided previously, then the form doesn't require |
806 | | # that a new file is provided this time. |
807 | | if 'initial' in kwargs: |
808 | | defaults['required'] = False |
809 | 806 | defaults.update(kwargs) |
810 | 807 | return super(FileField, self).formfield(**defaults) |
811 | 808 | |
-
diff --git a/django/newforms/fields.py b/django/newforms/fields.py
index 3b8f419..29f565c 100644
a
|
b
|
class Field(object):
|
93 | 93 | messages.update(error_messages or {}) |
94 | 94 | self.error_messages = messages |
95 | 95 | |
96 | | def clean(self, value): |
| 96 | def clean(self, value, initial=None): |
97 | 97 | """ |
98 | 98 | Validates the given value and returns its "cleaned" value as an |
99 | 99 | appropriate Python object. |
… |
… |
class CharField(Field):
|
128 | 128 | self.max_length, self.min_length = max_length, min_length |
129 | 129 | super(CharField, self).__init__(*args, **kwargs) |
130 | 130 | |
131 | | def clean(self, value): |
| 131 | def clean(self, value, initial=None): |
132 | 132 | "Validates max_length and min_length. Returns a Unicode object." |
133 | | super(CharField, self).clean(value) |
| 133 | super(CharField, self).clean(value, initial) |
134 | 134 | if value in EMPTY_VALUES: |
135 | 135 | return u'' |
136 | 136 | value = smart_unicode(value) |
… |
… |
class IntegerField(Field):
|
157 | 157 | self.max_value, self.min_value = max_value, min_value |
158 | 158 | super(IntegerField, self).__init__(*args, **kwargs) |
159 | 159 | |
160 | | def clean(self, value): |
| 160 | def clean(self, value, initial=None): |
161 | 161 | """ |
162 | 162 | Validates that int() can be called on the input. Returns the result |
163 | 163 | of int(). Returns None for empty values. |
164 | 164 | """ |
165 | | super(IntegerField, self).clean(value) |
| 165 | super(IntegerField, self).clean(value, initial) |
166 | 166 | if value in EMPTY_VALUES: |
167 | 167 | return None |
168 | 168 | try: |
… |
… |
class FloatField(Field):
|
186 | 186 | self.max_value, self.min_value = max_value, min_value |
187 | 187 | Field.__init__(self, *args, **kwargs) |
188 | 188 | |
189 | | def clean(self, value): |
| 189 | def clean(self, value, initial=None): |
190 | 190 | """ |
191 | 191 | Validates that float() can be called on the input. Returns a float. |
192 | 192 | Returns None for empty values. |
193 | 193 | """ |
194 | | super(FloatField, self).clean(value) |
| 194 | super(FloatField, self).clean(value, initial) |
195 | 195 | if not self.required and value in EMPTY_VALUES: |
196 | 196 | return None |
197 | 197 | try: |
… |
… |
class DecimalField(Field):
|
219 | 219 | self.max_digits, self.decimal_places = max_digits, decimal_places |
220 | 220 | Field.__init__(self, *args, **kwargs) |
221 | 221 | |
222 | | def clean(self, value): |
| 222 | def clean(self, value, initial=None): |
223 | 223 | """ |
224 | 224 | Validates that the input is a decimal number. Returns a Decimal |
225 | 225 | instance. Returns None for empty values. Ensures that there are no more |
226 | 226 | than max_digits in the number, and no more than decimal_places digits |
227 | 227 | after the decimal point. |
228 | 228 | """ |
229 | | super(DecimalField, self).clean(value) |
| 229 | super(DecimalField, self).clean(value, initial) |
230 | 230 | if not self.required and value in EMPTY_VALUES: |
231 | 231 | return None |
232 | 232 | value = smart_str(value).strip() |
… |
… |
class DateField(Field):
|
266 | 266 | super(DateField, self).__init__(*args, **kwargs) |
267 | 267 | self.input_formats = input_formats or DEFAULT_DATE_INPUT_FORMATS |
268 | 268 | |
269 | | def clean(self, value): |
| 269 | def clean(self, value, initial=None): |
270 | 270 | """ |
271 | 271 | Validates that the input can be converted to a date. Returns a Python |
272 | 272 | datetime.date object. |
273 | 273 | """ |
274 | | super(DateField, self).clean(value) |
| 274 | super(DateField, self).clean(value, initial) |
275 | 275 | if value in EMPTY_VALUES: |
276 | 276 | return None |
277 | 277 | if isinstance(value, datetime.datetime): |
… |
… |
class TimeField(Field):
|
299 | 299 | super(TimeField, self).__init__(*args, **kwargs) |
300 | 300 | self.input_formats = input_formats or DEFAULT_TIME_INPUT_FORMATS |
301 | 301 | |
302 | | def clean(self, value): |
| 302 | def clean(self, value, initial=None): |
303 | 303 | """ |
304 | 304 | Validates that the input can be converted to a time. Returns a Python |
305 | 305 | datetime.time object. |
306 | 306 | """ |
307 | | super(TimeField, self).clean(value) |
| 307 | super(TimeField, self).clean(value, initial) |
308 | 308 | if value in EMPTY_VALUES: |
309 | 309 | return None |
310 | 310 | if isinstance(value, datetime.time): |
… |
… |
class DateTimeField(Field):
|
338 | 338 | super(DateTimeField, self).__init__(*args, **kwargs) |
339 | 339 | self.input_formats = input_formats or DEFAULT_DATETIME_INPUT_FORMATS |
340 | 340 | |
341 | | def clean(self, value): |
| 341 | def clean(self, value, initial=None): |
342 | 342 | """ |
343 | 343 | Validates that the input can be converted to a datetime. Returns a |
344 | 344 | Python datetime.datetime object. |
345 | 345 | """ |
346 | | super(DateTimeField, self).clean(value) |
| 346 | super(DateTimeField, self).clean(value, initial) |
347 | 347 | if value in EMPTY_VALUES: |
348 | 348 | return None |
349 | 349 | if isinstance(value, datetime.datetime): |
… |
… |
class RegexField(CharField):
|
380 | 380 | regex = re.compile(regex) |
381 | 381 | self.regex = regex |
382 | 382 | |
383 | | def clean(self, value): |
| 383 | def clean(self, value, initial=None): |
384 | 384 | """ |
385 | 385 | Validates that the input matches the regular expression. Returns a |
386 | 386 | Unicode object. |
387 | 387 | """ |
388 | | value = super(RegexField, self).clean(value) |
| 388 | value = super(RegexField, self).clean(value, initial) |
389 | 389 | if value == u'': |
390 | 390 | return value |
391 | 391 | if not self.regex.search(value): |
… |
… |
class FileField(Field):
|
437 | 437 | def __init__(self, *args, **kwargs): |
438 | 438 | super(FileField, self).__init__(*args, **kwargs) |
439 | 439 | |
440 | | def clean(self, data): |
441 | | super(FileField, self).clean(data) |
| 440 | def clean(self, data, initial=None): |
| 441 | super(FileField, self).clean(initial or data) |
442 | 442 | if not self.required and data in EMPTY_VALUES: |
443 | 443 | return None |
| 444 | elif not data and initial: |
| 445 | return initial |
444 | 446 | try: |
445 | 447 | f = UploadedFile(data['filename'], data['content']) |
446 | 448 | except TypeError: |
… |
… |
class ImageField(FileField):
|
456 | 458 | 'invalid_image': _(u"Upload a valid image. The file you uploaded was either not an image or a corrupted image."), |
457 | 459 | } |
458 | 460 | |
459 | | def clean(self, data): |
| 461 | def clean(self, data, initial): |
460 | 462 | """ |
461 | 463 | Checks that the file-upload field data contains a valid image (GIF, JPG, |
462 | 464 | PNG, possibly others -- whatever the Python Imaging Library supports). |
463 | 465 | """ |
464 | | f = super(ImageField, self).clean(data) |
| 466 | f = super(ImageField, self).clean(data, initial) |
465 | 467 | if f is None: |
466 | 468 | return None |
467 | 469 | from PIL import Image |
… |
… |
class URLField(RegexField):
|
500 | 502 | self.verify_exists = verify_exists |
501 | 503 | self.user_agent = validator_user_agent |
502 | 504 | |
503 | | def clean(self, value): |
| 505 | def clean(self, value, initial=None): |
504 | 506 | # If no URL scheme given, assume http:// |
505 | 507 | if value and '://' not in value: |
506 | 508 | value = u'http://%s' % value |
507 | | value = super(URLField, self).clean(value) |
| 509 | value = super(URLField, self).clean(value, initial) |
508 | 510 | if value == u'': |
509 | 511 | return value |
510 | 512 | if self.verify_exists: |
… |
… |
class URLField(RegexField):
|
529 | 531 | class BooleanField(Field): |
530 | 532 | widget = CheckboxInput |
531 | 533 | |
532 | | def clean(self, value): |
| 534 | def clean(self, value, initial=None): |
533 | 535 | """Returns a Python boolean object.""" |
534 | | super(BooleanField, self).clean(value) |
| 536 | super(BooleanField, self).clean(value, initial) |
535 | 537 | # Explicitly check for the string 'False', which is what a hidden field |
536 | 538 | # will submit for False. Because bool("True") == True, we don't need to |
537 | 539 | # handle that explicitly. |
… |
… |
class NullBooleanField(BooleanField):
|
546 | 548 | """ |
547 | 549 | widget = NullBooleanSelect |
548 | 550 | |
549 | | def clean(self, value): |
| 551 | def clean(self, value, initial=None): |
550 | 552 | return {True: True, False: False}.get(value, None) |
551 | 553 | |
552 | 554 | class ChoiceField(Field): |
… |
… |
class ChoiceField(Field):
|
572 | 574 | |
573 | 575 | choices = property(_get_choices, _set_choices) |
574 | 576 | |
575 | | def clean(self, value): |
| 577 | def clean(self, value, initial=None): |
576 | 578 | """ |
577 | 579 | Validates that the input is in self.choices. |
578 | 580 | """ |
579 | | value = super(ChoiceField, self).clean(value) |
| 581 | value = super(ChoiceField, self).clean(value, initial) |
580 | 582 | if value in EMPTY_VALUES: |
581 | 583 | value = u'' |
582 | 584 | value = smart_unicode(value) |
… |
… |
class MultipleChoiceField(ChoiceField):
|
595 | 597 | 'invalid_list': _(u'Enter a list of values.'), |
596 | 598 | } |
597 | 599 | |
598 | | def clean(self, value): |
| 600 | def clean(self, value, initial=None): |
599 | 601 | """ |
600 | 602 | Validates that the input is a list or tuple. |
601 | 603 | """ |
… |
… |
class ComboField(Field):
|
626 | 628 | f.required = False |
627 | 629 | self.fields = fields |
628 | 630 | |
629 | | def clean(self, value): |
| 631 | def clean(self, value, initial=None): |
630 | 632 | """ |
631 | 633 | Validates the given value against all of self.fields, which is a |
632 | 634 | list of Field instances. |
633 | 635 | """ |
634 | | super(ComboField, self).clean(value) |
| 636 | super(ComboField, self).clean(value, initial) |
635 | 637 | for field in self.fields: |
636 | | value = field.clean(value) |
| 638 | value = field.clean(value, initial) |
637 | 639 | return value |
638 | 640 | |
639 | 641 | class MultiValueField(Field): |
… |
… |
class MultiValueField(Field):
|
666 | 668 | f.required = False |
667 | 669 | self.fields = fields |
668 | 670 | |
669 | | def clean(self, value): |
| 671 | def clean(self, value, initial=None): |
670 | 672 | """ |
671 | 673 | Validates every value in the given list. A value is validated against |
672 | 674 | the corresponding Field in self.fields. |
-
diff --git a/django/newforms/forms.py b/django/newforms/forms.py
index 556c00a..94232e3 100644
a
|
b
|
class BaseForm(StrAndUnicode):
|
181 | 181 | # Each widget type knows how to retrieve its own data, because some |
182 | 182 | # widgets split data over several HTML fields. |
183 | 183 | value = field.widget.value_from_datadict(self.data, self.files, self.add_prefix(name)) |
| 184 | initial = field.widget.value_from_initialdict(self.initial, name) |
184 | 185 | try: |
185 | | value = field.clean(value) |
| 186 | value = field.clean(value, initial) |
186 | 187 | self.cleaned_data[name] = value |
187 | 188 | if hasattr(self, 'clean_%s' % name): |
188 | 189 | value = getattr(self, 'clean_%s' % name)() |
-
diff --git a/django/newforms/models.py b/django/newforms/models.py
index fd0087a..4c130a3 100644
a
|
b
|
class ModelChoiceField(ChoiceField):
|
360 | 360 | |
361 | 361 | choices = property(_get_choices, _set_choices) |
362 | 362 | |
363 | | def clean(self, value): |
| 363 | def clean(self, value, initial=None): |
364 | 364 | Field.clean(self, value) |
365 | 365 | if value in EMPTY_VALUES: |
366 | 366 | return None |
… |
… |
class ModelMultipleChoiceField(ModelChoiceField):
|
386 | 386 | cache_choices, required, widget, label, initial, help_text, |
387 | 387 | *args, **kwargs) |
388 | 388 | |
389 | | def clean(self, value): |
| 389 | def clean(self, value, initial=None): |
390 | 390 | if self.required and not value: |
391 | 391 | raise ValidationError(self.error_messages['required']) |
392 | 392 | elif not self.required and not value: |
-
diff --git a/django/newforms/widgets.py b/django/newforms/widgets.py
index 5808348..fd585ed 100644
a
|
b
|
class Widget(object):
|
77 | 77 | return id_ |
78 | 78 | id_for_label = classmethod(id_for_label) |
79 | 79 | |
| 80 | def value_from_initialdict(self, initial, name): |
| 81 | """ |
| 82 | Given a dictionary of initial data return the value for this widget. |
| 83 | Returns None if it's not provided. |
| 84 | """ |
| 85 | if name in initial: |
| 86 | return initial[name] |
| 87 | return None |
| 88 | |
80 | 89 | class Input(Widget): |
81 | 90 | """ |
82 | 91 | Base class for all <input> widgets (except type='checkbox' and |
-
diff --git a/docs/newforms.txt b/docs/newforms.txt
index 19f42cb..257945e 100644
a
|
b
|
keep it simple and assume e-mail validation is contained in a function called
|
1594 | 1594 | from django import newforms as forms |
1595 | 1595 | |
1596 | 1596 | class MultiEmailField(forms.Field): |
1597 | | def clean(self, value): |
| 1597 | def clean(self, value, initial=None): |
1598 | 1598 | if not value: |
1599 | 1599 | raise forms.ValidationError('Enter at least one e-mail address.') |
1600 | 1600 | emails = value.split(',') |
-
diff --git a/tests/modeltests/model_forms/models.py b/tests/modeltests/model_forms/models.py
index 17c3b35..ff3f20e 100644
a
|
b
|
examples are probably a poor fit for the ModelForm syntax. In other words,
|
7 | 7 | most of these tests should be rewritten. |
8 | 8 | """ |
9 | 9 | |
| 10 | import os |
| 11 | import tempfile |
| 12 | |
10 | 13 | from django.db import models |
11 | 14 | |
12 | 15 | ARTICLE_STATUS = ( |
… |
… |
class PhoneNumber(models.Model):
|
55 | 58 | def __unicode__(self): |
56 | 59 | return self.phone |
57 | 60 | |
| 61 | class TextFile(models.Model): |
| 62 | description = models.CharField(max_length=20) |
| 63 | file = models.FileField(upload_to=tempfile.gettempdir()) |
| 64 | |
| 65 | def __unicode__(self): |
| 66 | return self.description |
| 67 | |
58 | 68 | __test__ = {'API_TESTS': """ |
59 | 69 | >>> from django import newforms as forms |
60 | 70 | >>> from django.newforms.models import ModelForm |
… |
… |
ValidationError: [u'Select a valid choice. 4 is not one of the available choices
|
701 | 711 | True |
702 | 712 | >>> f.cleaned_data |
703 | 713 | {'phone': u'312-555-1212', 'description': u'Assistance'} |
| 714 | |
| 715 | # FileField ################################################################### |
| 716 | |
| 717 | >>> class TextFileForm(ModelForm): |
| 718 | ... class Meta: |
| 719 | ... model = TextFile |
| 720 | |
| 721 | Test conditions when files is either not given or empty. |
| 722 | |
| 723 | >>> f = TextFileForm(data={'description': u'Assistance'}) |
| 724 | >>> f.is_valid() |
| 725 | False |
| 726 | >>> f = TextFileForm(data={'description': u'Assistance'}, files={}) |
| 727 | >>> f.is_valid() |
| 728 | False |
| 729 | |
| 730 | Upload a file and ensure it all works as expected. |
| 731 | |
| 732 | >>> f = TextFileForm(data={'description': u'Assistance'}, files={'file': {'filename': 'test1.txt', 'content': 'hello world'}}) |
| 733 | >>> f.is_valid() |
| 734 | True |
| 735 | >>> type(f.cleaned_data['file']) |
| 736 | <class 'django.newforms.fields.UploadedFile'> |
| 737 | >>> instance = f.save() |
| 738 | >>> instance.file |
| 739 | u'.../test1.txt' |
| 740 | |
| 741 | Edit an instance that already has the file defined in the model. This will not |
| 742 | save the file again, but leave it exactly as it is. |
| 743 | |
| 744 | >>> f = TextFileForm(data={'description': u'Assistance'}, instance=instance) |
| 745 | >>> f.is_valid() |
| 746 | True |
| 747 | >>> f.cleaned_data['file'] |
| 748 | u'.../test1.txt' |
| 749 | >>> instance = f.save() |
| 750 | >>> instance.file |
| 751 | u'.../test1.txt' |
| 752 | |
| 753 | Delete the current file since this is not done by Django. |
| 754 | |
| 755 | >>> os.unlink(instance.get_file_filename()) |
| 756 | |
| 757 | Override the file by uploading a new one. |
| 758 | |
| 759 | >>> f = TextFileForm(data={'description': u'Assistance'}, files={'file': {'filename': 'test2.txt', 'content': 'hello world'}}, instance=instance) |
| 760 | >>> f.is_valid() |
| 761 | True |
| 762 | >>> instance = f.save() |
| 763 | >>> instance.file |
| 764 | u'.../test2.txt' |
| 765 | |
| 766 | >>> instance.delete() |
| 767 | |
| 768 | Test the non-required FileField |
| 769 | |
| 770 | >>> f = TextFileForm(data={'description': u'Assistance'}) |
| 771 | >>> f.fields['file'].required = False |
| 772 | >>> f.is_valid() |
| 773 | True |
| 774 | >>> instance = f.save() |
| 775 | >>> instance.file |
| 776 | '' |
| 777 | |
| 778 | >>> f = TextFileForm(data={'description': u'Assistance'}, files={'file': {'filename': 'test3.txt', 'content': 'hello world'}}, instance=instance) |
| 779 | >>> f.is_valid() |
| 780 | True |
| 781 | >>> instance = f.save() |
| 782 | >>> instance.file |
| 783 | u'.../test3.txt' |
| 784 | >>> instance.delete() |
704 | 785 | """} |
-
diff --git a/tests/regressiontests/forms/fields.py b/tests/regressiontests/forms/fields.py
index cff5db6..9216210 100644
a
|
b
|
Traceback (most recent call last):
|
749 | 749 | ... |
750 | 750 | ValidationError: [u'This field is required.'] |
751 | 751 | |
| 752 | >>> f.clean('', '') |
| 753 | Traceback (most recent call last): |
| 754 | ... |
| 755 | ValidationError: [u'This field is required.'] |
| 756 | |
| 757 | >>> f.clean('', 'files/test1.pdf') |
| 758 | 'files/test1.pdf' |
| 759 | |
752 | 760 | >>> f.clean(None) |
753 | 761 | Traceback (most recent call last): |
754 | 762 | ... |
755 | 763 | ValidationError: [u'This field is required.'] |
756 | 764 | |
| 765 | >>> f.clean(None, '') |
| 766 | Traceback (most recent call last): |
| 767 | ... |
| 768 | ValidationError: [u'This field is required.'] |
| 769 | |
| 770 | >>> f.clean(None, 'files/test2.pdf') |
| 771 | 'files/test2.pdf' |
| 772 | |
757 | 773 | >>> f.clean({}) |
758 | 774 | Traceback (most recent call last): |
759 | 775 | ... |
760 | 776 | ValidationError: [u'No file was submitted.'] |
761 | 777 | |
| 778 | >>> f.clean({}, '') |
| 779 | Traceback (most recent call last): |
| 780 | ... |
| 781 | ValidationError: [u'No file was submitted.'] |
| 782 | |
| 783 | >>> f.clean({}, 'files/test3.pdf') |
| 784 | 'files/test3.pdf' |
| 785 | |
762 | 786 | >>> f.clean('some content that is not a file') |
763 | 787 | Traceback (most recent call last): |
764 | 788 | ... |
765 | 789 | ValidationError: [u'No file was submitted. Check the encoding type on the form.'] |
766 | 790 | |
767 | | >>> f.clean({'filename': 'name', 'content':None}) |
| 791 | >>> f.clean({'filename': 'name', 'content': None}) |
768 | 792 | Traceback (most recent call last): |
769 | 793 | ... |
770 | 794 | ValidationError: [u'The submitted file is empty.'] |
771 | 795 | |
772 | | >>> f.clean({'filename': 'name', 'content':''}) |
| 796 | >>> f.clean({'filename': 'name', 'content': ''}) |
773 | 797 | Traceback (most recent call last): |
774 | 798 | ... |
775 | 799 | ValidationError: [u'The submitted file is empty.'] |
776 | 800 | |
777 | | >>> type(f.clean({'filename': 'name', 'content':'Some File Content'})) |
| 801 | >>> type(f.clean({'filename': 'name', 'content': 'Some File Content'})) |
| 802 | <class 'django.newforms.fields.UploadedFile'> |
| 803 | |
| 804 | >>> type(f.clean({'filename': 'name', 'content': 'Some File Content'}, 'files/test4.pdf')) |
778 | 805 | <class 'django.newforms.fields.UploadedFile'> |
779 | 806 | |
780 | 807 | # URLField ################################################################## |