Opened 16 years ago
Last modified 8 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: | 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 , 16 years ago
comment:3 by , 16 years ago
milestone: | → 1.0 |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:4 by , 16 years ago
milestone: | 1.0 → post-1.0 |
---|---|
Resolution: | → invalid |
Status: | new → closed |
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 , 16 years ago
Resolution: | invalid |
---|---|
Status: | closed → reopened |
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 , 16 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 , 16 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:10 by , 16 years ago
Status: | reopened → assigned |
---|
comment:11 by , 15 years ago
I believe ticket:11801 addresses this issue, and that ticket includes a patch and tests.
comment:14 by , 13 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 , 13 years ago
Resolution: | duplicate |
---|---|
Status: | closed → reopened |
Type: | Uncategorized → New 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.
Thanks yakiimo for pointing this out.
comment:16 by , 12 years ago
Status: | reopened → new |
---|
comment:17 by , 10 years ago
#21592 is a duplicate which has an incomplete patch and some discussion.
The error is
raise AttributeError("'%s' object has no attribute 'ordered_forms'" % self.class.name)