mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-04 10:29:20 +02:00
See #170: add a description field on tracks, albums, tracks
This commit is contained in:
parent
424b9f133a
commit
2bc71eecfd
38 changed files with 653 additions and 59 deletions
|
@ -1,6 +1,8 @@
|
|||
from funkwhale_api.common import models as common_models
|
||||
from funkwhale_api.common import mutations
|
||||
from funkwhale_api.common import serializers as common_serializers
|
||||
from funkwhale_api.common import utils as common_utils
|
||||
|
||||
from funkwhale_api.federation import routes
|
||||
from funkwhale_api.tags import models as tags_models
|
||||
from funkwhale_api.tags import serializers as tags_serializers
|
||||
|
@ -23,11 +25,13 @@ def can_approve(obj, actor):
|
|||
|
||||
class TagMutation(mutations.UpdateMutationSerializer):
|
||||
tags = tags_serializers.TagsListField()
|
||||
previous_state_handlers = {
|
||||
"tags": lambda obj: list(
|
||||
|
||||
def get_previous_state_handlers(self):
|
||||
handlers = super().get_previous_state_handlers()
|
||||
handlers["tags"] = lambda obj: list(
|
||||
sorted(obj.tagged_items.values_list("tag__name", flat=True))
|
||||
)
|
||||
}
|
||||
return handlers
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
tags = validated_data.pop("tags", [])
|
||||
|
@ -36,17 +40,36 @@ class TagMutation(mutations.UpdateMutationSerializer):
|
|||
return r
|
||||
|
||||
|
||||
class DescriptionMutation(mutations.UpdateMutationSerializer):
|
||||
description = common_serializers.ContentSerializer()
|
||||
|
||||
def get_previous_state_handlers(self):
|
||||
handlers = super().get_previous_state_handlers()
|
||||
handlers["description"] = (
|
||||
lambda obj: common_serializers.ContentSerializer(obj.description).data
|
||||
if obj.description_id
|
||||
else None
|
||||
)
|
||||
return handlers
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
description = validated_data.pop("description", None)
|
||||
r = super().update(instance, validated_data)
|
||||
common_utils.attach_content(instance, "description", description)
|
||||
return r
|
||||
|
||||
|
||||
@mutations.registry.connect(
|
||||
"update",
|
||||
models.Track,
|
||||
perm_checkers={"suggest": can_suggest, "approve": can_approve},
|
||||
)
|
||||
class TrackMutationSerializer(TagMutation):
|
||||
class TrackMutationSerializer(TagMutation, DescriptionMutation):
|
||||
serialized_relations = {"license": "code"}
|
||||
|
||||
class Meta:
|
||||
model = models.Track
|
||||
fields = ["license", "title", "position", "copyright", "tags"]
|
||||
fields = ["license", "title", "position", "copyright", "tags", "description"]
|
||||
|
||||
def post_apply(self, obj, validated_data):
|
||||
routes.outbox.dispatch(
|
||||
|
@ -59,10 +82,10 @@ class TrackMutationSerializer(TagMutation):
|
|||
models.Artist,
|
||||
perm_checkers={"suggest": can_suggest, "approve": can_approve},
|
||||
)
|
||||
class ArtistMutationSerializer(TagMutation):
|
||||
class ArtistMutationSerializer(TagMutation, DescriptionMutation):
|
||||
class Meta:
|
||||
model = models.Artist
|
||||
fields = ["name", "tags"]
|
||||
fields = ["name", "tags", "description"]
|
||||
|
||||
def post_apply(self, obj, validated_data):
|
||||
routes.outbox.dispatch(
|
||||
|
@ -75,27 +98,23 @@ class ArtistMutationSerializer(TagMutation):
|
|||
models.Album,
|
||||
perm_checkers={"suggest": can_suggest, "approve": can_approve},
|
||||
)
|
||||
class AlbumMutationSerializer(TagMutation):
|
||||
class AlbumMutationSerializer(TagMutation, DescriptionMutation):
|
||||
cover = common_serializers.RelatedField(
|
||||
"uuid", queryset=common_models.Attachment.objects.all().local(), serializer=None
|
||||
)
|
||||
|
||||
serialized_relations = {"cover": "uuid"}
|
||||
previous_state_handlers = dict(
|
||||
list(TagMutation.previous_state_handlers.items())
|
||||
+ [
|
||||
(
|
||||
"cover",
|
||||
lambda obj: str(obj.attachment_cover.uuid)
|
||||
if obj.attachment_cover
|
||||
else None,
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = models.Album
|
||||
fields = ["title", "release_date", "tags", "cover"]
|
||||
fields = ["title", "release_date", "tags", "cover", "description"]
|
||||
|
||||
def get_previous_state_handlers(self):
|
||||
handlers = super().get_previous_state_handlers()
|
||||
handlers["cover"] = (
|
||||
lambda obj: str(obj.attachment_cover.uuid) if obj.attachment_cover else None
|
||||
)
|
||||
return handlers
|
||||
|
||||
def post_apply(self, obj, validated_data):
|
||||
routes.outbox.dispatch(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue