Exemplo n.º 1
0
 def _create_static_file(self, name, content):
     file_path = os.path.join(settings.STATIC_ROOT, name)
     with open(file_path, 'wb') as f:
         self.created_static_files.append(file_path)
         f.write(content)
     storage = PipelineCachedStorage()
     return storage.url(name)
Exemplo n.º 2
0
 def _create_static_file(self, name, content):
     file_path = os.path.join(settings.STATIC_ROOT, name)
     with open(file_path, 'wb') as f:
         self.created_static_files.append(file_path)
         f.write(content)
     storage = PipelineCachedStorage()
     return storage.url(name)
Exemplo n.º 3
0
    def hashed_name(self, name, content=None):
        """Look up and generate a hashed filename for the given filename.

        This will attempt to find a storage that serves up the given filename.
        If found, the hashed data from that storage will be used instead.

        If not found, then this falls back to the default functionality of
        either generating a hashed filename from the parent static file's
        storage, or raising an exception about a missing file.

        Args:
            name (str): The name of the file to look up.
            content (str): The content of the file, if known.

        Returns:
            str: A resulting file path for the file, with a hash in the
                 filename.
        """
        finder_storage = PackagingStorage()

        try:
            # See if there's a storage matching the prefix for the name.
            # If so, that's where we'll be looking up the file path.
            matched_path, storage = finder_storage.find_storage(name)
        except ValueError:
            # There was no storage matching this, so fall back to default
            # behavior.
            return super(PackagingCachedFilesStorage, self).hashed_name(
                name, content)

        # Build a cached storage for the FileSystemStorage that was found.
        # We want to keep this around in a cache, so as not to create too
        # many copies of these.
        if storage.location in self._cached_storages:
            storage = self._cached_storages[storage.location]
        else:
            storage = PipelineCachedStorage(location=storage.location)
            self._cached_storages[storage.location] = storage

        return storage.hashed_name(matched_path, content)