Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
inline: make the album/item available directly
There have been multiple requests, in the past, for the ability to use plugin fields in inline fields. This has not previously been available. From what I can tell, it was intentionally left unavailable due to performance concerns. The way the item fields are made available to the inline python code means that all fields are looked up, whether they're actually used by the code or not. Doing that for all computed fields would be a performance concern. I don't believe there's a good way to postpone the field computation, as python eval and compile requires that globals be a dictionary, not a mapping. Instead, we can make available the album or item model object to the code directly, and let the code access the fields it needs via that object, resulting in postponing the computation of the fields until they're actually accessed. This is a simple approach that makes the computed and plugin fields available to inline python, which allows for more code reuse, as well as more options for shifting logic out of templates and into python code. In items, the object is available as 'item', and in albums, it's available as 'album'. Examples: item_fields: test_file_size: item.filesize album_fields: test_album_path: album.path # If the missing plugin is enabled test_album_missing: album.missing Signed-off-by: Christopher Larson <kergoth@gmail.com>
- Loading branch information