Ticket #5986: django-fields-order.patch
File django-fields-order.patch, 1.4 KB (added by , 17 years ago) |
---|
-
newforms/forms.py
8 8 from django.utils.html import escape 9 9 from django.utils.encoding import StrAndUnicode, smart_unicode, force_unicode 10 10 from django.utils.safestring import mark_safe 11 from django.core.management.base import CommandError 11 12 12 13 from fields import Field 13 14 from widgets import TextInput, Textarea … … 38 39 if hasattr(base, 'base_fields'): 39 40 fields = base.base_fields.items() + fields 40 41 42 # Sort by Meta.fields_order if present. 43 # Raises CommandError if any of the fields is missing. 44 if attrs.has_key('Meta') and hasattr(attrs['Meta'], 'fields_order'): 45 def _indexcmp(x, y): 46 errstr = "%s not present in %s.Meta.fields_order" 47 try: 48 xindex = attrs['Meta'].fields_order.index(x[0]) 49 except ValueError: 50 raise CommandError, errstr % (x[0], name) 51 try: 52 yindex = attrs['Meta'].fields_order.index(y[0]) 53 except ValueError: 54 raise CommandError, errstr % (y[0], name) 55 return cmp(xindex, yindex) 56 fields.sort(_indexcmp) 57 41 58 attrs['base_fields'] = SortedDict(fields) 42 59 return type.__new__(cls, name, bases, attrs) 43 60