[Django] #30077: TextField constructor needs a strip=False option

6 views
Skip to first unread message

Django

unread,
Jan 5, 2019, 4:54:08 AM1/5/19
to django-...@googlegroups.com
#30077: TextField constructor needs a strip=False option
-------------------------------------+-------------------------------------
Reporter: Rob van | Owner: nobody
der Linde |
Type: | Status: new
Uncategorized |
Component: Database | Version: 2.1
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
In Django 1.9 an option strip=True was added to CharField, this is fine
but it also seems to affect TextField and there is no way to pass a
strip=False option to TextField constructor to turn that off.

The issue seems to be the formfield method, this has lead to people
subclassing TextField to "fix" this addition to Django 1.9, for example:

{{{
class NonStrippingTextField(TextField):
"""A TextField that does not strip whitespace at the beginning/end of
it's value. Might be important for markup/code."""

def formfield(self, **kwargs):
kwargs['strip'] = False
return super(NonStrippingTextField, self).formfield(**kwargs)

}}}

Other people fix it in the form and override the admin form, this has
become a bit messy, it seems to be necessary to introduce a strip argument
to the TextField constructor, to avoid having to create custom field
types.

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

Django

unread,
Jan 5, 2019, 9:01:07 AM1/5/19
to django-...@googlegroups.com
#30077: TextField constructor needs a strip=False option
-------------------------------------+-------------------------------------
Reporter: Rob van der Linde | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: 2.1
(models, ORM) |
Severity: Normal | Resolution:
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 Simon Charette):

* type: Uncategorized => New feature


Comment:

Just to make it clear the `strip=True` option was added to
`forms.CharField` and not `db.CharField` like the report seems to imply.
Moving this option to the database layer has been discussed and rejected
when the option was added to the form layer so I doubt there's consensus
on adding an option to specialize `TextField` here given striping spaces
should be the desired behaviour in most cases just like with
`db.CharField`.

> Other people fix it in the form and override the admin form

Can't this be simply done with
[https://docs.djangoproject.com/en/2.1/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_overrides
formfield_overrides] or `formfield_for_dbfield`?

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

Django

unread,
Jan 5, 2019, 12:57:43 PM1/5/19
to django-...@googlegroups.com
#30077: TextField constructor needs a strip=False option
-------------------------------------+-------------------------------------
Reporter: Rob van der Linde | Owner: nobody
Type: New feature | Status: closed

Component: Database layer | Version: 2.1
(models, ORM) |
Severity: Normal | Resolution: invalid
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 Rob van der Linde):

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


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

Django

unread,
Jan 5, 2019, 12:58:56 PM1/5/19
to django-...@googlegroups.com
#30077: TextField constructor needs a strip=False option
-------------------------------------+-------------------------------------
Reporter: Rob van der Linde | Owner: nobody
Type: New feature | Status: closed
Component: Database layer | Version: 2.1
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Rob van der Linde):

Ah I see, I'll have to find a Wagtail specific fix, though I must say I do
find this feature added to Django 1.9 extremely annoying.

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

Reply all
Reply to author
Forward
0 new messages