<s> from collections import OrderedDict <EOL> from functools import partial <EOL> from django . forms . fields import Field <EOL> from django . utils import six <EOL> def patch_document ( function , instance ) : <EOL> setattr ( instance , function . __name__ , partial ( function , instance ) ) <EOL> def get_declared_fields ( bases , attrs , with_base_fields = True ) : <EOL> """<STR_LIT>""" <EOL> fields = [ <EOL> ( field_name , attrs . pop ( field_name ) ) <EOL> for field_name , obj in list ( six . iteritems ( attrs ) ) if isinstance ( obj , Field ) <EOL> ] <EOL> fields . sort ( key = lambda x : x [ <NUM_LIT:1> ] . creation_counter ) <EOL> if with_base_fields : <EOL> for base in bases [ : : - <NUM_LIT:1> ] : <EOL> if hasattr ( base , '<STR_LIT>' ) : <EOL> fields = list ( six . iteritems ( base . base_fields ) ) + fields <EOL> else : <EOL> for base in bases [ : : - <NUM_LIT:1> ] : <EOL> if hasattr ( base , '<STR_LIT>' ) : <EOL> fields = list ( six . iteritems ( base . declared_fields ) ) + fields <EOL> return OrderedDict ( fields ) </s>
