def get_filename(self, basename): """ Returns full path to a file, for example: get_filename('css/one.css') -> '/full/path/to/static/css/one.css' """ filename = None # First try finding the file using the storage class. # This is skipped in DEBUG mode as files might be outdated in # compressor's final destination (COMPRESS_ROOT) during development if not settings.DEBUG: try: # call path first so remote storages don't make it to exists, # which would cause network I/O filename = self.storage.path(basename) if not self.storage.exists(basename): filename = None except NotImplementedError: # remote storages don't implement path, access the file locally if compressor_file_storage.exists(basename): filename = compressor_file_storage.path(basename) # secondly try to find it with staticfiles if not filename and self.finders: filename = self.finders.find(url2pathname(basename)) if filename: return filename # or just raise an exception as the last resort raise UncompressableFileError( "'%s' could not be found in the COMPRESS_ROOT '%s'%s" % ( basename, settings.COMPRESS_ROOT, self.finders and " or with staticfiles." or ".", ) )
def get_filename(self, basename): """ Returns full path to a file, for example: get_filename('css/one.css') -> '/full/path/to/static/css/one.css' """ filename = None # First try finding the file using the storage class. # This is skipped in DEBUG mode as files might be outdated in # compressor's final destination (COMPRESS_ROOT) during development if not settings.DEBUG: try: # call path first so remote storages don't make it to exists, # which would cause network I/O filename = self.storage.path(basename) if not self.storage.exists(basename): filename = None except NotImplementedError: # remote storages don't implement path, access the file locally if compressor_file_storage.exists(basename): filename = compressor_file_storage.path(basename) # secondly try to find it with staticfiles if not filename and self.finders: filename = self.finders.find(url2pathname(basename)) if filename: return filename # or just raise an exception as the last resort raise UncompressableFileError( "'%s' could not be found in the COMPRESS_ROOT '%s'%s" % (basename, settings.COMPRESS_ROOT, self.finders and " or with staticfiles." or "."))
def get_filename(self, basename): """ Returns full path to a file, for example: get_filename('css/one.css') -> '/full/path/to/static/css/one.css' """ filename = None # First try finding the file using the storage class. # This is skipped in DEVELOPER_MODE mode as files might be outdated # Or may not even be on disk. if not getattr(settings, "DEVELOPER_MODE", False): filename = staticfiles_storage.path(basename) if not staticfiles_storage.exists(basename): filename = None # secondly try to find it with staticfiles if not filename: filename = find_staticfiles(url2pathname(basename)) return filename
def file_path(self, url): """ Returns the relative path to the media file on disk for the given URL. """ relative_url = url[len(self.base_url[2]):] return url2pathname(relative_url)
from django.conf import settings