models: Make all fields default to None or empty collection
(cherry picked from commit abed15b9e4)
This commit is contained in:
parent
a4b17a9aa8
commit
680dbffc0c
@ -16,6 +16,10 @@ v0.19.5 (UNRELEASED)
|
|||||||
and in the other case explicitly set to the default value, but with otherwise
|
and in the other case explicitly set to the default value, but with otherwise
|
||||||
equal fields. (Fixes: :issue:`837`)
|
equal fields. (Fixes: :issue:`837`)
|
||||||
|
|
||||||
|
- Changed the default value of :attr:`mopidy.models.Album.num_tracks`,
|
||||||
|
:attr:`mopidy.models.Track.track_no`, and
|
||||||
|
:attr:`mopidy.models.Track.last_modified` from ``0`` to :class:`None`.
|
||||||
|
|
||||||
|
|
||||||
v0.19.4 (2014-09-01)
|
v0.19.4 (2014-09-01)
|
||||||
====================
|
====================
|
||||||
|
|||||||
@ -241,7 +241,7 @@ class Album(ImmutableObject):
|
|||||||
:param artists: album artists
|
:param artists: album artists
|
||||||
:type artists: list of :class:`Artist`
|
:type artists: list of :class:`Artist`
|
||||||
:param num_tracks: number of tracks in album
|
:param num_tracks: number of tracks in album
|
||||||
:type num_tracks: integer
|
:type num_tracks: integer or :class:`None` if unknown
|
||||||
:param num_discs: number of discs in album
|
:param num_discs: number of discs in album
|
||||||
:type num_discs: integer or :class:`None` if unknown
|
:type num_discs: integer or :class:`None` if unknown
|
||||||
:param date: album release date (YYYY or YYYY-MM-DD)
|
:param date: album release date (YYYY or YYYY-MM-DD)
|
||||||
@ -262,7 +262,7 @@ class Album(ImmutableObject):
|
|||||||
artists = frozenset()
|
artists = frozenset()
|
||||||
|
|
||||||
#: The number of tracks in the album. Read-only.
|
#: The number of tracks in the album. Read-only.
|
||||||
num_tracks = 0
|
num_tracks = None
|
||||||
|
|
||||||
#: The number of discs in the album. Read-only.
|
#: The number of discs in the album. Read-only.
|
||||||
num_discs = None
|
num_discs = None
|
||||||
@ -302,7 +302,7 @@ class Track(ImmutableObject):
|
|||||||
:param genre: track genre
|
:param genre: track genre
|
||||||
:type genre: string
|
:type genre: string
|
||||||
:param track_no: track number in album
|
:param track_no: track number in album
|
||||||
:type track_no: integer
|
:type track_no: integer or :class:`None` if unknown
|
||||||
:param disc_no: disc number in album
|
:param disc_no: disc number in album
|
||||||
:type disc_no: integer or :class:`None` if unknown
|
:type disc_no: integer or :class:`None` if unknown
|
||||||
:param date: track release date (YYYY or YYYY-MM-DD)
|
:param date: track release date (YYYY or YYYY-MM-DD)
|
||||||
@ -316,7 +316,7 @@ class Track(ImmutableObject):
|
|||||||
:param musicbrainz_id: MusicBrainz ID
|
:param musicbrainz_id: MusicBrainz ID
|
||||||
:type musicbrainz_id: string
|
:type musicbrainz_id: string
|
||||||
:param last_modified: Represents last modification time
|
:param last_modified: Represents last modification time
|
||||||
:type last_modified: integer
|
:type last_modified: integer or :class:`None` if unknown
|
||||||
"""
|
"""
|
||||||
|
|
||||||
#: The track URI. Read-only.
|
#: The track URI. Read-only.
|
||||||
@ -341,7 +341,7 @@ class Track(ImmutableObject):
|
|||||||
genre = None
|
genre = None
|
||||||
|
|
||||||
#: The track number in the album. Read-only.
|
#: The track number in the album. Read-only.
|
||||||
track_no = 0
|
track_no = None
|
||||||
|
|
||||||
#: The disc number in the album. Read-only.
|
#: The disc number in the album. Read-only.
|
||||||
disc_no = None
|
disc_no = None
|
||||||
@ -364,7 +364,7 @@ class Track(ImmutableObject):
|
|||||||
#: Integer representing when the track was last modified, exact meaning
|
#: Integer representing when the track was last modified, exact meaning
|
||||||
#: depends on source of track. For local files this is the mtime, for other
|
#: depends on source of track. For local files this is the mtime, for other
|
||||||
#: backends it could be a timestamp or simply a version counter.
|
#: backends it could be a timestamp or simply a version counter.
|
||||||
last_modified = 0
|
last_modified = None
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
get = lambda key: frozenset(kwargs.pop(key, None) or [])
|
get = lambda key: frozenset(kwargs.pop(key, None) or [])
|
||||||
|
|||||||
@ -44,11 +44,11 @@ def track_to_mpd_format(track, position=None):
|
|||||||
if track.date:
|
if track.date:
|
||||||
result.append(('Date', track.date))
|
result.append(('Date', track.date))
|
||||||
|
|
||||||
if track.album is not None and track.album.num_tracks != 0:
|
if track.album is not None and track.album.num_tracks is not None:
|
||||||
result.append(('Track', '%d/%d' % (
|
result.append(('Track', '%d/%d' % (
|
||||||
track.track_no, track.album.num_tracks)))
|
track.track_no or 0, track.album.num_tracks)))
|
||||||
else:
|
else:
|
||||||
result.append(('Track', track.track_no))
|
result.append(('Track', track.track_no or 0))
|
||||||
if position is not None and tlid is not None:
|
if position is not None and tlid is not None:
|
||||||
result.append(('Pos', position))
|
result.append(('Pos', position))
|
||||||
result.append(('Id', tlid))
|
result.append(('Id', tlid))
|
||||||
|
|||||||
@ -741,12 +741,6 @@ class TrackTest(unittest.TestCase):
|
|||||||
self.assertEqual(track1, track2)
|
self.assertEqual(track1, track2)
|
||||||
self.assertEqual(hash(track1), hash(track2))
|
self.assertEqual(hash(track1), hash(track2))
|
||||||
|
|
||||||
def test_ignores_values_with_default_value_zero(self):
|
|
||||||
track1 = Track(name='name1')
|
|
||||||
track2 = Track(name='name1', track_no=0)
|
|
||||||
self.assertEqual(track1, track2)
|
|
||||||
self.assertEqual(hash(track1), hash(track2))
|
|
||||||
|
|
||||||
def test_copy_can_reset_to_default_value(self):
|
def test_copy_can_reset_to_default_value(self):
|
||||||
track1 = Track(name='name1')
|
track1 = Track(name='name1')
|
||||||
track2 = Track(name='name1', album=Album()).copy(album=None)
|
track2 = Track(name='name1', album=Album()).copy(album=None)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user