From ea7d5f307cb69e5e9555770223e7a9594a0d8421 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Wed, 22 Mar 2023 16:21:30 -0600 Subject: [PATCH] Allow single IDs in familiar_followers Fixes #547 --- api/views/accounts.py | 21 ++++++++++++++++----- requirements.txt | 2 +- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/api/views/accounts.py b/api/views/accounts.py index 61421f4..3c938b4 100644 --- a/api/views/accounts.py +++ b/api/views/accounts.py @@ -75,10 +75,16 @@ def update_credentials( @scope_required("read") @api_view.get -def account_relationships(request, id: list[str] | None) -> list[schemas.Relationship]: +def account_relationships( + request, id: list[str] | str | None +) -> list[schemas.Relationship]: result = [] - # ID is actually a list. Thanks Mastodon! - ids = id or [] + if isinstance(id, str): + ids = [id] + elif id is None: + ids = [] + else: + ids = id for actual_id in ids: identity = get_object_or_404(Identity, pk=actual_id) result.append( @@ -90,12 +96,17 @@ def account_relationships(request, id: list[str] | None) -> list[schemas.Relatio @scope_required("read") @api_view.get def familiar_followers( - request, id: list[str] | None + request, id: list[str] | str | None ) -> list[schemas.FamiliarFollowers]: """ Returns people you follow that also follow given account IDs """ - ids = id or [] + if isinstance(id, str): + ids = [id] + elif id is None: + ids = [] + else: + ids = id result = [] for actual_id in ids: target_identity = get_object_or_404(Identity, pk=actual_id) diff --git a/requirements.txt b/requirements.txt index 23943cc..2ad2603 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,7 +5,7 @@ dj_database_url~=1.0.0 django-cache-url~=3.4.2 django-cors-headers~=3.13.0 django-debug-toolbar~=3.8.1 -django-hatchway~=0.5.0 +django-hatchway~=0.5.1 django-htmx~=1.13.0 django-oauth-toolkit~=2.2.0 django-storages[google,boto3]~=1.13.1