kopia lustrzana https://github.com/jointakahe/takahe
Base /api/v1/followed_tags off of HashtagFollow models
This is due to the Tag model not having a dedicated ID which is needed for pagination.pull/539/head
rodzic
d9b0fc6beb
commit
32392e727d
|
@ -287,6 +287,24 @@ class Tag(Schema):
|
|||
return cls(**hashtag.to_mastodon_json(followed=followed))
|
||||
|
||||
|
||||
class FollowedTag(Tag):
|
||||
id: str
|
||||
|
||||
@classmethod
|
||||
def from_follow(
|
||||
cls,
|
||||
follow: users_models.HashtagFollow,
|
||||
) -> "FollowedTag":
|
||||
return cls(id=follow.id, **follow.hashtag.to_mastodon_json(followed=True))
|
||||
|
||||
@classmethod
|
||||
def map_from_follows(
|
||||
cls,
|
||||
hashtag_follows: list[users_models.HashtagFollow],
|
||||
) -> list["Tag"]:
|
||||
return [cls.from_follow(follow) for follow in hashtag_follows]
|
||||
|
||||
|
||||
class FeaturedTag(Schema):
|
||||
id: str
|
||||
name: str
|
||||
|
|
|
@ -6,6 +6,7 @@ from activities.models import Hashtag
|
|||
from api import schemas
|
||||
from api.decorators import scope_required
|
||||
from api.pagination import MastodonPaginator, PaginatingApiResponse, PaginationResult
|
||||
from users.models import HashtagFollow
|
||||
|
||||
|
||||
@scope_required("read:follows")
|
||||
|
@ -17,10 +18,9 @@ def followed_tags(
|
|||
min_id: str | None = None,
|
||||
limit: int = 100,
|
||||
) -> list[schemas.Tag]:
|
||||
queryset = Hashtag.objects.followed_by(request.identity)
|
||||
queryset = HashtagFollow.objects.by_identity(request.identity)
|
||||
paginator = MastodonPaginator()
|
||||
# TODO: this fails due to the Hashtag model not having an `id` field
|
||||
pager: PaginationResult[Hashtag] = paginator.paginate(
|
||||
pager: PaginationResult[HashtagFollow] = paginator.paginate(
|
||||
queryset,
|
||||
min_id=min_id,
|
||||
max_id=max_id,
|
||||
|
@ -28,8 +28,7 @@ def followed_tags(
|
|||
limit=limit,
|
||||
)
|
||||
return PaginatingApiResponse(
|
||||
# TODO: add something like map_from_post to schemas.Tag
|
||||
schemas.Tag.map_from_post(pager.results, request.identity),
|
||||
schemas.FollowedTag.map_from_follows(pager.results),
|
||||
request=request,
|
||||
include_params=["limit"],
|
||||
)
|
||||
|
|
|
@ -5,8 +5,10 @@ from django.db import models
|
|||
|
||||
class HashtagFollowQuerySet(models.QuerySet):
|
||||
def by_hashtags(self, hashtags: list[str]):
|
||||
query = self.filter(hashtag_id__in=hashtags)
|
||||
return query
|
||||
return self.filter(hashtag_id__in=hashtags)
|
||||
|
||||
def by_identity(self, identity):
|
||||
return self.filter(identity=identity)
|
||||
|
||||
|
||||
class HashtagFollowManager(models.Manager):
|
||||
|
@ -16,6 +18,9 @@ class HashtagFollowManager(models.Manager):
|
|||
def by_hashtags(self, hashtags: list[str]):
|
||||
return self.get_queryset().by_hashtags(hashtags)
|
||||
|
||||
def by_identity(self, identity):
|
||||
return self.get_queryset().by_identity(identity)
|
||||
|
||||
|
||||
class HashtagFollow(models.Model):
|
||||
identity = models.ForeignKey(
|
||||
|
|
Ładowanie…
Reference in New Issue