-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add full user reposts feed * Clean up * Fix ns references * Add 'is' field to full track and playlist * Use handle.lower() and handle_lc * Move to item type in activity
- Loading branch information
1 parent
2896103
commit bd8d544
Showing
7 changed files
with
216 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from flask_restx import fields | ||
from flask_restx.fields import MarshallingError | ||
from flask_restx.marshalling import marshal | ||
from .common import ns | ||
from .tracks import track, track_full | ||
from .playlists import playlist_model, full_playlist_model | ||
|
||
class ItemType(fields.Raw): | ||
def format(self, value): | ||
if value == "track": | ||
return "track" | ||
if value == "playlist": | ||
return "playlist" | ||
raise MarshallingError("Unable to marshal as activity type") | ||
|
||
|
||
class ActivityItem(fields.Raw): | ||
def format(self, value): | ||
try: | ||
if value.get("track_id"): | ||
return marshal(value, track) | ||
if value.get("playlist_id"): | ||
return marshal(value, playlist_model) | ||
except: | ||
raise MarshallingError("Unable to marshal as activity item") | ||
|
||
|
||
class FullActivityItem(fields.Raw): | ||
def format(self, value): | ||
try: | ||
if value.get("track_id"): | ||
return marshal(value, track_full) | ||
if value.get("playlist_id"): | ||
return marshal(value, full_playlist_model) | ||
except: | ||
raise MarshallingError("Unable to marshal as activity item") | ||
|
||
|
||
activity_model = ns.model("activity", { | ||
"timestamp": fields.String(allow_null=True), | ||
"item_type": ItemType, | ||
"item": ActivityItem | ||
}) | ||
|
||
activity_model_full = ns.model("activity", { | ||
"timestamp": fields.String(allow_null=True), | ||
"item_type": ItemType, | ||
"item": FullActivityItem | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters