﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35964	Remove unnecessary calls and fix dictionary key order in Formset documentation examples can_order and can_delete.	Antoliny	Antoliny	"In the example from can_order, calls to is_valid() are unnecessary. because ordered_forms, a property that is accessed later, calls the is_valid method.
{{{
    @property
    def ordered_forms(self):
        """"""
        Return a list of form in the order specified by the incoming data.
        Raise 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__
            )
        ...
}}}
And I think the order of dictionary keys in the output of the examples for can_order and can_delete should be fixed.
As far as I know that the order of the keys is affected by the fields defined in ArticleForm.
Therefore, the fields of the ArticleForm used in the Formset documentation examples should follow the key order -> title, pub_date. ...
However, the output in the examples for can_order and can_delete does not seem to follow that order.

**can_order**
{{{
    >>> formset = ArticleFormSet(
    ...     data,
    ...     initial=[
    ...         {""title"": ""Article #1"", ""pub_date"": datetime.date(2008, 5, 10)},
    ...         {""title"": ""Article #2"", ""pub_date"": datetime.date(2008, 5, 11)},
    ...     ],
    ... )
    >>> formset.is_valid()
    True
    >>> for form in formset.ordered_forms:
    ...     print(form.cleaned_data)
    ...
    {'pub_date': datetime.date(2008, 5, 1), 'ORDER': 0, 'title': 'Article #3'}
    {'pub_date': datetime.date(2008, 5, 11), 'ORDER': 1, 'title': 'Article #2'}
    {'pub_date': datetime.date(2008, 5, 10), 'ORDER': 2, 'title': 'Article #1'}
}}}

**can_delete**
{{{
    >>> formset = ArticleFormSet(
    ...     data,
    ...     initial=[
    ...         {""title"": ""Article #1"", ""pub_date"": datetime.date(2008, 5, 10)},
    ...         {""title"": ""Article #2"", ""pub_date"": datetime.date(2008, 5, 11)},
    ...     ],
    ... )
    >>> [form.cleaned_data for form in formset.deleted_forms]
    [{'DELETE': True, 'pub_date': datetime.date(2008, 5, 10), 'title': 'Article #1'}]
}}}"	Cleanup/optimization	closed	Documentation	5.1	Normal	fixed	Formset		Ready for checkin	1	0	0	0	0	0
