mirror of
https://github.com/beetbox/beets.git
synced 2025-12-24 17:43:52 +01:00
item templates can use album flexattrs (fix #461)
This commit is contained in:
parent
da794ffc44
commit
cc5e3d489c
3 changed files with 28 additions and 3 deletions
|
|
@ -770,11 +770,12 @@ class Item(Model):
|
|||
"""
|
||||
mapping = super(Item, self)._formatted_mapping(for_path)
|
||||
|
||||
# Override album-level fields.
|
||||
# Merge in album-level fields.
|
||||
album = self.get_album()
|
||||
if album:
|
||||
for key in ALBUM_KEYS_ITEM:
|
||||
mapping[key] = album._get_formatted(key, for_path)
|
||||
for key in album.keys(True):
|
||||
if key in ALBUM_KEYS_ITEM or key not in ITEM_KEYS:
|
||||
mapping[key] = album._get_formatted(key, for_path)
|
||||
|
||||
# Use the album artist if the track artist is not set and
|
||||
# vice-versa.
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ consequences for all users are:
|
|||
the :doc:`/plugins/inline` to define a field called ``era``, you can now
|
||||
filter your library based on that field by typing something like
|
||||
``beet list era:goldenage``.
|
||||
* Album-level flexible attributes and plugin-provided attributes can now be
|
||||
used in path formats (and other item-level templates).
|
||||
|
||||
For developers, the short version of the story is that Item and Album objects
|
||||
provide *uniform access* across fixed, flexible, and computed attributes.
|
||||
|
|
|
|||
|
|
@ -1022,6 +1022,28 @@ class ImportTimeTest(_common.TestCase):
|
|||
self.assertGreater(self.singleton.added, 0)
|
||||
|
||||
|
||||
class TemplateTest(_common.LibTestCase):
|
||||
def album_fields_override_item_values(self):
|
||||
self.album = self.lib.add_album([self.i])
|
||||
self.album.albumartist = 'album-level'
|
||||
self.album.store()
|
||||
self.i.albumartist = 'track-level'
|
||||
self.i.store()
|
||||
self.assertEqual(self.i.evaluate_template('$albumartist'),
|
||||
'album-level')
|
||||
|
||||
def test_year_formatted_in_template(self):
|
||||
self.i.year = 123
|
||||
self.i.store()
|
||||
self.assertEqual(self.i.evaluate_template('$year'), '0123')
|
||||
|
||||
def test_album_flexattr_appears_in_item_template(self):
|
||||
self.album = self.lib.add_album([self.i])
|
||||
self.album.foo = 'baz'
|
||||
self.album.store()
|
||||
self.assertEqual(self.i.evaluate_template('$foo'), 'baz')
|
||||
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromName(__name__)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue