2019-10-23 14:44:17 +01:00
|
|
|
from enum import Enum
|
|
|
|
|
2020-04-30 14:54:05 +01:00
|
|
|
from fireo.models import Model
|
|
|
|
from fireo.fields import TextField, BooleanField, DateTime, NumberField, ListField
|
2019-10-23 14:44:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Sort(Enum):
|
2019-11-02 11:44:24 +00:00
|
|
|
default = 1
|
|
|
|
shuffle = 2
|
|
|
|
release_date = 3
|
2019-10-23 14:44:17 +01:00
|
|
|
|
|
|
|
|
2020-04-30 14:54:05 +01:00
|
|
|
class Playlist(Model):
|
|
|
|
class Meta:
|
|
|
|
collection_name = 'playlists'
|
2020-02-24 18:15:38 +00:00
|
|
|
|
2020-04-30 14:54:05 +01:00
|
|
|
uri = TextField()
|
|
|
|
name = TextField(required=True)
|
|
|
|
type = TextField(required=True)
|
2019-10-23 14:44:17 +01:00
|
|
|
|
2020-04-30 14:54:05 +01:00
|
|
|
include_recommendations = BooleanField(default=False)
|
|
|
|
recommendation_sample = NumberField(default=10)
|
|
|
|
include_library_tracks = BooleanField(default=False)
|
2019-10-23 14:44:17 +01:00
|
|
|
|
2020-04-30 14:54:05 +01:00
|
|
|
parts = ListField(default=[])
|
|
|
|
playlist_references = ListField(default=[])
|
|
|
|
shuffle = BooleanField(default=False)
|
2019-10-23 14:44:17 +01:00
|
|
|
|
2020-04-30 14:54:05 +01:00
|
|
|
sort = TextField(default='release_date')
|
|
|
|
description_overwrite = TextField()
|
|
|
|
description_suffix = TextField()
|
2019-10-23 14:44:17 +01:00
|
|
|
|
2020-04-30 14:54:05 +01:00
|
|
|
last_updated = DateTime()
|
2019-10-23 14:44:17 +01:00
|
|
|
|
2020-04-30 14:54:05 +01:00
|
|
|
lastfm_stat_count = NumberField(default=0)
|
|
|
|
lastfm_stat_album_count = NumberField(default=0)
|
|
|
|
lastfm_stat_artist_count = NumberField(default=0)
|
2019-10-23 14:44:17 +01:00
|
|
|
|
2020-04-30 14:54:05 +01:00
|
|
|
lastfm_stat_percent = NumberField(default=0)
|
|
|
|
lastfm_stat_album_percent = NumberField(default=0)
|
|
|
|
lastfm_stat_artist_percent = NumberField(default=0)
|
2019-10-23 14:44:17 +01:00
|
|
|
|
2020-04-30 14:54:05 +01:00
|
|
|
lastfm_stat_last_refresh = DateTime()
|
2020-02-24 18:15:38 +00:00
|
|
|
|
2020-04-30 14:54:05 +01:00
|
|
|
add_last_month = BooleanField(default=False)
|
|
|
|
add_this_month = BooleanField(default=False)
|
|
|
|
day_boundary = NumberField(default=21)
|
2019-10-23 14:44:17 +01:00
|
|
|
|
2020-05-08 15:19:27 +01:00
|
|
|
chart_range = TextField(default='MONTH')
|
2020-04-30 14:54:05 +01:00
|
|
|
chart_limit = NumberField(default=50)
|
2019-10-23 14:44:17 +01:00
|
|
|
|
2020-07-29 10:45:40 +01:00
|
|
|
mutable_keys = [
|
|
|
|
'type',
|
|
|
|
|
|
|
|
'include_recommendations',
|
|
|
|
'recommendation_sample',
|
|
|
|
'include_library_tracks',
|
|
|
|
|
|
|
|
'parts',
|
|
|
|
'playlist_references',
|
|
|
|
'shuffle',
|
|
|
|
|
|
|
|
'sort',
|
|
|
|
'description_overwrite',
|
|
|
|
'description_suffix',
|
|
|
|
|
|
|
|
'add_last_month',
|
|
|
|
'add_this_month',
|
|
|
|
'day_boundary',
|
|
|
|
|
|
|
|
'chart_range',
|
|
|
|
'chart_limit'
|
|
|
|
]
|
|
|
|
|
2019-10-23 14:44:17 +01:00
|
|
|
def to_dict(self):
|
2020-04-30 14:54:05 +01:00
|
|
|
to_return = super().to_dict()
|
2019-11-01 23:46:49 +00:00
|
|
|
|
2020-04-30 14:54:05 +01:00
|
|
|
to_return["playlist_references"] = [i.get().to_dict().get('name') for i in to_return['playlist_references']]
|
2019-11-01 23:46:49 +00:00
|
|
|
|
2020-04-30 14:54:05 +01:00
|
|
|
# remove unnecessary and sensitive fields
|
|
|
|
to_return.pop('id', None)
|
|
|
|
to_return.pop('key', None)
|
2019-11-01 23:46:49 +00:00
|
|
|
|
2020-04-30 14:54:05 +01:00
|
|
|
return to_return
|