[Django] #30243: Reduce structural dependency in contrib.admin 'has_file_field' checks

3 views
Skip to first unread message

Django

unread,
Mar 8, 2019, 1:00:01 PM3/8/19
to django-...@googlegroups.com
#30243: Reduce structural dependency in contrib.admin 'has_file_field' checks
------------------------------------------------+--------------------------
Reporter: btknu | Owner: btknu
Type: Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
------------------------------------------------+--------------------------
This ticket is about a very small cleanup. It's possible that a Trac
ticket isn't necessary for this, I decided to make one to stay on the safe
side.

The PR https://github.com/django/django/pull/9298 for ticket
https://code.djangoproject.com/ticket/28585 adds code:

{{{
'has_file_field': context['adminform'].form.is_multipart() or
any(
admin_formset.formset.form().is_multipart()
for admin_formset in context['inline_admin_formsets']
),
}}}

This snippet invokes `is_multipart()` on formset's `form()` object.
But the formset (specifically: `BaseFormSet`) already provides an
`is_multipart()` method.

It feels cleaner to rely on a single place to calculate `is_multipart` for
a formset.
This way if `is_multipart` logic gets more complex, we only need to update
it in one place and there's less risk of bugs.

I suggest replacing:

{{{
admin_formset.formset.form().is_multipart()
}}}

with:

{{{
admin_formset.formset.is_multipart()
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30243>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 8, 2019, 1:34:50 PM3/8/19
to django-...@googlegroups.com
#30243: Reduce structural dependency in contrib.admin 'has_file_field' checks
-------------------------------------+-------------------------------------
Reporter: btknu | Owner: btknu
Type: | Status: assigned
Cleanup/optimization |
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* stage: Unreviewed => Ready for checkin


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

Django

unread,
Mar 8, 2019, 6:04:55 PM3/8/19
to django-...@googlegroups.com
#30243: Reduce structural dependency in contrib.admin 'has_file_field' checks
-------------------------------------+-------------------------------------
Reporter: btknu | Owner: btknu
Type: | Status: closed
Cleanup/optimization |
Component: contrib.admin | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

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


Comment:

In [changeset:"7c3a8b9db2ccfbb247732ce6726ab8dc11eff34d" 7c3a8b9]:
{{{
#!CommitTicketReference repository=""
revision="7c3a8b9db2ccfbb247732ce6726ab8dc11eff34d"
Fixed #30243 -- Simplified ModelAdmin.render_change_form()'s
has_file_field.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30243#comment:2>

Reply all
Reply to author
Forward
0 new messages