code: def get_sorted_fields(self):
          inf = float("inf")
          order = self.get_field_order()
          def field_cmp(field1, field2):
              _n1 = field1.getName()
              _n2 = field2.getName()
              _i1 = _n1 in order and order.index(_n1) + 1 or inf
              _i2 = _n2 in order and order.index(_n2) + 1 or inf
              return cmp(_i1, _i2)
          return sorted(self.get_fields(), cmp=field_cmp)