Ticket #3337: newforms-fields-super.diff

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

call super() instead Field-class-methods

  • django/newforms/fields.py

     
    8686class CharField(Field):
    8787    def __init__(self, max_length=None, min_length=None, required=True, widget=None, label=None, initial=None):
    8888        self.max_length, self.min_length = max_length, min_length
    89         Field.__init__(self, required, widget, label, initial)
     89        super(CharField, self).__init__(self, required, widget, label, initial)
    9090
    9191    def clean(self, value):
    9292        "Validates max_length and min_length. Returns a Unicode object."
    93         Field.clean(self, value)
     93        super(CharField, self).clean(self, value)
    9494        if value in EMPTY_VALUES:
    9595            value = u''
    9696            if not self.required:
     
    109109class IntegerField(Field):
    110110    def __init__(self, max_value=None, min_value=None, required=True, widget=None, label=None, initial=None):
    111111        self.max_value, self.min_value = max_value, min_value
    112         Field.__init__(self, required, widget, label, initial)
     112        super(IntegerField, self).__init__(self, required, widget, label, initial)
    113113
    114114    def clean(self, value):
    115115        """
     
    139139
    140140class DateField(Field):
    141141    def __init__(self, input_formats=None, required=True, widget=None, label=None, initial=None):
    142         Field.__init__(self, required, widget, label, initial)
     142        super(DateField, self).__init__(self, required, widget, label, initial)
    143143        self.input_formats = input_formats or DEFAULT_DATE_INPUT_FORMATS
    144144
    145145    def clean(self, value):
     
    147147        Validates that the input can be converted to a date. Returns a Python
    148148        datetime.date object.
    149149        """
    150         Field.clean(self, value)
     150        super(DateField, self).clean(self, value)
    151151        if value in EMPTY_VALUES:
    152152            return None
    153153        if isinstance(value, datetime.datetime):
     
    168168
    169169class TimeField(Field):
    170170    def __init__(self, input_formats=None, required=True, widget=None, label=None, initial=None):
    171         Field.__init__(self, required, widget, label, initial)
     171        super(TimeField, self).__init__(self, required, widget, label, initial)
    172172        self.input_formats = input_formats or DEFAULT_TIME_INPUT_FORMATS
    173173
    174174    def clean(self, value):
     
    176176        Validates that the input can be converted to a time. Returns a Python
    177177        datetime.time object.
    178178        """
    179         Field.clean(self, value)
     179        super(TimeField, self).clean(self, value)
    180180        if value in EMPTY_VALUES:
    181181            return None
    182182        if isinstance(value, datetime.time):
     
    202202
    203203class DateTimeField(Field):
    204204    def __init__(self, input_formats=None, required=True, widget=None, label=None, initial=None):
    205         Field.__init__(self, required, widget, label, initial)
     205        super(DateTimeField, self).__init__(self, required, widget, label, initial)
    206206        self.input_formats = input_formats or DEFAULT_DATETIME_INPUT_FORMATS
    207207
    208208    def clean(self, value):
     
    210210        Validates that the input can be converted to a datetime. Returns a
    211211        Python datetime.datetime object.
    212212        """
    213         Field.clean(self, value)
     213        super(DateTimeField, self).clean(self, value)
    214214        if value in EMPTY_VALUES:
    215215            return None
    216216        if isinstance(value, datetime.datetime):
     
    232232        error_message is an optional error message to use, if
    233233        'Enter a valid value' is too generic for you.
    234234        """
    235         Field.__init__(self, required, widget, label, initial)
     235        super(RegexField, self).__init__(self, required, widget, label, initial)
    236236        if isinstance(regex, basestring):
    237237            regex = re.compile(regex)
    238238        self.regex = regex
     
    244244        Validates that the input matches the regular expression. Returns a
    245245        Unicode object.
    246246        """
    247         Field.clean(self, value)
     247        super(RegexField, self).clean(self, value)
    248248        if value in EMPTY_VALUES: value = u''
    249249        value = smart_unicode(value)
    250250        if not self.required and value == u'':
     
    282282class URLField(RegexField):
    283283    def __init__(self, max_length=None, min_length=None, required=True, verify_exists=False, widget=None, label=None,
    284284            initial=None, validator_user_agent=URL_VALIDATOR_USER_AGENT):
    285         RegexField.__init__(self, url_re, max_length, min_length, gettext(u'Enter a valid URL.'), required, widget, label, initial)
     285        super(URLField, self).__init__(self, url_re, max_length, min_length, gettext(u'Enter a valid URL.'), required, widget, label, initial)
    286286        self.verify_exists = verify_exists
    287287        self.user_agent = validator_user_agent
    288288
    289289    def clean(self, value):
    290         value = RegexField.clean(self, value)
     290        value = super(URLField, self).clean(self, value)
    291291        if not self.required and value == u'':
    292292            return value
    293293        if self.verify_exists:
     
    314314
    315315    def clean(self, value):
    316316        "Returns a Python boolean object."
    317         Field.clean(self, value)
     317        super(BooleanField, self).clean(self, value)
    318318        return bool(value)
    319319
    320320class ChoiceField(Field):
    321321    def __init__(self, choices=(), required=True, widget=Select, label=None, initial=None):
    322322        if isinstance(widget, type):
    323323            widget = widget(choices=choices)
    324         Field.__init__(self, required, widget, label, initial)
     324        super(ChoiceField, self).__init__(self, required, widget, label, initial)
    325325        self.choices = choices
    326326
    327327    def clean(self, value):
    328328        """
    329329        Validates that the input is in self.choices.
    330330        """
    331         value = Field.clean(self, value)
     331        value = super(ChoiceField, self).clean(self, value)
    332332        if value in EMPTY_VALUES: value = u''
    333333        value = smart_unicode(value)
    334334        if not self.required and value == u'':
     
    342342    hidden_widget = MultipleHiddenInput
    343343
    344344    def __init__(self, choices=(), required=True, widget=SelectMultiple, label=None, initial=None):
    345         ChoiceField.__init__(self, choices, required, widget, label, initial)
     345        super(MultipleChoiceField, self).__init__(self, choices, required, widget, label, initial)
    346346
    347347    def clean(self, value):
    348348        """
     
    367367
    368368class ComboField(Field):
    369369    def __init__(self, fields=(), required=True, widget=None, label=None, initial=None):
    370         Field.__init__(self, required, widget, label, initial)
     370        super(ComboField, self).__init__(self, required, widget, label, initial)
    371371        # Set 'required' to False on the individual fields, because the
    372372        # required validation will be handled by ComboField, not by those
    373373        # individual fields.
     
    380380        Validates the given value against all of self.fields, which is a
    381381        list of Field instances.
    382382        """
    383         Field.clean(self, value)
     383        super(ComboField, self).clean(self, value)
    384384        for field in self.fields:
    385385            value = field.clean(value)
    386386        return value
Back to Top