'Returns a list of form in the order specified by the incoming data.
Raises an AttributeError if ordering is not allowed.'

def _get_ordered_forms(self):

    if ((not self.is_valid()) or (not self.can_order)):
        raise AttributeError(("'%s'    object    has    no    attribute    'ordered_forms'" % self.__class__.__name__))
    if (not hasattr(self, '_ordering')):
        self._ordering = []
        for i in range(0, self.total_form_count()):
            form = self.forms[i]
            if ((i >= self.initial_form_count()) and (not form.has_changed())):
                continue
            if (self.can_delete and self._should_delete_form(form)):
                continue
            self._ordering.append((i, form.cleaned_data[ORDERING_FIELD_NAME]))
        def compare_ordering_key(k):
            if (k[1] is None):
                return (1, 0)
            return (0, k[1])
        self._ordering.sort(key=compare_ordering_key)
    return [self.forms[i[0]] for i in self._ordering]
