djblets.extensions.staticfiles¶
Support for looking up static files in extensions.
- class ExtensionStaticStorage(*args, **kwargs)[source]¶
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.
- __init__(extension: Extension, *args, **kwargs) None [source]¶
Initialize the static files storage for an extension.
This will build a path for the extension’s static directory and set it, whether it exists or not.
- Parameters:
extension (
djblets.extensions.extension.Extension
) – The extension the static files storage is bound to.*args (
tuple
) – Positional arguments to pass to the parent class.**kwargs (
dict
) – Keyword arguments to pass to the parent class.
- class ExtensionFinder(*args, **kwargs)[source]¶
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[source]¶
alias of
ExtensionStaticStorage
- class PackagingCachedFilesStorage(*args, **kwargs)[source]¶
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 ...
.- hashed_name(name, content=None)[source]¶
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.
- __annotations__ = {}¶
- class PackagingStorage(storage=None, *args, **kwargs)[source]¶
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.
- __annotations__ = {}¶
- class PackagingFinder(app_names=None, *args, **kwargs)[source]¶
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[source]¶
alias of
PackagingStorage
- extension_static_dir: Optional[str] = None¶
The path to the extension static directory.
This is set during packaging to collect static media files from the extension.
- Type:
- __annotations__ = {'extension_static_dir': 'Optional[str]'}¶