mirror of
https://github.com/beetbox/beets.git
synced 2025-12-31 13:02:47 +01:00
Add defaut value to formatted mapping dict.
This mimics dict get method behavior.
This commit is contained in:
parent
9901d6a4eb
commit
4aa626d263
2 changed files with 7 additions and 4 deletions
|
|
@ -590,13 +590,16 @@ class FormattedItemMapping(dbcore.db.FormattedMapping):
|
|||
if key in Album.item_keys or key not in item._fields.keys():
|
||||
self.album_keys.append(key)
|
||||
|
||||
def get(self, key):
|
||||
def get(self, key, default=None):
|
||||
if key in self.album_keys:
|
||||
return self.album._get_formatted(key, self.for_path)
|
||||
elif key in self.model_keys:
|
||||
return self.model._get_formatted(key, self.for_path)
|
||||
else:
|
||||
raise KeyError(key)
|
||||
if default is None:
|
||||
raise KeyError(key)
|
||||
else:
|
||||
return default
|
||||
|
||||
def __getitem__(self, key):
|
||||
value = self.get(key)
|
||||
|
|
|
|||
|
|
@ -576,8 +576,8 @@ def _field_diff(field, old, new):
|
|||
return None
|
||||
|
||||
# Get formatted values for output.
|
||||
oldstr = old.formatted.get(field) or u''
|
||||
newstr = new.formatted.get(field) or u''
|
||||
oldstr = old.formatted.get(field, u'')
|
||||
newstr = new.formatted.get(field, u'')
|
||||
|
||||
# For strings, highlight changes. For others, colorize the whole
|
||||
# thing.
|
||||
|
|
|
|||
Loading…
Reference in a new issue