diff options
author | Rocky Meza <rocky@fusionbox.com> | 2015-03-03 03:41:33 -0700 |
---|---|---|
committer | Rocky Meza <rocky@fusionbox.com> | 2015-04-22 16:07:00 -0600 |
commit | 518098530e4ab9c2f33303ba00f34a1575c7ba3c (patch) | |
tree | 855b44da4f5504cb2840e1785d621beb62c10611 /django_pyscss/utils.py | |
parent | 313c0e02b8d7b43ab534dd2491e07e37deeb17d3 (diff) | |
download | django-pyscss-518098530e4ab9c2f33303ba00f34a1575c7ba3c.tar.gz |
Add pyScss 1.3 and Python 3 support
Diffstat (limited to 'django_pyscss/utils.py')
-rw-r--r-- | django_pyscss/utils.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/django_pyscss/utils.py b/django_pyscss/utils.py index d668280..1f9e4b4 100644 --- a/django_pyscss/utils.py +++ b/django_pyscss/utils.py @@ -1,7 +1,9 @@ import fnmatch import os +from django.conf import settings from django.contrib.staticfiles import finders +from django.contrib.staticfiles.storage import staticfiles_storage def find_all_files(glob): @@ -17,3 +19,29 @@ def find_all_files(glob): or '', path), glob): yield path, storage + + +def get_file_from_storage(filename): + try: + filename = staticfiles_storage.path(filename) + except NotImplementedError: + # remote storages don't implement path + pass + if staticfiles_storage.exists(filename): + return filename, staticfiles_storage + else: + return None, None + + +def get_file_from_finders(filename): + for file_and_storage in find_all_files(filename): + return file_and_storage + return None, None + + +def get_file_and_storage(filename): + # TODO: the switch probably shouldn't be on DEBUG + if settings.DEBUG: + return get_file_from_finders(filename) + else: + return get_file_from_storage(filename) |