djblets.extensions.staticfiles¶
- class ExtensionStaticStorage(*args, **kwargs)¶
Bases:
FileSystemStorage
Provides access to static files owned by an extension.
This is a thin wrapper around FileSystemStorage that determines the path to the static directory within the extension. It will only operate on files within that path.
- source_dir = 'static'¶
- prefix = None¶
- __init__(extension, *args, **kwargs)¶
- class ExtensionFinder(*args, **kwargs)¶
Bases:
BaseFinder
Finds static files within enabled extensions.
ExtensionFinder can list static files belonging to an extension, and find the path of a static file, given an extension ID and path.
All static files are expected to be in the form of
ext/<extension_id>/<path>
, whereextension_id
is the ID given to an extension (based on the full class path for the extension class).An extension is only valid if it has a “static” directory.
- storage_class¶
alias of
ExtensionStaticStorage
- __init__(*args, **kwargs)¶
- find(path, all=False)¶
Finds the real path to a static file, given a static path.
The path must start with “ext/<extension_id>/”. The files within will map to files within the extension’s “static” directory.
- class PackagingCachedFilesStorage(*args, **kwargs)¶
Bases:
PipelineStorage
Looks up referenced static files from the current storage.
When one static file references another, Django assumes that the referenced file is in the same static storage and path as that of the parent. This prevents a bundled file (such as a .less file) in an extension from referencing an image or other file shipped with the main application.
This storage works around this by attempting to look up a storage matching the referenced path. If found, the paths from that storage will be used instead.
This behavior is only activated when Django performs a lookup as the result of a
.css
containing aurl(...)
or@import ...
.- __init__(*args, **kwargs)¶
- hashed_name(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.
- class PackagingStorage(storage=None, *args, **kwargs)¶
Bases:
PipelineFinder
Looks up stored files when packaging an extension.
This is a special Pipeline static file storage implementation that can locate the proper Storage class when trying to find a file.
This works just like PipelineFinder, but can interface with PackagingFinder to trigger a lookup across all storages, since PackagingFinder by default limits to the extension’s static files.
- find_storage(name)¶
- class PackagingFinder(app_names=None, *args, **kwargs)¶
Bases:
FileSystemFinder
Finds static media files for an extension.
This is used during packaging to list only static media files provided by the extension, but to allow looking up static media from all apps.
It works with PackagingStorage to do the appropriate lookup given the parameters passed.
Essentially, when collecting static media (using the collectstatic management command), Django will call list() on the finders, grabbing every known static file, and packaging those. For extensions, we don’t want to grab media files from the main apps, and want to limit only to the files bundled with the extension.
There are times when we do want to list all files, though. For example, when referencing definitions files provided by the project for .less files.
In the default case, PackagingFinder.list will only look up files from the extension, but if given an extra parameter that PackagingStorage can pass (used for finding referenced files), it will look through all storages.
- storage_class¶
alias of
PackagingStorage
- extension_static_dir = None¶