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.
* 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>
* keywords: field is_readonly <p> => callable field is_readonly <p>
--
Ticket URL: <https://code.djangoproject.com/ticket/27386#comment:2>
* 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>
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>
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>
* 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>
* status: closed => new
* resolution: fixed =>
* needs_tests: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/27386#comment:7>
* needs_better_patch: 0 => 1
Comment:
Some comments for improvement are on the PR.
--
Ticket URL: <https://code.djangoproject.com/ticket/27386#comment:8>
* 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>