Skip to content

Instantly share code, notes, and snippets.

@sveinn-steinarsson
Created July 14, 2014 12:51
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sveinn-steinarsson/3c76bc174844948c5f98 to your computer and use it in GitHub Desktop.
Save sveinn-steinarsson/3c76bc174844948c5f98 to your computer and use it in GitHub Desktop.
Use django pipeline in Class Media (for example in admin.py)
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