From c0b2c8d41ea9046a967330ff90bb2b3c4ff4fe24 Mon Sep 17 00:00:00 2001 From: wvffle Date: Sun, 25 Sep 2022 15:02:21 +0000 Subject: [PATCH] Fix black linting --- api/funkwhale_api/activity/views.py | 2 +- api/funkwhale_api/audio/views.py | 10 ++--- api/funkwhale_api/common/decorators.py | 8 +++- api/funkwhale_api/common/views.py | 10 ++--- api/funkwhale_api/favorites/views.py | 6 +-- api/funkwhale_api/federation/api_views.py | 14 +++---- api/funkwhale_api/federation/decorators.py | 6 ++- api/funkwhale_api/instance/views.py | 4 +- api/funkwhale_api/manage/views.py | 14 +++---- api/funkwhale_api/music/views.py | 18 +++++---- api/funkwhale_api/playlists/views.py | 4 +- api/funkwhale_api/radios/views.py | 4 +- api/funkwhale_api/schema.py | 43 ++++++++++++---------- api/funkwhale_api/users/oauth/views.py | 2 +- api/funkwhale_api/users/views.py | 26 ++++++------- 15 files changed, 92 insertions(+), 79 deletions(-) diff --git a/api/funkwhale_api/activity/views.py b/api/funkwhale_api/activity/views.py index d75a94cb9..15524c8f1 100644 --- a/api/funkwhale_api/activity/views.py +++ b/api/funkwhale_api/activity/views.py @@ -15,7 +15,7 @@ class ActivityViewSet(viewsets.GenericViewSet): permission_classes = [ConditionalAuthentication] queryset = TrackFavorite.objects.none() - @extend_schema(operation_id='get_activity') + @extend_schema(operation_id="get_activity") def list(self, request, *args, **kwargs): activity = utils.get_activity(user=request.user) serializer = self.serializer_class(activity, many=True) diff --git a/api/funkwhale_api/audio/views.py b/api/funkwhale_api/audio/views.py index 83c34c648..8989ed9b3 100644 --- a/api/funkwhale_api/audio/views.py +++ b/api/funkwhale_api/audio/views.py @@ -46,10 +46,10 @@ class ChannelsMixin(object): @extend_schema_view( - metedata_choices=extend_schema(operation_id='get_channel_metadata_choices'), - subscribe=extend_schema(operation_id='subscribe_channel'), - unsubscribe=extend_schema(operation_id='unsubscribe_channel'), - rss_subscribe=extend_schema(operation_id='subscribe_channel_rss'), + metedata_choices=extend_schema(operation_id="get_channel_metadata_choices"), + subscribe=extend_schema(operation_id="subscribe_channel"), + unsubscribe=extend_schema(operation_id="unsubscribe_channel"), + rss_subscribe=extend_schema(operation_id="subscribe_channel_rss"), ) class ChannelViewSet( ChannelsMixin, @@ -330,7 +330,7 @@ class SubscriptionsViewSet( qs = super().get_queryset() 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) def all(self, request, *args, **kwargs): """ diff --git a/api/funkwhale_api/common/decorators.py b/api/funkwhale_api/common/decorators.py index f30587a98..b2a298d3f 100644 --- a/api/funkwhale_api/common/decorators.py +++ b/api/funkwhale_api/common/decorators.py @@ -89,8 +89,12 @@ def mutations_route(types): ) return response.Response(serializer.data, status=status.HTTP_201_CREATED) - return extend_schema(methods=['post'], responses=serializers.APIMutationSerializer())( - extend_schema(methods=['get'], responses=serializers.APIMutationSerializer(many=True))( + return extend_schema( + methods=["post"], responses=serializers.APIMutationSerializer() + )( + extend_schema( + methods=["get"], responses=serializers.APIMutationSerializer(many=True) + )( decorators.action( methods=["get", "post"], detail=True, required_scope="edits" )(mutations) diff --git a/api/funkwhale_api/common/views.py b/api/funkwhale_api/common/views.py index f122b8b32..a19927599 100644 --- a/api/funkwhale_api/common/views.py +++ b/api/funkwhale_api/common/views.py @@ -80,7 +80,7 @@ class MutationViewSet( return super().perform_destroy(instance) - @extend_schema(operation_id='approve_mutation') + @extend_schema(operation_id="approve_mutation") @action(detail=True, methods=["post"]) @transaction.atomic def approve(self, request, *args, **kwargs): @@ -110,7 +110,7 @@ class MutationViewSet( ) return response.Response({}, status=200) - @extend_schema(operation_id='reject_mutation') + @extend_schema(operation_id="reject_mutation") @action(detail=True, methods=["post"]) @transaction.atomic def reject(self, request, *args, **kwargs): @@ -205,7 +205,7 @@ class AttachmentViewSet( class TextPreviewView(views.APIView): permission_classes = [] - @extend_schema(operation_id='preview_text') + @extend_schema(operation_id="preview_text") def post(self, request, *args, **kwargs): payload = request.data if "text" not in payload: @@ -278,7 +278,7 @@ class PluginViewSet(mixins.ListModelMixin, viewsets.GenericViewSet): user.plugins.filter(code=kwargs["pk"]).delete() return response.Response(status=204) - @extend_schema(operation_id='enable_plugin') + @extend_schema(operation_id="enable_plugin") @action(detail=True, methods=["post"]) def enable(self, request, *args, **kwargs): user = request.user @@ -287,7 +287,7 @@ class PluginViewSet(mixins.ListModelMixin, viewsets.GenericViewSet): plugins.enable_conf(kwargs["pk"], True, user) return response.Response({}, status=200) - @extend_schema(operation_id='disable_plugin') + @extend_schema(operation_id="disable_plugin") @action(detail=True, methods=["post"]) def disable(self, request, *args, **kwargs): user = request.user diff --git a/api/funkwhale_api/favorites/views.py b/api/funkwhale_api/favorites/views.py index 5926ca52d..f8a6d7cd1 100644 --- a/api/funkwhale_api/favorites/views.py +++ b/api/funkwhale_api/favorites/views.py @@ -40,7 +40,7 @@ class TrackFavoriteViewSet( return serializers.UserTrackFavoriteSerializer return serializers.UserTrackFavoriteWriteSerializer - @extend_schema(operation_id='favorite_track') + @extend_schema(operation_id="favorite_track") def create(self, request, *args, **kwargs): serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) @@ -70,7 +70,7 @@ class TrackFavoriteViewSet( favorite = models.TrackFavorite.add(track=track, user=self.request.user) return favorite - @extend_schema(operation_id='unfavorite_track') + @extend_schema(operation_id="unfavorite_track") @action(methods=["delete", "post"], detail=False) def remove(self, request, *args, **kwargs): try: @@ -81,7 +81,7 @@ class TrackFavoriteViewSet( favorite.delete() 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) def all(self, request, *args, **kwargs): """ diff --git a/api/funkwhale_api/federation/api_views.py b/api/funkwhale_api/federation/api_views.py index 074941253..13cb20207 100644 --- a/api/funkwhale_api/federation/api_views.py +++ b/api/funkwhale_api/federation/api_views.py @@ -41,12 +41,12 @@ def update_follow(follow, approved): @extend_schema_view( - list=extend_schema(operation_id='get_federation_library_follows'), - create=extend_schema(operation_id='create_federation_library_follow'), + list=extend_schema(operation_id="get_federation_library_follows"), + 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. -@extend_schema(operation_id='get_federation_library_follow', methods=['get']) -@extend_schema(operation_id='delete_federation_library_follow', methods=['delete']) +@extend_schema(operation_id="get_federation_library_follow", methods=["get"]) +@extend_schema(operation_id="delete_federation_library_follow", methods=["delete"]) class LibraryFollowViewSet( mixins.CreateModelMixin, mixins.ListModelMixin, @@ -86,7 +86,7 @@ class LibraryFollowViewSet( context["actor"] = self.request.user.actor return context - @extend_schema(operation_id='accept_federation_library_follow') + @extend_schema(operation_id="accept_federation_library_follow") @decorators.action(methods=["post"], detail=True) def accept(self, request, *args, **kwargs): try: @@ -98,7 +98,7 @@ class LibraryFollowViewSet( update_follow(follow, approved=True) 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) def reject(self, request, *args, **kwargs): try: @@ -111,7 +111,7 @@ class LibraryFollowViewSet( update_follow(follow, approved=False) 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) def all(self, request, *args, **kwargs): """ diff --git a/api/funkwhale_api/federation/decorators.py b/api/funkwhale_api/federation/decorators.py index 04052417a..8cb35430f 100644 --- a/api/funkwhale_api/federation/decorators.py +++ b/api/funkwhale_api/federation/decorators.py @@ -44,8 +44,10 @@ def fetches_route(): serializer = api_serializers.FetchSerializer(fetch) return response.Response(serializer.data, status=status.HTTP_201_CREATED) - return extend_schema(methods=['post'], responses=api_serializers.FetchSerializer())( - extend_schema(methods=['get'], responses=api_serializers.FetchSerializer(many=True))( + return extend_schema(methods=["post"], responses=api_serializers.FetchSerializer())( + extend_schema( + methods=["get"], responses=api_serializers.FetchSerializer(many=True) + )( decorators.action( methods=["get", "post"], detail=True, diff --git a/api/funkwhale_api/instance/views.py b/api/funkwhale_api/instance/views.py index fe2441e00..7eb34135d 100644 --- a/api/funkwhale_api/instance/views.py +++ b/api/funkwhale_api/instance/views.py @@ -53,7 +53,7 @@ class InstanceSettings(generics.GenericAPIView): ] return api_preferences - @extend_schema(operation_id='get_instance_settings') + @extend_schema(operation_id="get_instance_settings") def get(self, request): queryset = self.get_queryset() data = GlobalPreferenceSerializer(queryset, many=True).data @@ -122,7 +122,7 @@ class SpaManifest(views.APIView): permission_classes = [] authentication_classes = [] - @extend_schema(operation_id='get_spa_manifest') + @extend_schema(operation_id="get_spa_manifest") def get(self, request, *args, **kwargs): existing_manifest = middleware.get_spa_file( settings.FUNKWHALE_SPA_HTML_ROOT, "manifest.json" diff --git a/api/funkwhale_api/manage/views.py b/api/funkwhale_api/manage/views.py index 83c822542..292ac1fa1 100644 --- a/api/funkwhale_api/manage/views.py +++ b/api/funkwhale_api/manage/views.py @@ -95,7 +95,7 @@ class ManageArtistViewSet( required_scope = "instance:libraries" 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) def stats(self, request, *args, **kwargs): artist = self.get_object() @@ -138,7 +138,7 @@ class ManageAlbumViewSet( required_scope = "instance:libraries" 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) def stats(self, request, *args, **kwargs): album = self.get_object() @@ -200,7 +200,7 @@ class ManageTrackViewSet( "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) def stats(self, request, *args, **kwargs): track = self.get_object() @@ -262,7 +262,7 @@ class ManageLibraryViewSet( filterset_class = filters.ManageLibraryFilterSet 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) def stats(self, request, *args, **kwargs): library = self.get_object() @@ -430,7 +430,7 @@ class ManageDomainViewSet( domain.refresh_from_db() 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) def stats(self, request, *args, **kwargs): domain = self.get_object() @@ -475,7 +475,7 @@ class ManageActorViewSet( 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) def stats(self, request, *args, **kwargs): obj = self.get_object() @@ -717,7 +717,7 @@ class ManageChannelViewSet( required_scope = "instance:libraries" 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) def stats(self, request, *args, **kwargs): channel = self.get_object() diff --git a/api/funkwhale_api/music/views.py b/api/funkwhale_api/music/views.py index fa78698b0..5804f6997 100644 --- a/api/funkwhale_api/music/views.py +++ b/api/funkwhale_api/music/views.py @@ -68,9 +68,9 @@ def get_libraries(filter_uploads): serializer = federation_api_serializers.LibrarySerializer(qs, many=True) return Response(serializer.data) - return extend_schema(responses=federation_api_serializers.LibrarySerializer(many=True))( - action(methods=["get"], detail=True)(libraries) - ) + return extend_schema( + responses=federation_api_serializers.LibrarySerializer(many=True) + )(action(methods=["get"], detail=True)(libraries)) def refetch_obj(obj, queryset): @@ -171,9 +171,11 @@ class ArtistViewSet( Prefetch("albums", queryset=albums), TAG_PREFETCH ) - libraries = get_libraries(lambda o, uploads: uploads.filter( - Q(track__artist=o) | Q(track__album__artist=o) - )) + libraries = get_libraries( + lambda o, uploads: uploads.filter( + Q(track__artist=o) | Q(track__album__artist=o) + ) + ) class AlbumViewSet( @@ -740,7 +742,7 @@ class UploadViewSet( qs = qs.playable_by(actor) 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") def audio_file_metadata(self, request, *args, **kwargs): upload = self.get_object() @@ -799,7 +801,7 @@ class Search(views.APIView): required_scope = "libraries" anonymous_policy = "setting" - @extend_schema(operation_id='get_search_results') + @extend_schema(operation_id="get_search_results") def get(self, request, *args, **kwargs): query = request.GET.get("query", request.GET.get("q", "")) or "" query = query.strip() diff --git a/api/funkwhale_api/playlists/views.py b/api/funkwhale_api/playlists/views.py index de4a2e633..e2ebd59ab 100644 --- a/api/funkwhale_api/playlists/views.py +++ b/api/funkwhale_api/playlists/views.py @@ -52,7 +52,9 @@ class PlaylistViewSet( data = {"count": len(plts), "results": serializer.data} 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) @transaction.atomic def add(self, request, *args, **kwargs): diff --git a/api/funkwhale_api/radios/views.py b/api/funkwhale_api/radios/views.py index 51241cc61..1d3098d59 100644 --- a/api/funkwhale_api/radios/views.py +++ b/api/funkwhale_api/radios/views.py @@ -66,7 +66,7 @@ class RadioViewSet( ) return Response(serializer.data) - @extend_schema(operation_id='validate_radio') + @extend_schema(operation_id="validate_radio") @action(methods=["post"], detail=False) def validate(self, request, *args, **kwargs): try: @@ -128,7 +128,7 @@ class RadioSessionTrackViewSet(mixins.CreateModelMixin, viewsets.GenericViewSet) queryset = models.RadioSessionTrack.objects.all() permission_classes = [] - @extend_schema(operation_id='get_next_radio_track') + @extend_schema(operation_id="get_next_radio_track") def create(self, request, *args, **kwargs): serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) diff --git a/api/funkwhale_api/schema.py b/api/funkwhale_api/schema.py index 0ba5920fe..b7ceb9c61 100644 --- a/api/funkwhale_api/schema.py +++ b/api/funkwhale_api/schema.py @@ -7,16 +7,15 @@ import re class CustomAutoSchema(AutoSchema): method_mapping = { - 'get': 'get', - 'post': 'create', - 'put': 'update', - 'patch': 'partial_update', - 'delete': 'delete', + "get": "get", + "post": "create", + "put": "update", + "patch": "partial_update", + "delete": "delete", } pluralizer = Pluralizer() - def get_operation_id(self): # Modified operation id getter from # 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() # 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 tokenized_path = [self.pluralizer.singular(t) for t in tokenized_path] if not tokenized_path: - tokenized_path.append('root') + tokenized_path.append("root") model = tokenized_path.pop() - if self.method == 'GET' and self._is_list_view(): - action = 'get' + if self.method == "GET" and self._is_list_view(): + action = "get" model = self.pluralizer.plural(model) else: action = self.method_mapping[self.method.lower()] - if re.search(r'', self.path_regex): - tokenized_path.append('formatted') + if re.search(r"", self.path_regex): + tokenized_path.append("formatted") # 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) # 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) # 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) # 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) # 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) - 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]) diff --git a/api/funkwhale_api/users/oauth/views.py b/api/funkwhale_api/users/oauth/views.py index ee8cbb3f2..d4d640650 100644 --- a/api/funkwhale_api/users/oauth/views.py +++ b/api/funkwhale_api/users/oauth/views.py @@ -86,7 +86,7 @@ class ApplicationViewSet( qs = qs.filter(user=self.request.user) return qs - @extend_schema(operation_id='refresh_oauth_token') + @extend_schema(operation_id="refresh_oauth_token") @action( detail=True, methods=["post"], diff --git a/api/funkwhale_api/users/views.py b/api/funkwhale_api/users/views.py index 1d65a092d..a780e8d7d 100644 --- a/api/funkwhale_api/users/views.py +++ b/api/funkwhale_api/users/views.py @@ -21,7 +21,7 @@ from funkwhale_api.common import throttling from . import models, serializers, tasks -@extend_schema(operation_id='register', methods=['post']) +@extend_schema(operation_id="register", methods=["post"]) class RegisterView(registration_views.RegisterView): serializer_class = serializers.RegisterSerializer permission_classes = [] @@ -46,22 +46,22 @@ class RegisterView(registration_views.RegisterView): return user -@extend_schema(operation_id='verify_email') +@extend_schema(operation_id="verify_email") class VerifyEmailView(registration_views.VerifyEmailView): action = "verify-email" -@extend_schema(operation_id='change_password') +@extend_schema(operation_id="change_password") class PasswordChangeView(rest_auth_views.PasswordChangeView): action = "password-change" -@extend_schema(operation_id='reset_password') +@extend_schema(operation_id="reset_password") class PasswordResetView(rest_auth_views.PasswordResetView): action = "password-reset" -@extend_schema(operation_id='confirm_password_reset') +@extend_schema(operation_id="confirm_password_reset") class PasswordResetConfirmView(rest_auth_views.PasswordResetConfirmView): action = "password-reset-confirm" @@ -73,8 +73,8 @@ class UserViewSet(mixins.UpdateModelMixin, viewsets.GenericViewSet): lookup_value_regex = r"[a-zA-Z0-9-_.]+" required_scope = "profile" - @extend_schema(operation_id='get_authenticated_user', methods=['get']) - @extend_schema(operation_id='delete_authenticated_user', methods=['delete']) + @extend_schema(operation_id="get_authenticated_user", methods=["get"]) + @extend_schema(operation_id="delete_authenticated_user", methods=["delete"]) @action(methods=["get", "delete"], detail=False) def me(self, request, *args, **kwargs): """Return information about the current user or delete it""" @@ -89,7 +89,7 @@ class UserViewSet(mixins.UpdateModelMixin, viewsets.GenericViewSet): serializer = serializers.MeSerializer(request.user) 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") def set_settings(self, request, *args, **kwargs): """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} return Response(data) - @extend_schema(operation_id='change_email') + @extend_schema(operation_id="change_email") @action( methods=["post"], required_scope="security", @@ -149,8 +149,8 @@ class UserViewSet(mixins.UpdateModelMixin, viewsets.GenericViewSet): return super().partial_update(request, *args, **kwargs) -@extend_schema(operation_id='login') -@action(methods=['post'], detail=False) +@extend_schema(operation_id="login") +@action(methods=["post"], detail=False) def login(request): throttling.check_request(request, "login") if request.method != "POST": @@ -170,8 +170,8 @@ def login(request): return response -@extend_schema(operation_id='logout') -@action(methods=['post'], detail=False) +@extend_schema(operation_id="logout") +@action(methods=["post"], detail=False) def logout(request): if request.method != "POST": return http.HttpResponse(status=405)