mirror of
https://github.com/beetbox/beets.git
synced 2026-01-15 04:34:23 +01:00
Item fields take precedence over Album fields in formatting
For consistency, this is reversed when formatting paths. Fixes #858.
This commit is contained in:
parent
0798af7774
commit
91c5d0ae12
2 changed files with 20 additions and 5 deletions
|
|
@ -217,7 +217,9 @@ class LibModel(dbcore.Model):
|
|||
|
||||
|
||||
class FormattedItemMapping(dbcore.db.FormattedMapping):
|
||||
"""Add lookup for album level fields.
|
||||
"""Add lookup for album-level fields.
|
||||
|
||||
Album-level fields take precedence if `for_path` is true.
|
||||
"""
|
||||
|
||||
def __init__(self, item, for_path=False):
|
||||
|
|
@ -234,10 +236,12 @@ class FormattedItemMapping(dbcore.db.FormattedMapping):
|
|||
"""Get the value for a key, either from the album or the item.
|
||||
Raise a KeyError for invalid keys.
|
||||
"""
|
||||
if key in self.album_keys:
|
||||
if self.for_path and key in self.album_keys:
|
||||
return self._get_formatted(self.album, key)
|
||||
elif key in self.model_keys:
|
||||
return self._get_formatted(self.model, key)
|
||||
elif key in self.album_keys:
|
||||
return self._get_formatted(self.album, key)
|
||||
else:
|
||||
raise KeyError(key)
|
||||
|
||||
|
|
@ -263,7 +267,6 @@ class FormattedItemMapping(dbcore.db.FormattedMapping):
|
|||
return len(self.all_keys)
|
||||
|
||||
|
||||
|
||||
class Item(LibModel):
|
||||
_table = 'items'
|
||||
_flex_table = 'item_attributes'
|
||||
|
|
|
|||
|
|
@ -478,7 +478,19 @@ class ItemFormattedMappingTest(_common.LibTestCase):
|
|||
formatted = self.i.formatted()
|
||||
self.assertEqual(formatted.get('other_field', 'default'), 'default')
|
||||
|
||||
def test_album_field_overrides_item_field(self):
|
||||
def test_item_precedence(self):
|
||||
album = self.lib.add_album([self.i])
|
||||
album['artist'] = 'foo'
|
||||
album.store()
|
||||
self.assertNotEqual('foo', self.i.formatted().get('artist'))
|
||||
|
||||
def test_album_flex_field(self):
|
||||
album = self.lib.add_album([self.i])
|
||||
album['flex'] = 'foo'
|
||||
album.store()
|
||||
self.assertEqual('foo', self.i.formatted().get('flex'))
|
||||
|
||||
def test_album_field_overrides_item_field_for_path(self):
|
||||
# Make the album inconsistent with the item.
|
||||
album = self.lib.add_album([self.i])
|
||||
album.album = 'foo'
|
||||
|
|
@ -487,7 +499,7 @@ class ItemFormattedMappingTest(_common.LibTestCase):
|
|||
self.i.store()
|
||||
|
||||
# Ensure the album takes precedence.
|
||||
formatted = self.i.formatted()
|
||||
formatted = self.i.formatted(for_path=True)
|
||||
self.assertEqual(formatted['album'], 'foo')
|
||||
|
||||
def test_artist_falls_back_to_albumartist(self):
|
||||
|
|
|
|||
Loading…
Reference in a new issue