d-demirci / django-adminlte3

AdminLTE Templates, Template Tags, and Admin Theme for Django
https://django-adminlte3.herokuapp.com/admin
Other
244 stars 111 forks source link

collectstatic fails when using ManifestStaticFilesStorage #12

Closed danstreeter closed 4 years ago

danstreeter commented 4 years ago

The collectstatic command fails to process when you are using STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage' within your project.

This is because jquery-ui css files contain comments which have paths in them that match the collectstatic regex parsing.

A similar issue has been documented here: https://github.com/django-helpdesk/django-helpdesk/issues/479

As I am using this package within a Docker container and have control over my build process, I have implemented the following workaround within my Dockerfile build process just before the build does the collectstatic command:

# - Dynamically locate the python install directory and tack the package path on the end,
# - Iterate over each of the css files and delete out the offending line with sed outputting it to a new file with .2 on the end,
# - Iterate over the .2 files and move them over the top of the original by moving to the name without the last extension.
# I found that merely directing the output of sed to the same file caused empty files so that is another hacky workaround - but it works!
RUN cd $(pip show django-adminlte3 | grep Location | cut -d" " -f2)/adminlte3/static/admin-lte/plugins/jquery-ui && for f in *.css; do echo "Removing offending comments from $f"; sed '/To view and modify this theme/d' $f > $f.2; done && for f in *.css.2; do mv "$f" "${f%.*}"; done

Not sure how else to get around it given that the jQuery files will be brought in from somewhere else and there isn't really any control over it - but this has fit my use case and my build process is now able to 'collectstatic' as needed without any issues.

d-demirci commented 4 years ago

as you mentioned this is related to comments in jquery css files and thanks for the one-liner. It will be good to refer your one-liner in README. For the people who is facing the same issue (and not using Dockerfile) after installing django-adminlte3 run above command without RUN at the beginning. Like this : cd $(pip show django-adminlte3 | grep Location | cut -d" " -f2)/adminlte3/static/admin-lte/plugins/jquery-ui && for f in *.css; do echo "Removing offending comments from $f"; sed '/To view and modify this theme/d' $f > $f.2; done && for f in *.css.2; do mv "$f" "${f%.*}"; done

danstreeter commented 4 years ago

No problem at all. The command that the Dockerfile is running may not be fully supported on the environments the users are using, as the Dockerfile will be running in a known and controlled linux environment with all of the binaries required; and not on the host.

Those on OSX would have differing, potentially failure results because of the binaries used on that command and the parameters it requires, cut parameters differs from Linux to OSX for example.

Those on Windows wont have a hope of it working. (Not even tried as I dont have a Windows machine to test with)

d-demirci commented 4 years ago

Ok I removed the comments with bf7bcca0aeb67070c873858d936f74485cb5ebe7 pypi version 0.1.6 with every adminlte.io update, this should be checked.