[Django] #27386: Callable field is wrapped inside <p>...</p>

11 views
Skip to first unread message

Django

unread,
Oct 25, 2016, 5:15:36 PM10/25/16
to django-...@googlegroups.com
#27386: Callable field is wrapped inside <p>...</p>
--------------------------------------+--------------------
Reporter: Jacob Rief | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Keywords: field
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+--------------------
(Pseudo)-Fields in classes inheriting from
``django.contrib.admin.ModelsAdmin`` which are callables, must be listed
in ``readonly_fields``. This implies that in
``admin/includes/fieldset.html`` (line 17) and
``admin/edit_inline/tabular.html`` (line 55) the content of this field is
wrapped inside a paragraph ``<p>{{ field.contents }}</p>``.

However, a ``<p>...</p>`` is not suitable to accept every kind of HTML
element. Therefore when using a "callable" field, which renders it's
content in HTML, one might get a surprising result.

Since the author of a callable field may wrap it's content into whatever
(s)he likes, there should be a way to avoid these wrapping paragraphs.

My proposal is to check if ``field.contents`` is safe text, and if so then
leave it as-is, or otherwise wrap it into ``<p>..</p>`` as we do it right
now.

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

Django

unread,
Oct 25, 2016, 5:16:07 PM10/25/16
to django-...@googlegroups.com
#27386: Callable field is wrapped inside <p>...</p>
-------------------------------------+-------------------------------------

Reporter: Jacob Rief | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: field is_readonly | Triage Stage:
<p> | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Rief):

* keywords: field => field is_readonly <p>
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


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

Django

unread,
Oct 25, 2016, 5:16:26 PM10/25/16
to django-...@googlegroups.com
#27386: Callable field is wrapped inside <p>...</p>
-------------------------------------+-------------------------------------

Reporter: Jacob Rief | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: callable field | Triage Stage:
is_readonly <p> | Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Rief):

* keywords: field is_readonly <p> => callable field is_readonly <p>


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

Django

unread,
Oct 25, 2016, 6:36:20 PM10/25/16
to django-...@googlegroups.com
#27386: Readonly callable field is unconditionally wrapped inside <p>...</p>, which
might create invalid HTML
-------------------------------------+-------------------------------------

Reporter: Jacob Rief | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: callable field | Triage Stage: Accepted
is_readonly <p> |

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* stage: Unreviewed => Accepted


Old description:

> (Pseudo)-Fields in classes inheriting from
> ``django.contrib.admin.ModelsAdmin`` which are callables, must be listed
> in ``readonly_fields``. This implies that in
> ``admin/includes/fieldset.html`` (line 17) and
> ``admin/edit_inline/tabular.html`` (line 55) the content of this field is
> wrapped inside a paragraph ``<p>{{ field.contents }}</p>``.
>
> However, a ``<p>...</p>`` is not suitable to accept every kind of HTML
> element. Therefore when using a "callable" field, which renders it's
> content in HTML, one might get a surprising result.
>
> Since the author of a callable field may wrap it's content into whatever
> (s)he likes, there should be a way to avoid these wrapping paragraphs.
>
> My proposal is to check if ``field.contents`` is safe text, and if so
> then leave it as-is, or otherwise wrap it into ``<p>..</p>`` as we do it
> right now.

New description:

(Pseudo)-Fields in classes inheriting from
`django.contrib.admin.ModelsAdmin` which are callables, must be listed in
`readonly_fields`. This implies that in `admin/includes/fieldset.html`
(line 17) and `admin/edit_inline/tabular.html` (line 55) the content of
this field is wrapped inside a paragraph `<p>{{ field.contents }}</p>`.

However, a `<p>...</p>` is not suitable to accept every kind of HTML
element. Therefore when using a "callable" field, which renders it's
content in HTML, one might get a surprising result.

Since the author of a callable field may wrap it's content into whatever
(s)he likes, there should be a way to avoid these wrapping paragraphs.

My proposal is to check if `field.contents` is safe text, and if so then
leave it as-is, or otherwise wrap it into `<p>..</p>` as we do it right
now.

--

Comment:

I'm not sure if the proposal is completely backwards-compatible, but the
problem seems real.

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

