Ticket #3632: forms.diff

File forms.diff, 1.7 KB (added by ludo@…, 18 years ago)

tentative patch to newforms/forms.py

  • newforms/forms.py

     
    3636    'base_fields', taking into account parent class 'base_fields' as well.
    3737    """
    3838    def __new__(cls, name, bases, attrs):
    39         fields = [(field_name, attrs.pop(field_name)) for field_name, obj in attrs.items() if isinstance(obj, Field)]
    40         fields.sort(lambda x, y: cmp(x[1].creation_counter, y[1].creation_counter))
     39        if 'base_fields' in attrs:
     40            fields = attrs['base_fields']
     41        else:
     42            fields = [(field_name, attrs.pop(field_name)) for field_name, obj in attrs.items() if isinstance(obj, Field)]
     43            fields.sort(lambda x, y: cmp(x[1].creation_counter, y[1].creation_counter))
    4144
    42         # If this class is subclassing another Form, add that Form's fields.
    43         # Note that we loop over the bases in *reverse*. This is necessary in
    44         # order to preserve the correct order of fields.
    45         for base in bases[::-1]:
    46             if hasattr(base, 'base_fields'):
    47                 fields = base.base_fields.items() + fields
     45            # If this class is subclassing another Form, add that Form's fields.
     46            # Note that we loop over the bases in *reverse*. This is necessary in
     47            # order to preserve the correct order of fields.
     48            for base in bases[::-1]:
     49                if hasattr(base, 'base_fields'):
     50                    fields = base.base_fields.items() + fields
    4851
    49         attrs['base_fields'] = SortedDictFromList(fields)
     52            attrs['base_fields'] = SortedDictFromList(fields)
    5053        return type.__new__(cls, name, bases, attrs)
    5154
    5255class BaseForm(StrAndUnicode):
Back to Top