2018-05-28 22:07:20 +00:00
|
|
|
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,
|
|
|
|
):
|
2018-05-28 22:07:20 +00:00
|
|
|
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")
|
2018-05-28 22:07:20 +00:00
|
|
|
)
|
|
|
|
serializer_class = serializers.ManageTrackFileSerializer
|
|
|
|
filter_class = filters.ManageTrackFileFilterSet
|
|
|
|
permission_classes = (HasUserPermission,)
|
2018-06-09 13:36:16 +00:00
|
|
|
required_permissions = ["library"]
|
2018-05-28 22:07:20 +00:00
|
|
|
ordering_fields = [
|
2018-06-09 13:36:16 +00:00
|
|
|
"accessed_date",
|
|
|
|
"modification_date",
|
|
|
|
"creation_date",
|
|
|
|
"track__artist__name",
|
|
|
|
"bitrate",
|
|
|
|
"size",
|
|
|
|
"duration",
|
2018-05-28 22:07:20 +00:00
|
|
|
]
|
|
|
|
|
2018-06-09 13:36:16 +00:00
|
|
|
@list_route(methods=["post"])
|
2018-05-28 22:07:20 +00:00
|
|
|
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
|
2018-05-28 22:07:20 +00:00
|
|
|
)
|
|
|
|
serializer.is_valid(raise_exception=True)
|
|
|
|
result = serializer.save()
|
|
|
|
return response.Response(result, status=200)
|