{{{
class Editor(widgets.Textarea):
class Media:
js = ('editor/editor.js',)
css = {'all': ('editor/editor.css',)}
}}}
When using CachedFilesMixin, from the staticfiles contrib app, the right
path to the media file should be the one with the hash suffix but what we
got is just a concatenation of STATIC_URL and the relative path of the
media file.
--
Ticket URL: <https://code.djangoproject.com/ticket/21221>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_docs: => 0
* needs_better_patch: => 0
* component: contrib.admin => contrib.staticfiles
* needs_tests: => 0
* stage: Unreviewed => Accepted
Comment:
I haven't tested, but it seems like this should indeed work like you
described.
--
Ticket URL: <https://code.djangoproject.com/ticket/21221#comment:1>
Comment (by eranrund):
Hi!
Any plan to do anything about this?
This is unfortunately still broken :(
--
Ticket URL: <https://code.djangoproject.com/ticket/21221#comment:2>
Comment (by timgraham):
It doesn't appear that anyone has offered a patch.
--
Ticket URL: <https://code.djangoproject.com/ticket/21221#comment:3>
* owner: nobody => antonpp
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/21221#comment:4>
Comment (by dsanders11):
Many of the admin forms in Django mainline get around this by manually
using the `django.contrib.admin.templatetag.admin_static.static` template
tag when specifying the filename, although this has disadvantages. See
#25553 regarding the need for a lazy version of the tag since the forms
may be imported during the app registry process and try to evaluate the
templatetag too early (before `collectstatic` has run).
It's also tricky to have a subclass override one of the form assets if the
filename changes, requiring it to use the static version of the filename
to ensure it matches in all cases.
Off the top of my head (without thinking too deeply about it), it seems
like the change would fit best in the rendering process for the Media
widget? This is where the simple logic of prepending the `STATIC_URL`
occurs so it seems logical to do the transformation here, and also leaves
the filenames as their untransformed version up until the actual
rendering. Specifically seems like it would fit in the `absolute_path`
method
[https://github.com/django/django/blob/master/django/forms/widgets.py#L80
here].
--
Ticket URL: <https://code.djangoproject.com/ticket/21221#comment:5>
* status: assigned => new
* owner: antonpp =>
* cc: maxime.lorant@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/21221#comment:6>
Comment (by mlorant):
No patch from antonpp in seven months, so I allowed myself to set this
ticket to ''new'' again. Solution proposed by dsanders seems fine, but I
think we should be cautious and not re-process the URL at each
page/template generated (the static URL should not changed in time, unless
we call `collectstatic`)...
For information got the same problem when using a third-party library
(django-select2) in a project using a CDN : https://github.com/applegrew
/django-select2/issues/221#issuecomment-153666276
--
Ticket URL: <https://code.djangoproject.com/ticket/21221#comment:7>
* cc: info@… (added)
Comment:
I agree this is an issue. It is ether poorly documented that form media
behaves different than static files or the behaviour is just wrong.
I'd very much like to clarify that, before making any changes to `django-
select2`. If this is in deed wrong behaviour and not a documentation
issue, I can work on this on the DUTH sprints.
--
Ticket URL: <https://code.djangoproject.com/ticket/21221#comment:8>
Comment (by claudep):
I did some experiments with this, leading to
https://github.com/claudep/django/commit/2f5c6892523e80d57f9b50bb7bc2e5dcfc07426b
But I'm afraid this suffers from the re-processing load mentioned in
comment:7.
--
Ticket URL: <https://code.djangoproject.com/ticket/21221#comment:9>
* owner: => codingjoe
* status: new => assigned
Comment:
I agree. I'll look into it during the DUTH sprints.
--
Ticket URL: <https://code.djangoproject.com/ticket/21221#comment:10>
* cc: cmawebsite@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/21221#comment:11>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/21221#comment:12>
Comment (by collinanderson):
(If we don't like the contrib import from core, and alternative could be
to move the necessary code into core #25689). In this case I think it's
ok.
--
Ticket URL: <https://code.djangoproject.com/ticket/21221#comment:13>
Comment (by claudep):
Should we `lru_cache` the `static` tag results?
--
Ticket URL: <https://code.djangoproject.com/ticket/21221#comment:14>
Comment (by codingjoe):
I wouldn't. I don't see a big performance opportunity, but the risk that
someone wants to manipulate the storage during runtime.
I added a second commit that should clean up a little.
--
Ticket URL: <https://code.djangoproject.com/ticket/21221#comment:15>
* needs_better_patch: 0 => 1
Comment:
Left some comments for improvement on the
[https://github.com/django/django/pull/5571 pull request].
--
Ticket URL: <https://code.djangoproject.com/ticket/21221#comment:16>
* needs_better_patch: 1 => 0
Comment:
I hope I caught them all. Thanks Tim
--
Ticket URL: <https://code.djangoproject.com/ticket/21221#comment:17>
* needs_better_patch: 0 => 1
Comment:
Left some more comments.
--
Ticket URL: <https://code.djangoproject.com/ticket/21221#comment:18>
* needs_better_patch: 1 => 0
Comment:
Updated my PR
--
Ticket URL: <https://code.djangoproject.com/ticket/21221#comment:19>
* type: Bug => New feature
* stage: Accepted => Ready for checkin
Comment:
Looks good pending incorporation of my edits.
--
Ticket URL: <https://code.djangoproject.com/ticket/21221#comment:20>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"cf546e11ac76c8dec527e39ff8ce8249a195ab42" cf546e1]:
{{{
#!CommitTicketReference repository=""
revision="cf546e11ac76c8dec527e39ff8ce8249a195ab42"
Fixed #21221 -- Made form Media and static template tag use staticfiles if
installed.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/21221#comment:21>
Comment (by Tim Graham <timograham@…>):
In [changeset:"20e2b228aa87f2ce6341d5e96642c53b87a87459" 20e2b22]:
{{{
#!CommitTicketReference repository=""
revision="20e2b228aa87f2ce6341d5e96642c53b87a87459"
Refs #21221 -- Added test for legacy static usage in form Media.
Before cf546e1, static files in form or widget Media were usually
wrapped with contrib.staticfiles.templatetags.staticfiles.static.
This test ensures compatibility with third-party code that's still
using this pattern.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/21221#comment:22>
Comment (by Tim Graham <timograham@…>):
In [changeset:"a85e84212e0c0aa05a7c7ddd3ca81a4228ef013e" a85e842]:
{{{
#!CommitTicketReference repository=""
revision="a85e84212e0c0aa05a7c7ddd3ca81a4228ef013e"
Refs #21221 -- Prevented {% static %} tests from using
contrib.staticfiles.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/21221#comment:23>
Comment (by Tim Graham <timograham@…>):
In [changeset:"7d607127e39792aa45b6abc2619b99fc55bcc672" 7d607127]:
{{{
#!CommitTicketReference repository=""
revision="7d607127e39792aa45b6abc2619b99fc55bcc672"
Refs #21221 -- Deprecated staticfiles and admin_static template tag
libraries.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/21221#comment:24>
Comment (by Tim Graham <timograham@…>):
In [changeset:"92d4d0859a63347de6e2a7bc3ddd49979cc192c5" 92d4d085]:
{{{
#!CommitTicketReference repository=""
revision="92d4d0859a63347de6e2a7bc3ddd49979cc192c5"
Refs #21221 -- Removed staticfiles and admin_static template tag
libraries.
Per deprecation timeline.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/21221#comment:25>