Created
July 14, 2014 12:51
-
-
Save sveinn-steinarsson/3c76bc174844948c5f98 to your computer and use it in GitHub Desktop.
Use django pipeline in Class Media (for example in admin.py)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib.staticfiles.storage import staticfiles_storage | |
from pipeline.packager import Packager | |
from pipeline.conf import settings | |
def get_pipeline_urls(package_type, package_name): | |
packager = Packager() | |
package = packager.package_for(package_type, package_name) | |
if settings.PIPELINE_ENABLED: | |
return ( staticfiles_storage.url(package.output_filename), ) | |
else: | |
files = () | |
for path in package.paths: | |
files += ( staticfiles_storage.url(path), ) | |
return files | |
# Usage: | |
# ... | |
# class Media: | |
# css = { | |
# 'all': get_pipeline_urls('css','your_css_package_name') | |
# } | |
# js = get_pipeline_urls('js','your_js_package_name') | |
# ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment