[Django] #33226: Add css class hooks to BaseForm

2 views
Skip to first unread message

Django

unread,
Oct 24, 2021, 5:26:57 AM10/24/21
to django-...@googlegroups.com
#33226: Add css class hooks to BaseForm
-----------------------------------------+------------------------
Reporter: David Smith | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
`Form` has a couple of hooks to add classes to a form. See
[https://docs.djangoproject.com/en/3.2/ref/forms/api/#styling-required-or-
erroneous-form-rows docs].

However, the
[https://github.com/django/django/blob/551c997feaaa293987af8b05efc3634b93305fac/django/forms/forms.py#L54
`BaseForm`] does not have a class level initialisation of these. The
classes are then later added via a `hasattr` check.

I was wondering if class level defaults (`None`) should be added for these
to make them more discovarable, also the `hasattr` logic can just be
replaced with `Form.required_css_class`

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

Django

unread,
Oct 26, 2021, 2:42:54 AM10/26/21
to django-...@googlegroups.com
#33226: Add css class hooks to BaseForm
-------------------------------+--------------------------------------

Reporter: David Smith | Owner: nobody
Type: Uncategorized | Status: closed
Component: Uncategorized | Version: 3.2
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Carlton Gibson):

* status: new => closed
* resolution: => duplicate


Comment:

Hey David, this is a duplicate of #14322.

''Possibly'' that's worth re-opening (via a discussion,
[https://docs.djangoproject.com/en/dev/internals/contributing/triaging-
tickets/#closing-tickets following triage guidelines for wontfix tickets])
— auto-complete and type checkers much prefer attributes to be defined (as
`None`?) rather than injected later.

I recall we've closed similar proposals along these lines though; often
the references are able to remain entirely within the injecting code,
whereas if they're declared (suddenly) they're split over multiple files.
(e.g. excluding usages, `required_css_class` appears **only** in
`boundfield.py`) — we didn't want to litter class definitions and/or init
methods with `None` declarations. (Better the tooling gets cleverer.)

Also #14322 (and #3512) were concerned about backwards compatibility. The
specific issue there may not apply after all this time, but it needs a
thought.

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

Reply all
Reply to author
Forward
0 new messages