Open thclark opened 4 years ago
Some further discussion of the same issue in https://code.djangoproject.com/ticket/21221
Thanks @thclark for the analysis, I think have the same issue, which makes it impossible to use the icons in my project together with whitenoise. A workaround is simply not possible, right? Since I need to use sth. like whitenoise in my setup with Django 3, I cannot use this package.
The fix seems to be simple, but I'm not sure how to write a unit test for it. How can I force manifested static files collection in a test? Could this be done by just setting
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'
in the settings in the test and then calling 'collectstatic'?
Thanks @thclark for the analysis, I think have the same issue, which makes it impossible to use the icons in my project together with whitenoise. A workaround is simply not possible, right? Since I need to use sth. like whitenoise in my setup with Django 3, I cannot use this package.
The fix seems to be simple, but I'm not sure how to write a unit test for it. How can I force manifested static files collection in a test? Could this be done by just setting
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'
in the settings in the test and then calling 'collectstatic'?
Hmm. I don't know actually. Yes, I guess so! Even if untested in this particular scenario it'd be a helpful fix to have (I'm still in the dark ages on font awesome 4!)
@mcrot this might be of help; use call_command
to do the static collection within a unit test...
https://adamj.eu/tech/2020/09/07/how-to-unit-test-a-django-management-command/
There seem to be no tests so far, so maybe I should not be holier than the pope.
I've created a PR with your fix, but I haven't tested it yet. Is it easy for you to do a manual test? For me it's a bit difficult in my setup.
However, I will also try the package django-icons as an alternative which is using a CDN.
Thanks for the pointer to call_command
, I would definitely need it for a test.
I think django-fontawesome-5 is incompatible with manifested static files collection (e.g. using whitenoise to efficiently cache and serve).
This is because the
css_admin
is not lazily evaluated atwidgets.py, line 9
:This gets called even when invoking management commands, like
collectstatic
. Of course, if you are compressing and/or manifesting your static files (e.g. like using a CDN or whitenoise) the call tostatic()
(which gets their new, hashed, name) will check for the presence of the file in the manifest... which isn't there, because you haven't run collectstatic yet!Without such manifesting, it's not a problem because django won't run the check for the presence of the modified filename.
Basically, you can't call
get_css_admin()
until such a time as you can reasonably expect thatcollectstatic
will have completed. I think the fix is as simple as moving the call to theMedia
class below.Here's a traceback: