Fix black linting
This commit is contained in:
parent
7b0cffba6a
commit
c0b2c8d41e
|
@ -15,7 +15,7 @@ class ActivityViewSet(viewsets.GenericViewSet):
|
||||||
permission_classes = [ConditionalAuthentication]
|
permission_classes = [ConditionalAuthentication]
|
||||||
queryset = TrackFavorite.objects.none()
|
queryset = TrackFavorite.objects.none()
|
||||||
|
|
||||||
@extend_schema(operation_id='get_activity')
|
@extend_schema(operation_id="get_activity")
|
||||||
def list(self, request, *args, **kwargs):
|
def list(self, request, *args, **kwargs):
|
||||||
activity = utils.get_activity(user=request.user)
|
activity = utils.get_activity(user=request.user)
|
||||||
serializer = self.serializer_class(activity, many=True)
|
serializer = self.serializer_class(activity, many=True)
|
||||||
|
|
|
@ -46,10 +46,10 @@ class ChannelsMixin(object):
|
||||||
|
|
||||||
|
|
||||||
@extend_schema_view(
|
@extend_schema_view(
|
||||||
metedata_choices=extend_schema(operation_id='get_channel_metadata_choices'),
|
metedata_choices=extend_schema(operation_id="get_channel_metadata_choices"),
|
||||||
subscribe=extend_schema(operation_id='subscribe_channel'),
|
subscribe=extend_schema(operation_id="subscribe_channel"),
|
||||||
unsubscribe=extend_schema(operation_id='unsubscribe_channel'),
|
unsubscribe=extend_schema(operation_id="unsubscribe_channel"),
|
||||||
rss_subscribe=extend_schema(operation_id='subscribe_channel_rss'),
|
rss_subscribe=extend_schema(operation_id="subscribe_channel_rss"),
|
||||||
)
|
)
|
||||||
class ChannelViewSet(
|
class ChannelViewSet(
|
||||||
ChannelsMixin,
|
ChannelsMixin,
|
||||||
|
@ -330,7 +330,7 @@ class SubscriptionsViewSet(
|
||||||
qs = super().get_queryset()
|
qs = super().get_queryset()
|
||||||
return qs.filter(actor=self.request.user.actor)
|
return qs.filter(actor=self.request.user.actor)
|
||||||
|
|
||||||
@extend_schema(operation_id='get_all_subscriptions')
|
@extend_schema(operation_id="get_all_subscriptions")
|
||||||
@decorators.action(methods=["get"], detail=False)
|
@decorators.action(methods=["get"], detail=False)
|
||||||
def all(self, request, *args, **kwargs):
|
def all(self, request, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -89,8 +89,12 @@ def mutations_route(types):
|
||||||
)
|
)
|
||||||
return response.Response(serializer.data, status=status.HTTP_201_CREATED)
|
return response.Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||||
|
|
||||||
return extend_schema(methods=['post'], responses=serializers.APIMutationSerializer())(
|
return extend_schema(
|
||||||
extend_schema(methods=['get'], responses=serializers.APIMutationSerializer(many=True))(
|
methods=["post"], responses=serializers.APIMutationSerializer()
|
||||||
|
)(
|
||||||
|
extend_schema(
|
||||||
|
methods=["get"], responses=serializers.APIMutationSerializer(many=True)
|
||||||
|
)(
|
||||||
decorators.action(
|
decorators.action(
|
||||||
methods=["get", "post"], detail=True, required_scope="edits"
|
methods=["get", "post"], detail=True, required_scope="edits"
|
||||||
)(mutations)
|
)(mutations)
|
||||||
|
|
|
@ -80,7 +80,7 @@ class MutationViewSet(
|
||||||
|
|
||||||
return super().perform_destroy(instance)
|
return super().perform_destroy(instance)
|
||||||
|
|
||||||
@extend_schema(operation_id='approve_mutation')
|
@extend_schema(operation_id="approve_mutation")
|
||||||
@action(detail=True, methods=["post"])
|
@action(detail=True, methods=["post"])
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def approve(self, request, *args, **kwargs):
|
def approve(self, request, *args, **kwargs):
|
||||||
|
@ -110,7 +110,7 @@ class MutationViewSet(
|
||||||
)
|
)
|
||||||
return response.Response({}, status=200)
|
return response.Response({}, status=200)
|
||||||
|
|
||||||
@extend_schema(operation_id='reject_mutation')
|
@extend_schema(operation_id="reject_mutation")
|
||||||
@action(detail=True, methods=["post"])
|
@action(detail=True, methods=["post"])
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def reject(self, request, *args, **kwargs):
|
def reject(self, request, *args, **kwargs):
|
||||||
|
@ -205,7 +205,7 @@ class AttachmentViewSet(
|
||||||
class TextPreviewView(views.APIView):
|
class TextPreviewView(views.APIView):
|
||||||
permission_classes = []
|
permission_classes = []
|
||||||
|
|
||||||
@extend_schema(operation_id='preview_text')
|
@extend_schema(operation_id="preview_text")
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
payload = request.data
|
payload = request.data
|
||||||
if "text" not in payload:
|
if "text" not in payload:
|
||||||
|
@ -278,7 +278,7 @@ class PluginViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
|
||||||
user.plugins.filter(code=kwargs["pk"]).delete()
|
user.plugins.filter(code=kwargs["pk"]).delete()
|
||||||
return response.Response(status=204)
|
return response.Response(status=204)
|
||||||
|
|
||||||
@extend_schema(operation_id='enable_plugin')
|
@extend_schema(operation_id="enable_plugin")
|
||||||
@action(detail=True, methods=["post"])
|
@action(detail=True, methods=["post"])
|
||||||
def enable(self, request, *args, **kwargs):
|
def enable(self, request, *args, **kwargs):
|
||||||
user = request.user
|
user = request.user
|
||||||
|
@ -287,7 +287,7 @@ class PluginViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
|
||||||
plugins.enable_conf(kwargs["pk"], True, user)
|
plugins.enable_conf(kwargs["pk"], True, user)
|
||||||
return response.Response({}, status=200)
|
return response.Response({}, status=200)
|
||||||
|
|
||||||
@extend_schema(operation_id='disable_plugin')
|
@extend_schema(operation_id="disable_plugin")
|
||||||
@action(detail=True, methods=["post"])
|
@action(detail=True, methods=["post"])
|
||||||
def disable(self, request, *args, **kwargs):
|
def disable(self, request, *args, **kwargs):
|
||||||
user = request.user
|
user = request.user
|
||||||
|
|
|
@ -40,7 +40,7 @@ class TrackFavoriteViewSet(
|
||||||
return serializers.UserTrackFavoriteSerializer
|
return serializers.UserTrackFavoriteSerializer
|
||||||
return serializers.UserTrackFavoriteWriteSerializer
|
return serializers.UserTrackFavoriteWriteSerializer
|
||||||
|
|
||||||
@extend_schema(operation_id='favorite_track')
|
@extend_schema(operation_id="favorite_track")
|
||||||
def create(self, request, *args, **kwargs):
|
def create(self, request, *args, **kwargs):
|
||||||
serializer = self.get_serializer(data=request.data)
|
serializer = self.get_serializer(data=request.data)
|
||||||
serializer.is_valid(raise_exception=True)
|
serializer.is_valid(raise_exception=True)
|
||||||
|
@ -70,7 +70,7 @@ class TrackFavoriteViewSet(
|
||||||
favorite = models.TrackFavorite.add(track=track, user=self.request.user)
|
favorite = models.TrackFavorite.add(track=track, user=self.request.user)
|
||||||
return favorite
|
return favorite
|
||||||
|
|
||||||
@extend_schema(operation_id='unfavorite_track')
|
@extend_schema(operation_id="unfavorite_track")
|
||||||
@action(methods=["delete", "post"], detail=False)
|
@action(methods=["delete", "post"], detail=False)
|
||||||
def remove(self, request, *args, **kwargs):
|
def remove(self, request, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
|
@ -81,7 +81,7 @@ class TrackFavoriteViewSet(
|
||||||
favorite.delete()
|
favorite.delete()
|
||||||
return Response([], status=status.HTTP_204_NO_CONTENT)
|
return Response([], status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
@extend_schema(operation_id='get_all_favorite_tracks')
|
@extend_schema(operation_id="get_all_favorite_tracks")
|
||||||
@action(methods=["get"], detail=False)
|
@action(methods=["get"], detail=False)
|
||||||
def all(self, request, *args, **kwargs):
|
def all(self, request, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -41,12 +41,12 @@ def update_follow(follow, approved):
|
||||||
|
|
||||||
|
|
||||||
@extend_schema_view(
|
@extend_schema_view(
|
||||||
list=extend_schema(operation_id='get_federation_library_follows'),
|
list=extend_schema(operation_id="get_federation_library_follows"),
|
||||||
create=extend_schema(operation_id='create_federation_library_follow'),
|
create=extend_schema(operation_id="create_federation_library_follow"),
|
||||||
)
|
)
|
||||||
# NOTE: For some weird reason, @extend_schema_view doesn't work with `retrieve` and `destroy` methods.
|
# NOTE: For some weird reason, @extend_schema_view doesn't work with `retrieve` and `destroy` methods.
|
||||||
@extend_schema(operation_id='get_federation_library_follow', methods=['get'])
|
@extend_schema(operation_id="get_federation_library_follow", methods=["get"])
|
||||||
@extend_schema(operation_id='delete_federation_library_follow', methods=['delete'])
|
@extend_schema(operation_id="delete_federation_library_follow", methods=["delete"])
|
||||||
class LibraryFollowViewSet(
|
class LibraryFollowViewSet(
|
||||||
mixins.CreateModelMixin,
|
mixins.CreateModelMixin,
|
||||||
mixins.ListModelMixin,
|
mixins.ListModelMixin,
|
||||||
|
@ -86,7 +86,7 @@ class LibraryFollowViewSet(
|
||||||
context["actor"] = self.request.user.actor
|
context["actor"] = self.request.user.actor
|
||||||
return context
|
return context
|
||||||
|
|
||||||
@extend_schema(operation_id='accept_federation_library_follow')
|
@extend_schema(operation_id="accept_federation_library_follow")
|
||||||
@decorators.action(methods=["post"], detail=True)
|
@decorators.action(methods=["post"], detail=True)
|
||||||
def accept(self, request, *args, **kwargs):
|
def accept(self, request, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
|
@ -98,7 +98,7 @@ class LibraryFollowViewSet(
|
||||||
update_follow(follow, approved=True)
|
update_follow(follow, approved=True)
|
||||||
return response.Response(status=204)
|
return response.Response(status=204)
|
||||||
|
|
||||||
@extend_schema(operation_id='reject_federation_library_follow')
|
@extend_schema(operation_id="reject_federation_library_follow")
|
||||||
@decorators.action(methods=["post"], detail=True)
|
@decorators.action(methods=["post"], detail=True)
|
||||||
def reject(self, request, *args, **kwargs):
|
def reject(self, request, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
|
@ -111,7 +111,7 @@ class LibraryFollowViewSet(
|
||||||
update_follow(follow, approved=False)
|
update_follow(follow, approved=False)
|
||||||
return response.Response(status=204)
|
return response.Response(status=204)
|
||||||
|
|
||||||
@extend_schema(operation_id='get_all_federation_library_follows')
|
@extend_schema(operation_id="get_all_federation_library_follows")
|
||||||
@decorators.action(methods=["get"], detail=False)
|
@decorators.action(methods=["get"], detail=False)
|
||||||
def all(self, request, *args, **kwargs):
|
def all(self, request, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -44,8 +44,10 @@ def fetches_route():
|
||||||
serializer = api_serializers.FetchSerializer(fetch)
|
serializer = api_serializers.FetchSerializer(fetch)
|
||||||
return response.Response(serializer.data, status=status.HTTP_201_CREATED)
|
return response.Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||||
|
|
||||||
return extend_schema(methods=['post'], responses=api_serializers.FetchSerializer())(
|
return extend_schema(methods=["post"], responses=api_serializers.FetchSerializer())(
|
||||||
extend_schema(methods=['get'], responses=api_serializers.FetchSerializer(many=True))(
|
extend_schema(
|
||||||
|
methods=["get"], responses=api_serializers.FetchSerializer(many=True)
|
||||||
|
)(
|
||||||
decorators.action(
|
decorators.action(
|
||||||
methods=["get", "post"],
|
methods=["get", "post"],
|
||||||
detail=True,
|
detail=True,
|
||||||
|
|
|
@ -53,7 +53,7 @@ class InstanceSettings(generics.GenericAPIView):
|
||||||
]
|
]
|
||||||
return api_preferences
|
return api_preferences
|
||||||
|
|
||||||
@extend_schema(operation_id='get_instance_settings')
|
@extend_schema(operation_id="get_instance_settings")
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
queryset = self.get_queryset()
|
queryset = self.get_queryset()
|
||||||
data = GlobalPreferenceSerializer(queryset, many=True).data
|
data = GlobalPreferenceSerializer(queryset, many=True).data
|
||||||
|
@ -122,7 +122,7 @@ class SpaManifest(views.APIView):
|
||||||
permission_classes = []
|
permission_classes = []
|
||||||
authentication_classes = []
|
authentication_classes = []
|
||||||
|
|
||||||
@extend_schema(operation_id='get_spa_manifest')
|
@extend_schema(operation_id="get_spa_manifest")
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
existing_manifest = middleware.get_spa_file(
|
existing_manifest = middleware.get_spa_file(
|
||||||
settings.FUNKWHALE_SPA_HTML_ROOT, "manifest.json"
|
settings.FUNKWHALE_SPA_HTML_ROOT, "manifest.json"
|
||||||
|
|
|
@ -95,7 +95,7 @@ class ManageArtistViewSet(
|
||||||
required_scope = "instance:libraries"
|
required_scope = "instance:libraries"
|
||||||
ordering_fields = ["creation_date", "name"]
|
ordering_fields = ["creation_date", "name"]
|
||||||
|
|
||||||
@extend_schema(operation_id='admin_get_library_artist_stats')
|
@extend_schema(operation_id="admin_get_library_artist_stats")
|
||||||
@rest_decorators.action(methods=["get"], detail=True)
|
@rest_decorators.action(methods=["get"], detail=True)
|
||||||
def stats(self, request, *args, **kwargs):
|
def stats(self, request, *args, **kwargs):
|
||||||
artist = self.get_object()
|
artist = self.get_object()
|
||||||
|
@ -138,7 +138,7 @@ class ManageAlbumViewSet(
|
||||||
required_scope = "instance:libraries"
|
required_scope = "instance:libraries"
|
||||||
ordering_fields = ["creation_date", "title", "release_date"]
|
ordering_fields = ["creation_date", "title", "release_date"]
|
||||||
|
|
||||||
@extend_schema(operation_id='admin_get_library_album_stats')
|
@extend_schema(operation_id="admin_get_library_album_stats")
|
||||||
@rest_decorators.action(methods=["get"], detail=True)
|
@rest_decorators.action(methods=["get"], detail=True)
|
||||||
def stats(self, request, *args, **kwargs):
|
def stats(self, request, *args, **kwargs):
|
||||||
album = self.get_object()
|
album = self.get_object()
|
||||||
|
@ -200,7 +200,7 @@ class ManageTrackViewSet(
|
||||||
"disc_number",
|
"disc_number",
|
||||||
]
|
]
|
||||||
|
|
||||||
@extend_schema(operation_id='admin_get_track_stats')
|
@extend_schema(operation_id="admin_get_track_stats")
|
||||||
@rest_decorators.action(methods=["get"], detail=True)
|
@rest_decorators.action(methods=["get"], detail=True)
|
||||||
def stats(self, request, *args, **kwargs):
|
def stats(self, request, *args, **kwargs):
|
||||||
track = self.get_object()
|
track = self.get_object()
|
||||||
|
@ -262,7 +262,7 @@ class ManageLibraryViewSet(
|
||||||
filterset_class = filters.ManageLibraryFilterSet
|
filterset_class = filters.ManageLibraryFilterSet
|
||||||
required_scope = "instance:libraries"
|
required_scope = "instance:libraries"
|
||||||
|
|
||||||
@extend_schema(operation_id='admin_get_library_stats')
|
@extend_schema(operation_id="admin_get_library_stats")
|
||||||
@rest_decorators.action(methods=["get"], detail=True)
|
@rest_decorators.action(methods=["get"], detail=True)
|
||||||
def stats(self, request, *args, **kwargs):
|
def stats(self, request, *args, **kwargs):
|
||||||
library = self.get_object()
|
library = self.get_object()
|
||||||
|
@ -430,7 +430,7 @@ class ManageDomainViewSet(
|
||||||
domain.refresh_from_db()
|
domain.refresh_from_db()
|
||||||
return response.Response(domain.nodeinfo, status=200)
|
return response.Response(domain.nodeinfo, status=200)
|
||||||
|
|
||||||
@extend_schema(operation_id='admin_get_federation_domain_stats')
|
@extend_schema(operation_id="admin_get_federation_domain_stats")
|
||||||
@rest_decorators.action(methods=["get"], detail=True)
|
@rest_decorators.action(methods=["get"], detail=True)
|
||||||
def stats(self, request, *args, **kwargs):
|
def stats(self, request, *args, **kwargs):
|
||||||
domain = self.get_object()
|
domain = self.get_object()
|
||||||
|
@ -475,7 +475,7 @@ class ManageActorViewSet(
|
||||||
|
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
@extend_schema(operation_id='admin_get_account_stats')
|
@extend_schema(operation_id="admin_get_account_stats")
|
||||||
@rest_decorators.action(methods=["get"], detail=True)
|
@rest_decorators.action(methods=["get"], detail=True)
|
||||||
def stats(self, request, *args, **kwargs):
|
def stats(self, request, *args, **kwargs):
|
||||||
obj = self.get_object()
|
obj = self.get_object()
|
||||||
|
@ -717,7 +717,7 @@ class ManageChannelViewSet(
|
||||||
required_scope = "instance:libraries"
|
required_scope = "instance:libraries"
|
||||||
ordering_fields = ["creation_date", "name"]
|
ordering_fields = ["creation_date", "name"]
|
||||||
|
|
||||||
@extend_schema(operation_id='admin_get_channel_stats')
|
@extend_schema(operation_id="admin_get_channel_stats")
|
||||||
@rest_decorators.action(methods=["get"], detail=True)
|
@rest_decorators.action(methods=["get"], detail=True)
|
||||||
def stats(self, request, *args, **kwargs):
|
def stats(self, request, *args, **kwargs):
|
||||||
channel = self.get_object()
|
channel = self.get_object()
|
||||||
|
|
|
@ -68,9 +68,9 @@ def get_libraries(filter_uploads):
|
||||||
serializer = federation_api_serializers.LibrarySerializer(qs, many=True)
|
serializer = federation_api_serializers.LibrarySerializer(qs, many=True)
|
||||||
return Response(serializer.data)
|
return Response(serializer.data)
|
||||||
|
|
||||||
return extend_schema(responses=federation_api_serializers.LibrarySerializer(many=True))(
|
return extend_schema(
|
||||||
action(methods=["get"], detail=True)(libraries)
|
responses=federation_api_serializers.LibrarySerializer(many=True)
|
||||||
)
|
)(action(methods=["get"], detail=True)(libraries))
|
||||||
|
|
||||||
|
|
||||||
def refetch_obj(obj, queryset):
|
def refetch_obj(obj, queryset):
|
||||||
|
@ -171,9 +171,11 @@ class ArtistViewSet(
|
||||||
Prefetch("albums", queryset=albums), TAG_PREFETCH
|
Prefetch("albums", queryset=albums), TAG_PREFETCH
|
||||||
)
|
)
|
||||||
|
|
||||||
libraries = get_libraries(lambda o, uploads: uploads.filter(
|
libraries = get_libraries(
|
||||||
|
lambda o, uploads: uploads.filter(
|
||||||
Q(track__artist=o) | Q(track__album__artist=o)
|
Q(track__artist=o) | Q(track__album__artist=o)
|
||||||
))
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class AlbumViewSet(
|
class AlbumViewSet(
|
||||||
|
@ -740,7 +742,7 @@ class UploadViewSet(
|
||||||
qs = qs.playable_by(actor)
|
qs = qs.playable_by(actor)
|
||||||
return qs
|
return qs
|
||||||
|
|
||||||
@extend_schema(operation_id='get_upload_metadata')
|
@extend_schema(operation_id="get_upload_metadata")
|
||||||
@action(methods=["get"], detail=True, url_path="audio-file-metadata")
|
@action(methods=["get"], detail=True, url_path="audio-file-metadata")
|
||||||
def audio_file_metadata(self, request, *args, **kwargs):
|
def audio_file_metadata(self, request, *args, **kwargs):
|
||||||
upload = self.get_object()
|
upload = self.get_object()
|
||||||
|
@ -799,7 +801,7 @@ class Search(views.APIView):
|
||||||
required_scope = "libraries"
|
required_scope = "libraries"
|
||||||
anonymous_policy = "setting"
|
anonymous_policy = "setting"
|
||||||
|
|
||||||
@extend_schema(operation_id='get_search_results')
|
@extend_schema(operation_id="get_search_results")
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
query = request.GET.get("query", request.GET.get("q", "")) or ""
|
query = request.GET.get("query", request.GET.get("q", "")) or ""
|
||||||
query = query.strip()
|
query = query.strip()
|
||||||
|
|
|
@ -52,7 +52,9 @@ class PlaylistViewSet(
|
||||||
data = {"count": len(plts), "results": serializer.data}
|
data = {"count": len(plts), "results": serializer.data}
|
||||||
return Response(data, status=200)
|
return Response(data, status=200)
|
||||||
|
|
||||||
@extend_schema(operation_id="add_to_playlist", request=serializers.PlaylistAddManySerializer)
|
@extend_schema(
|
||||||
|
operation_id="add_to_playlist", request=serializers.PlaylistAddManySerializer
|
||||||
|
)
|
||||||
@action(methods=["post"], detail=True)
|
@action(methods=["post"], detail=True)
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def add(self, request, *args, **kwargs):
|
def add(self, request, *args, **kwargs):
|
||||||
|
|
|
@ -66,7 +66,7 @@ class RadioViewSet(
|
||||||
)
|
)
|
||||||
return Response(serializer.data)
|
return Response(serializer.data)
|
||||||
|
|
||||||
@extend_schema(operation_id='validate_radio')
|
@extend_schema(operation_id="validate_radio")
|
||||||
@action(methods=["post"], detail=False)
|
@action(methods=["post"], detail=False)
|
||||||
def validate(self, request, *args, **kwargs):
|
def validate(self, request, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
|
@ -128,7 +128,7 @@ class RadioSessionTrackViewSet(mixins.CreateModelMixin, viewsets.GenericViewSet)
|
||||||
queryset = models.RadioSessionTrack.objects.all()
|
queryset = models.RadioSessionTrack.objects.all()
|
||||||
permission_classes = []
|
permission_classes = []
|
||||||
|
|
||||||
@extend_schema(operation_id='get_next_radio_track')
|
@extend_schema(operation_id="get_next_radio_track")
|
||||||
def create(self, request, *args, **kwargs):
|
def create(self, request, *args, **kwargs):
|
||||||
serializer = self.get_serializer(data=request.data)
|
serializer = self.get_serializer(data=request.data)
|
||||||
serializer.is_valid(raise_exception=True)
|
serializer.is_valid(raise_exception=True)
|
||||||
|
|
|
@ -7,16 +7,15 @@ import re
|
||||||
|
|
||||||
class CustomAutoSchema(AutoSchema):
|
class CustomAutoSchema(AutoSchema):
|
||||||
method_mapping = {
|
method_mapping = {
|
||||||
'get': 'get',
|
"get": "get",
|
||||||
'post': 'create',
|
"post": "create",
|
||||||
'put': 'update',
|
"put": "update",
|
||||||
'patch': 'partial_update',
|
"patch": "partial_update",
|
||||||
'delete': 'delete',
|
"delete": "delete",
|
||||||
}
|
}
|
||||||
|
|
||||||
pluralizer = Pluralizer()
|
pluralizer = Pluralizer()
|
||||||
|
|
||||||
|
|
||||||
def get_operation_id(self):
|
def get_operation_id(self):
|
||||||
# Modified operation id getter from
|
# Modified operation id getter from
|
||||||
# https://github.com/tfranzel/drf-spectacular/blob/6973aa48f4ff08f7f33799d50c288fcc79ea8076/drf_spectacular/openapi.py#L424-L441
|
# https://github.com/tfranzel/drf-spectacular/blob/6973aa48f4ff08f7f33799d50c288fcc79ea8076/drf_spectacular/openapi.py#L424-L441
|
||||||
|
@ -24,46 +23,50 @@ class CustomAutoSchema(AutoSchema):
|
||||||
tokenized_path = self._tokenize_path()
|
tokenized_path = self._tokenize_path()
|
||||||
|
|
||||||
# replace dashes as they can be problematic later in code generation
|
# replace dashes as they can be problematic later in code generation
|
||||||
tokenized_path = [t.replace('-', '_') for t in tokenized_path]
|
tokenized_path = [t.replace("-", "_") for t in tokenized_path]
|
||||||
|
|
||||||
# replace plural forms with singular forms
|
# replace plural forms with singular forms
|
||||||
tokenized_path = [self.pluralizer.singular(t) for t in tokenized_path]
|
tokenized_path = [self.pluralizer.singular(t) for t in tokenized_path]
|
||||||
|
|
||||||
if not tokenized_path:
|
if not tokenized_path:
|
||||||
tokenized_path.append('root')
|
tokenized_path.append("root")
|
||||||
|
|
||||||
model = tokenized_path.pop()
|
model = tokenized_path.pop()
|
||||||
|
|
||||||
if self.method == 'GET' and self._is_list_view():
|
if self.method == "GET" and self._is_list_view():
|
||||||
action = 'get'
|
action = "get"
|
||||||
model = self.pluralizer.plural(model)
|
model = self.pluralizer.plural(model)
|
||||||
else:
|
else:
|
||||||
action = self.method_mapping[self.method.lower()]
|
action = self.method_mapping[self.method.lower()]
|
||||||
|
|
||||||
if re.search(r'<drf_format_suffix\w*:\w+>', self.path_regex):
|
if re.search(r"<drf_format_suffix\w*:\w+>", self.path_regex):
|
||||||
tokenized_path.append('formatted')
|
tokenized_path.append("formatted")
|
||||||
|
|
||||||
# rename `get_radio_radio_track` to `get_radio_track`
|
# rename `get_radio_radio_track` to `get_radio_track`
|
||||||
if len(tokenized_path) > 1 and tokenized_path[1] == 'radio' and tokenized_path[1] == 'radio':
|
if (
|
||||||
|
len(tokenized_path) > 1
|
||||||
|
and tokenized_path[1] == "radio"
|
||||||
|
and tokenized_path[1] == "radio"
|
||||||
|
):
|
||||||
tokenized_path.pop(0)
|
tokenized_path.pop(0)
|
||||||
|
|
||||||
# rename `get_manage_channel` to `admin_get_channel`
|
# rename `get_manage_channel` to `admin_get_channel`
|
||||||
elif len(tokenized_path) > 0 and tokenized_path[0] == 'manage':
|
elif len(tokenized_path) > 0 and tokenized_path[0] == "manage":
|
||||||
tokenized_path.pop(0)
|
tokenized_path.pop(0)
|
||||||
|
|
||||||
# rename `get_manage_library_album` to `admin_get_album`
|
# rename `get_manage_library_album` to `admin_get_album`
|
||||||
if len(tokenized_path) > 0 and tokenized_path[0] == 'library':
|
if len(tokenized_path) > 0 and tokenized_path[0] == "library":
|
||||||
tokenized_path.pop(0)
|
tokenized_path.pop(0)
|
||||||
|
|
||||||
# rename `get_manage_user_users` to `admin_get_users`
|
# rename `get_manage_user_users` to `admin_get_users`
|
||||||
elif len(tokenized_path) > 0 and tokenized_path[0] == 'user':
|
elif len(tokenized_path) > 0 and tokenized_path[0] == "user":
|
||||||
tokenized_path.pop(0)
|
tokenized_path.pop(0)
|
||||||
|
|
||||||
# rename `get_manage_moderation_note` to `moderation_get_note`
|
# rename `get_manage_moderation_note` to `moderation_get_note`
|
||||||
elif len(tokenized_path) > 0 and tokenized_path[0] == 'moderation':
|
elif len(tokenized_path) > 0 and tokenized_path[0] == "moderation":
|
||||||
tokenized_path.pop(0)
|
tokenized_path.pop(0)
|
||||||
return '_'.join(['moderation', action] + tokenized_path + [model])
|
return "_".join(["moderation", action] + tokenized_path + [model])
|
||||||
|
|
||||||
return '_'.join(['admin', action] + tokenized_path + [model])
|
return "_".join(["admin", action] + tokenized_path + [model])
|
||||||
|
|
||||||
return '_'.join([action] + tokenized_path + [model])
|
return "_".join([action] + tokenized_path + [model])
|
||||||
|
|
|
@ -86,7 +86,7 @@ class ApplicationViewSet(
|
||||||
qs = qs.filter(user=self.request.user)
|
qs = qs.filter(user=self.request.user)
|
||||||
return qs
|
return qs
|
||||||
|
|
||||||
@extend_schema(operation_id='refresh_oauth_token')
|
@extend_schema(operation_id="refresh_oauth_token")
|
||||||
@action(
|
@action(
|
||||||
detail=True,
|
detail=True,
|
||||||
methods=["post"],
|
methods=["post"],
|
||||||
|
|
|
@ -21,7 +21,7 @@ from funkwhale_api.common import throttling
|
||||||
from . import models, serializers, tasks
|
from . import models, serializers, tasks
|
||||||
|
|
||||||
|
|
||||||
@extend_schema(operation_id='register', methods=['post'])
|
@extend_schema(operation_id="register", methods=["post"])
|
||||||
class RegisterView(registration_views.RegisterView):
|
class RegisterView(registration_views.RegisterView):
|
||||||
serializer_class = serializers.RegisterSerializer
|
serializer_class = serializers.RegisterSerializer
|
||||||
permission_classes = []
|
permission_classes = []
|
||||||
|
@ -46,22 +46,22 @@ class RegisterView(registration_views.RegisterView):
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
||||||
@extend_schema(operation_id='verify_email')
|
@extend_schema(operation_id="verify_email")
|
||||||
class VerifyEmailView(registration_views.VerifyEmailView):
|
class VerifyEmailView(registration_views.VerifyEmailView):
|
||||||
action = "verify-email"
|
action = "verify-email"
|
||||||
|
|
||||||
|
|
||||||
@extend_schema(operation_id='change_password')
|
@extend_schema(operation_id="change_password")
|
||||||
class PasswordChangeView(rest_auth_views.PasswordChangeView):
|
class PasswordChangeView(rest_auth_views.PasswordChangeView):
|
||||||
action = "password-change"
|
action = "password-change"
|
||||||
|
|
||||||
|
|
||||||
@extend_schema(operation_id='reset_password')
|
@extend_schema(operation_id="reset_password")
|
||||||
class PasswordResetView(rest_auth_views.PasswordResetView):
|
class PasswordResetView(rest_auth_views.PasswordResetView):
|
||||||
action = "password-reset"
|
action = "password-reset"
|
||||||
|
|
||||||
|
|
||||||
@extend_schema(operation_id='confirm_password_reset')
|
@extend_schema(operation_id="confirm_password_reset")
|
||||||
class PasswordResetConfirmView(rest_auth_views.PasswordResetConfirmView):
|
class PasswordResetConfirmView(rest_auth_views.PasswordResetConfirmView):
|
||||||
action = "password-reset-confirm"
|
action = "password-reset-confirm"
|
||||||
|
|
||||||
|
@ -73,8 +73,8 @@ class UserViewSet(mixins.UpdateModelMixin, viewsets.GenericViewSet):
|
||||||
lookup_value_regex = r"[a-zA-Z0-9-_.]+"
|
lookup_value_regex = r"[a-zA-Z0-9-_.]+"
|
||||||
required_scope = "profile"
|
required_scope = "profile"
|
||||||
|
|
||||||
@extend_schema(operation_id='get_authenticated_user', methods=['get'])
|
@extend_schema(operation_id="get_authenticated_user", methods=["get"])
|
||||||
@extend_schema(operation_id='delete_authenticated_user', methods=['delete'])
|
@extend_schema(operation_id="delete_authenticated_user", methods=["delete"])
|
||||||
@action(methods=["get", "delete"], detail=False)
|
@action(methods=["get", "delete"], detail=False)
|
||||||
def me(self, request, *args, **kwargs):
|
def me(self, request, *args, **kwargs):
|
||||||
"""Return information about the current user or delete it"""
|
"""Return information about the current user or delete it"""
|
||||||
|
@ -89,7 +89,7 @@ class UserViewSet(mixins.UpdateModelMixin, viewsets.GenericViewSet):
|
||||||
serializer = serializers.MeSerializer(request.user)
|
serializer = serializers.MeSerializer(request.user)
|
||||||
return Response(serializer.data)
|
return Response(serializer.data)
|
||||||
|
|
||||||
@extend_schema(operation_id='update_settings')
|
@extend_schema(operation_id="update_settings")
|
||||||
@action(methods=["post"], detail=False, url_name="settings", url_path="settings")
|
@action(methods=["post"], detail=False, url_name="settings", url_path="settings")
|
||||||
def set_settings(self, request, *args, **kwargs):
|
def set_settings(self, request, *args, **kwargs):
|
||||||
"""Return information about the current user or delete it"""
|
"""Return information about the current user or delete it"""
|
||||||
|
@ -121,7 +121,7 @@ class UserViewSet(mixins.UpdateModelMixin, viewsets.GenericViewSet):
|
||||||
data = {"subsonic_api_token": self.request.user.subsonic_api_token}
|
data = {"subsonic_api_token": self.request.user.subsonic_api_token}
|
||||||
return Response(data)
|
return Response(data)
|
||||||
|
|
||||||
@extend_schema(operation_id='change_email')
|
@extend_schema(operation_id="change_email")
|
||||||
@action(
|
@action(
|
||||||
methods=["post"],
|
methods=["post"],
|
||||||
required_scope="security",
|
required_scope="security",
|
||||||
|
@ -149,8 +149,8 @@ class UserViewSet(mixins.UpdateModelMixin, viewsets.GenericViewSet):
|
||||||
return super().partial_update(request, *args, **kwargs)
|
return super().partial_update(request, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
@extend_schema(operation_id='login')
|
@extend_schema(operation_id="login")
|
||||||
@action(methods=['post'], detail=False)
|
@action(methods=["post"], detail=False)
|
||||||
def login(request):
|
def login(request):
|
||||||
throttling.check_request(request, "login")
|
throttling.check_request(request, "login")
|
||||||
if request.method != "POST":
|
if request.method != "POST":
|
||||||
|
@ -170,8 +170,8 @@ def login(request):
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
@extend_schema(operation_id='logout')
|
@extend_schema(operation_id="logout")
|
||||||
@action(methods=['post'], detail=False)
|
@action(methods=["post"], detail=False)
|
||||||
def logout(request):
|
def logout(request):
|
||||||
if request.method != "POST":
|
if request.method != "POST":
|
||||||
return http.HttpResponse(status=405)
|
return http.HttpResponse(status=405)
|
||||||
|
|
Loading…
Reference in New Issue