Django

unread,
Oct 26, 2016, 5:11:48 AM10/26/16
to django-...@googlegroups.com
#27386: Readonly callable field is unconditionally wrapped inside <p>...</p>, which
might create invalid HTML
-------------------------------------+-------------------------------------
Reporter: Jacob Rief | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: master

Severity: Normal | Resolution:
Keywords: callable field | Triage Stage: Accepted
is_readonly <p> |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Jacob Rief):

Yes, changing this could add a minor backwards compatibility problem;
something probably not really noticeable and if, easy to fix.

I looked at the code. We presumably should add another tag to
``django.contrib.admin.helpers.AdminReadonlyField.__init__`` named
``is_callable`` which is ``True`` for callable fields. Then in the
templates, we'd have to add another ``{% if field.is_callable %}`` and
only wrap the content inside ``<p>..</p>`` it that's false.

If this proposal is accepted, I will implement it right now.

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

Django

unread,
Oct 29, 2016, 8:41:24 PM10/29/16
to django-...@googlegroups.com
#27386: Readonly callable field is unconditionally wrapped inside <p>...</p>, which
might create invalid HTML
-------------------------------------+-------------------------------------
Reporter: Jacob Rief | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: master

Severity: Normal | Resolution:
Keywords: callable field | Triage Stage: Accepted
is_readonly <p> |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

I'm not sure. It doesn't seem obviously correct to assume that all
callables might have HTML.

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

Django

unread,
Nov 5, 2016, 9:34:35 AM11/5/16
to django-...@googlegroups.com
#27386: Readonly callable field is unconditionally wrapped inside <p>...</p>, which
might create invalid HTML
-------------------------------------+-------------------------------------
Reporter: Jacob Rief | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: contrib.admin | Version: master
Severity: Normal | Resolution: fixed

Keywords: callable field | Triage Stage: Accepted
is_readonly <p> |
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Rief):

* status: new => closed
* has_patch: 0 => 1
* resolution: => fixed
* needs_tests: 0 => 1


Comment:

PR https://github.com/django/django/pull/7477 to fix this ticket is
pending.

--
Ticket URL: <https://code.djangoproject.com/ticket/27386#comment:6>

Django

unread,
Nov 5, 2016, 9:46:38 AM11/5/16
to django-...@googlegroups.com
#27386: Readonly callable field is unconditionally wrapped inside <p>...</p>, which
might create invalid HTML
-------------------------------------+-------------------------------------
Reporter: Jacob Rief | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: master
Severity: Normal | Resolution:

Keywords: callable field | Triage Stage: Accepted
is_readonly <p> |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Rief):

* status: closed => new
* resolution: fixed =>
* needs_tests: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/27386#comment:7>

Django

unread,
Nov 8, 2016, 7:16:09 PM11/8/16
to django-...@googlegroups.com
#27386: Readonly callable field is unconditionally wrapped inside <p>...</p>, which
might create invalid HTML
-------------------------------------+-------------------------------------
Reporter: Jacob Rief | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: master

Severity: Normal | Resolution:
Keywords: callable field | Triage Stage: Accepted
is_readonly <p> |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* needs_better_patch: 0 => 1


Comment:

Some comments for improvement are on the PR.

--
Ticket URL: <https://code.djangoproject.com/ticket/27386#comment:8>

Django

unread,
Nov 12, 2016, 10:07:44 AM11/12/16
to django-...@googlegroups.com
#27386: Readonly callable field is unconditionally wrapped inside <p>...</p>, which
might create invalid HTML
-------------------------------------+-------------------------------------
Reporter: Jacob Rief | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: contrib.admin | Version: master
Severity: Normal | Resolution: fixed

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

* status: new => closed

* resolution: => fixed


Comment:

In [changeset:"b3162cab94ca2988c99afe01887a4b61d6a35c1a" b3162ca]:
{{{
#!CommitTicketReference repository=""
revision="b3162cab94ca2988c99afe01887a4b61d6a35c1a"
Fixed #27386 -- Wrapped admin's readonly fields in <div> rather than <p>.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27386#comment:9>

Reply all
Reply to author
Forward
0 new messages