[Django] #35964: Remove unnecessary calls and fix dictionary key order in Formset documentation examples can_order and can_delete.

7 views
Skip to first unread message

Django

unread,
Dec 2, 2024, 2:24:46 AM12/2/24
to django-...@googlegroups.com
#35964: Remove unnecessary calls and fix dictionary key order in Formset
documentation examples can_order and can_delete.
--------------------------+------------------------------------------------
Reporter: Antoliny | Type: Cleanup/optimization
Status: new | Component: Documentation
Version: 5.1 | Severity: Normal
Keywords: Formset | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------+------------------------------------------------
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'}]
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35964>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 2, 2024, 2:25:02 AM12/2/24
to django-...@googlegroups.com
#35964: Remove unnecessary calls and fix dictionary key order in Formset
documentation examples can_order and can_delete.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: | Status: assigned
Cleanup/optimization |
Component: Documentation | Version: 5.1
Severity: Normal | Resolution:
Keywords: Formset | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Antoliny):

* owner: (none) => Antoliny
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/35964#comment:1>

Django

unread,
Dec 2, 2024, 2:38:06 AM12/2/24
to django-...@googlegroups.com
#35964: Remove unnecessary calls and fix dictionary key order in Formset
documentation examples can_order and can_delete.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: | Status: assigned
Cleanup/optimization |
Component: Documentation | Version: 5.1
Severity: Normal | Resolution:
Keywords: Formset | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Antoliny):

[https://github.com/django/django/pull/18875 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/35964#comment:2>

Django

unread,
Dec 2, 2024, 2:38:20 AM12/2/24
to django-...@googlegroups.com
#35964: Remove unnecessary calls and fix dictionary key order in Formset
documentation examples can_order and can_delete.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: | Status: assigned
Cleanup/optimization |
Component: Documentation | Version: 5.1
Severity: Normal | Resolution:
Keywords: Formset | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Antoliny):

* has_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/35964#comment:3>

Django

unread,
Dec 2, 2024, 4:26:16 AM12/2/24
to django-...@googlegroups.com
#35964: Remove unnecessary calls and fix dictionary key order in Formset
documentation examples can_order and can_delete.
--------------------------------------+------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: Cleanup/optimization | Status: assigned
Component: Documentation | Version: 5.1
Severity: Normal | Resolution:
Keywords: Formset | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Sarah Boyce):

* stage: Unreviewed => Accepted

--
Ticket URL: <https://code.djangoproject.com/ticket/35964#comment:4>

Django

unread,
Dec 2, 2024, 4:30:42 AM12/2/24
to django-...@googlegroups.com
#35964: Remove unnecessary calls and fix dictionary key order in Formset
documentation examples can_order and can_delete.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: | Status: assigned
Cleanup/optimization |
Component: Documentation | Version: 5.1
Severity: Normal | Resolution:
Keywords: Formset | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/35964#comment:5>

Django

unread,
Dec 2, 2024, 6:56:55 AM12/2/24
to django-...@googlegroups.com
#35964: Remove unnecessary calls and fix dictionary key order in Formset
documentation examples can_order and can_delete.
-------------------------------------+-------------------------------------
Reporter: Antoliny | Owner: Antoliny
Type: | Status: closed
Cleanup/optimization |
Component: Documentation | Version: 5.1
Severity: Normal | Resolution: fixed
Keywords: Formset | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce <42296566+sarahboyce@…>):

* resolution: => fixed
* status: assigned => closed

Comment:

In [changeset:"32b9e00b0c74b3af77c25215e2e2d1254b995355" 32b9e00]:
{{{#!CommitTicketReference repository=""
revision="32b9e00b0c74b3af77c25215e2e2d1254b995355"
Fixed #35964 -- Cleaned up can_order and can_delete formset examples.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35964#comment:6>
Reply all
Reply to author
Forward
0 new messages