Fix linting issues

This commit is contained in:
Ciarán Ainsworth 2022-07-18 01:08:38 +02:00
parent 1a12159c28
commit b5b98a2907
7 changed files with 15 additions and 10 deletions

View File

@ -35,8 +35,8 @@ class CustomApplicationTokenExt(OpenApiAuthenticationExtension):
def get_security_definition(self, auto_schema): def get_security_definition(self, auto_schema):
return build_bearer_security_scheme_object( return build_bearer_security_scheme_object(
header_name='Authorization', header_name="Authorization",
token_prefix='Bearer', token_prefix="Bearer",
) )

View File

@ -15,6 +15,7 @@ from funkwhale_api.federation import models as federation_models
from funkwhale_api.federation import utils as federation_utils from funkwhale_api.federation import utils as federation_utils
from funkwhale_api.users import models as user_models from funkwhale_api.users import models as user_models
def empty_dict(): def empty_dict():
return {} return {}

View File

@ -141,6 +141,7 @@ def local_qs(queryset, url_field="fid", include=True):
query = ~query query = ~query
return queryset.filter(query) return queryset.filter(query)
@extend_schema_field(OpenApiTypes.BOOL) @extend_schema_field(OpenApiTypes.BOOL)
def is_local(url): def is_local(url):
if not url: if not url:

View File

@ -429,7 +429,7 @@ class ManageArtistSerializer(
def get_albums_count(self, obj): def get_albums_count(self, obj):
return getattr(obj, "_albums_count", None) return getattr(obj, "_albums_count", None)
@extend_schema_field({'type': 'array', 'items': {'type': 'string'}}) @extend_schema_field({"type": "array", "items": {"type": "string"}})
def get_tags(self, obj): def get_tags(self, obj):
tagged_items = getattr(obj, "_prefetched_tagged_items", []) tagged_items = getattr(obj, "_prefetched_tagged_items", [])
return [ti.tag.name for ti in tagged_items] return [ti.tag.name for ti in tagged_items]
@ -464,7 +464,7 @@ class ManageAlbumSerializer(
def get_tracks_count(self, o): def get_tracks_count(self, o):
return len(o.tracks.all()) return len(o.tracks.all())
@extend_schema_field({'type': 'array', 'items': {'type': 'string'}}) @extend_schema_field({"type": "array", "items": {"type": "string"}})
def get_tags(self, obj): def get_tags(self, obj):
tagged_items = getattr(obj, "_prefetched_tagged_items", []) tagged_items = getattr(obj, "_prefetched_tagged_items", [])
return [ti.tag.name for ti in tagged_items] return [ti.tag.name for ti in tagged_items]
@ -503,7 +503,7 @@ class ManageTrackSerializer(
def get_uploads_count(self, obj): def get_uploads_count(self, obj):
return getattr(obj, "uploads_count", None) return getattr(obj, "uploads_count", None)
@extend_schema_field({'type': 'array', 'items': {'type': 'string'}}) @extend_schema_field({"type": "array", "items": {"type": "string"}})
def get_tags(self, obj): def get_tags(self, obj):
tagged_items = getattr(obj, "_prefetched_tagged_items", []) tagged_items = getattr(obj, "_prefetched_tagged_items", [])
return [ti.tag.name for ti in tagged_items] return [ti.tag.name for ti in tagged_items]

View File

@ -41,6 +41,7 @@ class CoverField(common_serializers.AttachmentSerializer):
cover_field = CoverField() cover_field = CoverField()
@extend_schema_field(OpenApiTypes.OBJECT) @extend_schema_field(OpenApiTypes.OBJECT)
def serialize_attributed_to(self, obj): def serialize_attributed_to(self, obj):
# Import at runtime to avoid a circular import issue # Import at runtime to avoid a circular import issue
@ -132,7 +133,7 @@ class ArtistWithAlbumsSerializer(OptionalDescriptionMixin, serializers.Serialize
is_local = serializers.BooleanField() is_local = serializers.BooleanField()
cover = cover_field cover = cover_field
@extend_schema_field({'type': 'array', 'items': {'type': 'string'}}) @extend_schema_field({"type": "array", "items": {"type": "string"}})
def get_tags(self, obj): def get_tags(self, obj):
tagged_items = getattr(obj, "_prefetched_tagged_items", []) tagged_items = getattr(obj, "_prefetched_tagged_items", [])
return [ti.tag.name for ti in tagged_items] return [ti.tag.name for ti in tagged_items]
@ -231,7 +232,7 @@ class AlbumSerializer(OptionalDescriptionMixin, serializers.Serializer):
except AttributeError: except AttributeError:
return None return None
@extend_schema_field({'type': 'array', 'items': {'type': 'string'}}) @extend_schema_field({"type": "array", "items": {"type": "string"}})
def get_tags(self, obj): def get_tags(self, obj):
tagged_items = getattr(obj, "_prefetched_tagged_items", []) tagged_items = getattr(obj, "_prefetched_tagged_items", [])
return [ti.tag.name for ti in tagged_items] return [ti.tag.name for ti in tagged_items]
@ -269,6 +270,7 @@ class TrackAlbumSerializer(serializers.ModelSerializer):
"tracks_count", "tracks_count",
) )
@extend_schema_field(OpenApiTypes.OBJECT) @extend_schema_field(OpenApiTypes.OBJECT)
def serialize_upload(upload): def serialize_upload(upload):
return { return {
@ -327,7 +329,7 @@ class TrackSerializer(OptionalDescriptionMixin, serializers.Serializer):
def get_listen_url(self, obj): def get_listen_url(self, obj):
return obj.listen_url return obj.listen_url
@extend_schema_field({'type': 'array', 'items': {'type': 'object'}}) @extend_schema_field({"type": "array", "items": {"type": "object"}})
def get_uploads(self, obj): def get_uploads(self, obj):
uploads = getattr(obj, "playable_uploads", []) uploads = getattr(obj, "playable_uploads", [])
# we put local uploads first # we put local uploads first
@ -335,7 +337,7 @@ class TrackSerializer(OptionalDescriptionMixin, serializers.Serializer):
uploads = sorted(uploads, key=lambda u: u["is_local"], reverse=True) uploads = sorted(uploads, key=lambda u: u["is_local"], reverse=True)
return list(uploads) return list(uploads)
@extend_schema_field({'type': 'array', 'items': {'type': 'str'}}) @extend_schema_field({"type": "array", "items": {"type": "str"}})
def get_tags(self, obj): def get_tags(self, obj):
tagged_items = getattr(obj, "_prefetched_tagged_items", []) tagged_items = getattr(obj, "_prefetched_tagged_items", [])
return [ti.tag.name for ti in tagged_items] return [ti.tag.name for ti in tagged_items]

View File

@ -78,7 +78,7 @@ class PlaylistSerializer(serializers.ModelSerializer):
# no annotation? # no annotation?
return 0 return 0
@extend_schema_field({'type': 'array', 'items': {'type': 'uri'}}) @extend_schema_field({"type": "array", "items": {"type": "uri"}})
def get_album_covers(self, obj): def get_album_covers(self, obj):
try: try:
plts = obj.plts_for_cover plts = obj.plts_for_cover

View File

@ -29,6 +29,7 @@ from funkwhale_api.federation import keys
from funkwhale_api.federation import models as federation_models from funkwhale_api.federation import models as federation_models
from funkwhale_api.federation import utils as federation_utils from funkwhale_api.federation import utils as federation_utils
def get_token(length=5): def get_token(length=5):
wordlist_path = os.path.join( wordlist_path = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "wordlist.txt" os.path.dirname(os.path.abspath(__file__)), "wordlist.txt"