funkwhale/api/funkwhale_api/manage/views.py

47 wiersze
1.4 KiB
Python
Czysty Zwykły widok Historia

from rest_framework import mixins
from rest_framework import response
from rest_framework import viewsets
from rest_framework.decorators import list_route
from funkwhale_api.music import models as music_models
from funkwhale_api.users.permissions import HasUserPermission
from . import filters
from . import serializers
class ManageTrackFileViewSet(
2018-06-09 13:36:16 +00:00
mixins.ListModelMixin,
mixins.RetrieveModelMixin,
mixins.DestroyModelMixin,
viewsets.GenericViewSet,
):
queryset = (
music_models.TrackFile.objects.all()
2018-06-09 13:36:16 +00:00
.select_related("track__artist", "track__album__artist", "library_track")
.order_by("-id")
)
serializer_class = serializers.ManageTrackFileSerializer
filter_class = filters.ManageTrackFileFilterSet
permission_classes = (HasUserPermission,)
2018-06-09 13:36:16 +00:00
required_permissions = ["library"]
ordering_fields = [
2018-06-09 13:36:16 +00:00
"accessed_date",
"modification_date",
"creation_date",
"track__artist__name",
"bitrate",
"size",
"duration",
]
2018-06-09 13:36:16 +00:00
@list_route(methods=["post"])
def action(self, request, *args, **kwargs):
queryset = self.get_queryset()
serializer = serializers.ManageTrackFileActionSerializer(
2018-06-09 13:36:16 +00:00
request.data, queryset=queryset
)
serializer.is_valid(raise_exception=True)
result = serializer.save()
return response.Response(result, status=200)