Code

Ticket #3337: newforms-fields-super.diff

File newforms-fields-super.diff, 7.0 KB (added by Dirk Datzert <dummy@…>, 7 years ago)

call super() instead Field-class-methods

Line 
1Index: django/newforms/fields.py
2===================================================================
3--- django/newforms/fields.py   (Revision 4365)
4+++ django/newforms/fields.py   (Arbeitskopie)
5@@ -86,11 +86,11 @@
6 class CharField(Field):
7     def __init__(self, max_length=None, min_length=None, required=True, widget=None, label=None, initial=None):
8         self.max_length, self.min_length = max_length, min_length
9-        Field.__init__(self, required, widget, label, initial)
10+        super(CharField, self).__init__(self, required, widget, label, initial)
11 
12     def clean(self, value):
13         "Validates max_length and min_length. Returns a Unicode object."
14-        Field.clean(self, value)
15+        super(CharField, self).clean(self, value)
16         if value in EMPTY_VALUES:
17             value = u''
18             if not self.required:
19@@ -109,7 +109,7 @@
20 class IntegerField(Field):
21     def __init__(self, max_value=None, min_value=None, required=True, widget=None, label=None, initial=None):
22         self.max_value, self.min_value = max_value, min_value
23-        Field.__init__(self, required, widget, label, initial)
24+        super(IntegerField, self).__init__(self, required, widget, label, initial)
25 
26     def clean(self, value):
27         """
28@@ -139,7 +139,7 @@
29 
30 class DateField(Field):
31     def __init__(self, input_formats=None, required=True, widget=None, label=None, initial=None):
32-        Field.__init__(self, required, widget, label, initial)
33+        super(DateField, self).__init__(self, required, widget, label, initial)
34         self.input_formats = input_formats or DEFAULT_DATE_INPUT_FORMATS
35 
36     def clean(self, value):
37@@ -147,7 +147,7 @@
38         Validates that the input can be converted to a date. Returns a Python
39         datetime.date object.
40         """
41-        Field.clean(self, value)
42+        super(DateField, self).clean(self, value)
43         if value in EMPTY_VALUES:
44             return None
45         if isinstance(value, datetime.datetime):
46@@ -168,7 +168,7 @@
47 
48 class TimeField(Field):
49     def __init__(self, input_formats=None, required=True, widget=None, label=None, initial=None):
50-        Field.__init__(self, required, widget, label, initial)
51+        super(TimeField, self).__init__(self, required, widget, label, initial)
52         self.input_formats = input_formats or DEFAULT_TIME_INPUT_FORMATS
53 
54     def clean(self, value):
55@@ -176,7 +176,7 @@
56         Validates that the input can be converted to a time. Returns a Python
57         datetime.time object.
58         """
59-        Field.clean(self, value)
60+        super(TimeField, self).clean(self, value)
61         if value in EMPTY_VALUES:
62             return None
63         if isinstance(value, datetime.time):
64@@ -202,7 +202,7 @@
65 
66 class DateTimeField(Field):
67     def __init__(self, input_formats=None, required=True, widget=None, label=None, initial=None):
68-        Field.__init__(self, required, widget, label, initial)
69+        super(DateTimeField, self).__init__(self, required, widget, label, initial)
70         self.input_formats = input_formats or DEFAULT_DATETIME_INPUT_FORMATS
71 
72     def clean(self, value):
73@@ -210,7 +210,7 @@
74         Validates that the input can be converted to a datetime. Returns a
75         Python datetime.datetime object.
76         """
77-        Field.clean(self, value)
78+        super(DateTimeField, self).clean(self, value)
79         if value in EMPTY_VALUES:
80             return None
81         if isinstance(value, datetime.datetime):
82@@ -232,7 +232,7 @@
83         error_message is an optional error message to use, if
84         'Enter a valid value' is too generic for you.
85         """
86-        Field.__init__(self, required, widget, label, initial)
87+        super(RegexField, self).__init__(self, required, widget, label, initial)
88         if isinstance(regex, basestring):
89             regex = re.compile(regex)
90         self.regex = regex
91@@ -244,7 +244,7 @@
92         Validates that the input matches the regular expression. Returns a
93         Unicode object.
94         """
95-        Field.clean(self, value)
96+        super(RegexField, self).clean(self, value)
97         if value in EMPTY_VALUES: value = u''
98         value = smart_unicode(value)
99         if not self.required and value == u'':
100@@ -282,12 +282,12 @@
101 class URLField(RegexField):
102     def __init__(self, max_length=None, min_length=None, required=True, verify_exists=False, widget=None, label=None,
103             initial=None, validator_user_agent=URL_VALIDATOR_USER_AGENT):
104-        RegexField.__init__(self, url_re, max_length, min_length, gettext(u'Enter a valid URL.'), required, widget, label, initial)
105+        super(URLField, self).__init__(self, url_re, max_length, min_length, gettext(u'Enter a valid URL.'), required, widget, label, initial)
106         self.verify_exists = verify_exists
107         self.user_agent = validator_user_agent
108 
109     def clean(self, value):
110-        value = RegexField.clean(self, value)
111+        value = super(URLField, self).clean(self, value)
112         if not self.required and value == u'':
113             return value
114         if self.verify_exists:
115@@ -314,21 +314,21 @@
116 
117     def clean(self, value):
118         "Returns a Python boolean object."
119-        Field.clean(self, value)
120+        super(BooleanField, self).clean(self, value)
121         return bool(value)
122 
123 class ChoiceField(Field):
124     def __init__(self, choices=(), required=True, widget=Select, label=None, initial=None):
125         if isinstance(widget, type):
126             widget = widget(choices=choices)
127-        Field.__init__(self, required, widget, label, initial)
128+        super(ChoiceField, self).__init__(self, required, widget, label, initial)
129         self.choices = choices
130 
131     def clean(self, value):
132         """
133         Validates that the input is in self.choices.
134         """
135-        value = Field.clean(self, value)
136+        value = super(ChoiceField, self).clean(self, value)
137         if value in EMPTY_VALUES: value = u''
138         value = smart_unicode(value)
139         if not self.required and value == u'':
140@@ -342,7 +342,7 @@
141     hidden_widget = MultipleHiddenInput
142 
143     def __init__(self, choices=(), required=True, widget=SelectMultiple, label=None, initial=None):
144-        ChoiceField.__init__(self, choices, required, widget, label, initial)
145+        super(MultipleChoiceField, self).__init__(self, choices, required, widget, label, initial)
146 
147     def clean(self, value):
148         """
149@@ -367,7 +367,7 @@
150 
151 class ComboField(Field):
152     def __init__(self, fields=(), required=True, widget=None, label=None, initial=None):
153-        Field.__init__(self, required, widget, label, initial)
154+        super(ComboField, self).__init__(self, required, widget, label, initial)
155         # Set 'required' to False on the individual fields, because the
156         # required validation will be handled by ComboField, not by those
157         # individual fields.
158@@ -380,7 +380,7 @@
159         Validates the given value against all of self.fields, which is a
160         list of Field instances.
161         """
162-        Field.clean(self, value)
163+        super(ComboField, self).clean(self, value)
164         for field in self.fields:
165             value = field.clean(value)
166         return value