Opened 16 years ago

Last modified 7 years ago

#8165 new New feature

When using can_order=True on formset, ordered_forms is not avaible when formset.is_valid() is false

Reported by: James Chua <james_027@…> Owned by: nobody
Component: Forms Version: dev
Severity: Normal Keywords: formsets
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

IMO ordered_forms attribute needs to be available even then the formset.is_valid() result to false in order to return the formset in order for re-inputting purpose

Change History (14)

comment:1 by James Chua <james_027@…>, 16 years ago

The error is

raise AttributeError("'%s' object has no attribute 'ordered_forms'" % self.class.name)

comment:3 by Jacob, 16 years ago

milestone: 1.0
Triage Stage: UnreviewedAccepted

comment:4 by Brian Rosner, 16 years ago

milestone: 1.0post-1.0
Resolution: invalid
Status: newclosed

I talked with Joseph about this. He says that the behavior of ordered_forms is completely intentional to mirror how cleaned_data works. I can't seem to remember exactly what we discussed here James. I apologize. I am going to close for now, but you are welcome to reopen with a specific use-case. At any rate it is a post-1.0 item due to feature freeze and this isn't a bug.

comment:5 by james_027, 16 years ago

Resolution: invalid
Status: closedreopened

An specific use-case could be if a page with a number of same forms were submitted and not every forms are valid and needed to return for re-inputting purpose and when it needed to be return with an order needed, ordered_forms should be available in spite of is_valid() is false.

comment:6 by Patrick Kranzlmueller, 15 years ago

I absolutely agree with james_027. why should ordered_forms only be available when is_valid() is true. it may be intentional to mirror cleaned_data, but that doesn´t mean it´s a good idea.

comment:7 by Patrick Kranzlmueller, 15 years ago

another usecase: ordering edit-inlines should be possible when order_with_respect_to is defined (or when you use a custom formset with can_order=true). in case of an error, the order of the items (edited inline) is obviously wrong.
solving this whole issue would allow for re-ordering edit-inlines.

comment:8 by (none), 15 years ago

milestone: post-1.0

Milestone post-1.0 deleted

comment:10 by Zain Memon, 15 years ago

Status: reopenedassigned

comment:11 by dantallis, 14 years ago

I believe ticket:11801 addresses this issue, and that ticket includes a patch and tests.

comment:12 by Jacob, 14 years ago

Resolution: duplicate
Status: assignedclosed

Dup of #11801.

comment:14 by yakiimo, 12 years ago

Easy pickings: unset
Severity: Normal
Type: Uncategorized
UI/UX: unset

It seems to me that this is not actually resolved in the ticket this is marked as a duplicate of. Could someone tell me why I'm wrong? I'm new with django so I don't want to reopen it unnecessarily.

The other ticket seems to be on a related issue, but in 1.3 ordered_forms are still not available before the form passes is_valid().

In formsets.py, line 184, within BaseFormSet:

    def _get_ordered_forms(self):
        """
        Returns a list of form in the order specified by the incoming data.
        Raises an AttributeError if ordering is not allowed.
        """
        if not self.is_valid() or not self.can_order:
            raise AttributeError("'%s' object has no attribute 'ordered_forms'" % self.__class__.__name__)
        ...

For what it's worth, my use case is that I'd like to have parallel ordering between two formsets through a foreign key. The only two ways I found were through overriding iter or this way. I thought this way seemed more natural since it doesn't require any overrides.

comment:15 by Carl Meyer, 12 years ago

Resolution: duplicate
Status: closedreopened
Type: UncategorizedNew feature

Yes, this ticket was incorrectly closed as a duplicate. #11801 addressed a much more edge case: when there is a deleted form that would otherwise have been invalid, but since it is deleted the overall formset is still valid. This ticket is requesting that the ordered_forms attribute should be available unconditionally, even when the formset is actually not valid.

Version 0, edited 12 years ago by Carl Meyer (next)

comment:16 by Aymeric Augustin, 11 years ago

Status: reopenednew

comment:17 by Tim Graham, 9 years ago

#21592 is a duplicate which has an incomplete patch and some discussion.

Note: See TracTickets for help on using tickets.
Back to Top