From 2746d8750d237e8af1dc3ddcfaa4bfba55c138ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20Ainsworth?= Date: Sun, 17 Jul 2022 16:28:59 +0200 Subject: [PATCH] Use standard Python type hints in models --- api/funkwhale_api/audio/models.py | 6 +----- api/funkwhale_api/common/models.py | 4 ---- api/funkwhale_api/federation/models.py | 15 +++------------ api/funkwhale_api/music/models.py | 10 ++-------- api/funkwhale_api/users/models.py | 6 +----- 5 files changed, 7 insertions(+), 34 deletions(-) diff --git a/api/funkwhale_api/audio/models.py b/api/funkwhale_api/audio/models.py index 3fe34f2b1..2ef608c92 100644 --- a/api/funkwhale_api/audio/models.py +++ b/api/funkwhale_api/audio/models.py @@ -15,9 +15,6 @@ from funkwhale_api.federation import models as federation_models from funkwhale_api.federation import utils as federation_utils from funkwhale_api.users import models as user_models -from drf_spectacular.utils import extend_schema_field -from drf_spectacular.types import OpenApiTypes - def empty_dict(): return {} @@ -83,8 +80,7 @@ class Channel(models.Model): return self.actor.fid @property - @extend_schema_field(OpenApiTypes.BOOL) - def is_local(self): + def is_local(self) -> bool: return self.actor.is_local @property diff --git a/api/funkwhale_api/common/models.py b/api/funkwhale_api/common/models.py index 29eb4696a..9dd19c2ec 100644 --- a/api/funkwhale_api/common/models.py +++ b/api/funkwhale_api/common/models.py @@ -18,9 +18,6 @@ from django.urls import reverse from versatileimagefield.fields import VersatileImageField from versatileimagefield.image_warmer import VersatileImageFieldWarmer -from drf_spectacular.utils import extend_schema_field -from drf_spectacular.types import OpenApiTypes - from funkwhale_api.federation import utils as federation_utils from . import utils @@ -243,7 +240,6 @@ class Attachment(models.Model): return super().save() @property - @extend_schema_field(OpenApiTypes.BOOL) def is_local(self): return federation_utils.is_local(self.fid) diff --git a/api/funkwhale_api/federation/models.py b/api/funkwhale_api/federation/models.py index 3ca50ed12..125b61353 100644 --- a/api/funkwhale_api/federation/models.py +++ b/api/funkwhale_api/federation/models.py @@ -19,9 +19,6 @@ from funkwhale_api.common import utils as common_utils from funkwhale_api.common import validators as common_validators from funkwhale_api.music import utils as music_utils -from drf_spectacular.utils import extend_schema_field -from drf_spectacular.types import OpenApiTypes - from . import utils as federation_utils TYPE_CHOICES = [ @@ -51,8 +48,7 @@ class FederationMixin(models.Model): abstract = True @property - @extend_schema_field(OpenApiTypes.BOOL) - def is_local(self): + def is_local(self) -> bool: return federation_utils.is_local(self.fid) @property @@ -176,8 +172,7 @@ class Domain(models.Model): return data @property - @extend_schema_field(OpenApiTypes.BOOL) - def is_local(self): + def is_local(self) -> bool: return self.name == settings.FEDERATION_HOSTNAME @@ -237,24 +232,20 @@ class Actor(models.Model): return "{}#main-key".format(self.fid) @property - @extend_schema_field(OpenApiTypes.STR) - def full_username(self): + def full_username(self) -> str: return "{}@{}".format(self.preferred_username, self.domain_id) def __str__(self): return "{}@{}".format(self.preferred_username, self.domain_id) @property - @extend_schema_field(OpenApiTypes.BOOL) def is_local(self) -> bool: return self.domain_id == settings.FEDERATION_HOSTNAME - @extend_schema_field({'type': 'array', 'items': {'type': 'object'}}) def get_approved_followers(self): follows = self.received_follows.filter(approved=True) return self.followers.filter(pk__in=follows.values_list("actor", flat=True)) - @extend_schema_field(OpenApiTypes.BOOL) def should_autoapprove_follow(self, actor): if self.get_channel(): return True diff --git a/api/funkwhale_api/music/models.py b/api/funkwhale_api/music/models.py index c98c48b41..de2dda0a8 100644 --- a/api/funkwhale_api/music/models.py +++ b/api/funkwhale_api/music/models.py @@ -35,9 +35,6 @@ from funkwhale_api.federation import utils as federation_utils from funkwhale_api.tags import models as tags_models from . import importers, metadata, utils -from drf_spectacular.utils import extend_schema_field -from drf_spectacular.types import OpenApiTypes - logger = logging.getLogger(__name__) MAX_LENGTHS = { @@ -140,8 +137,7 @@ class APIModelMixin(models.Model): return super().save(**kwargs) @property - @extend_schema_field(OpenApiTypes.BOOL) - def is_local(self): + def is_local(self) -> bool: return federation_utils.is_local(self.fid) @property @@ -152,7 +148,6 @@ class APIModelMixin(models.Model): parsed = urllib.parse.urlparse(self.fid) return parsed.hostname - @extend_schema_field({'type': 'array', 'items': {'type': 'string'}}) def get_tags(self): return list(sorted(self.tagged_items.values_list("tag__name", flat=True))) @@ -787,8 +782,7 @@ class Upload(models.Model): objects = UploadQuerySet.as_manager() @property - @extend_schema_field(OpenApiTypes.BOOL) - def is_local(self): + def is_local(self) -> bool: return federation_utils.is_local(self.fid) @property diff --git a/api/funkwhale_api/users/models.py b/api/funkwhale_api/users/models.py index 36f0583ac..3b4c41796 100644 --- a/api/funkwhale_api/users/models.py +++ b/api/funkwhale_api/users/models.py @@ -29,9 +29,6 @@ from funkwhale_api.federation import keys from funkwhale_api.federation import models as federation_models from funkwhale_api.federation import utils as federation_utils -from drf_spectacular.utils import extend_schema_field -from drf_spectacular.types import OpenApiTypes - def get_token(length=5): wordlist_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), "wordlist.txt" @@ -309,8 +306,7 @@ class User(AbstractUser): return groups - @extend_schema_field(OpenApiTypes.STR) - def full_username(self): + def full_username(self) -> str: return "{}@{}".format(self.username, settings.FEDERATION_HOSTNAME) def get_avatar(self):