diff --git a/models.py b/models.py index f3f27f6..33ea2f2 100644 --- a/models.py +++ b/models.py @@ -1048,14 +1048,15 @@ class Follower(ndb.Model): return follower @staticmethod - def fetch_page(collection): - """Fetches a page of Followers for the current user. + def fetch_page(collection, user): + """Fetches a page of :class:`Follower`s for a given user. Wraps :func:`fetch_page`. Paging uses the ``before`` and ``after`` query parameters, if available in the request. Args: collection (str): ``followers`` or ``following`` + user (User) Returns: (list of Follower, str, str) tuple: results, annotated with an extra @@ -1068,7 +1069,7 @@ class Follower(ndb.Model): filter_prop = Follower.to if collection == 'followers' else Follower.from_ query = Follower.query( Follower.status == 'active', - filter_prop == g.user.key, + filter_prop == user.key, ).order(-Follower.updated) followers, before, after = fetch_page(query, Follower, by=Follower.updated) diff --git a/pages.py b/pages.py index b692740..0afc3b7 100644 --- a/pages.py +++ b/pages.py @@ -53,6 +53,9 @@ def load_user(protocol, id): protocol (str): id (str): + Returns: + models.User: + Raises: :class:`werkzeug.exceptions.HTTPException` on error or redirect """ @@ -85,6 +88,7 @@ def load_user(protocol, id): error(f'{protocol} user {id} not found', status=404) assert not g.user.use_instead + return g.user @app.route('/') @@ -158,9 +162,9 @@ def notifications(protocol, id): @app.get(f'///') @canonicalize_request_domain(common.PROTOCOL_DOMAINS, common.PRIMARY_DOMAIN) def followers_or_following(protocol, id, collection): - load_user(protocol, id) + user = load_user(protocol, id) - followers, before, after = Follower.fetch_page(collection) + followers, before, after = Follower.fetch_page(collection, user) num_followers, num_following = g.user.count_followers() return render_template( f'{collection}.html',