kopia lustrzana https://github.com/snarfed/bridgy-fed
rodzic
29158e02e9
commit
a1a7ceef51
|
@ -1048,14 +1048,15 @@ class Follower(ndb.Model):
|
||||||
return follower
|
return follower
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def fetch_page(collection):
|
def fetch_page(collection, user):
|
||||||
"""Fetches a page of Followers for the current user.
|
"""Fetches a page of :class:`Follower`s for a given user.
|
||||||
|
|
||||||
Wraps :func:`fetch_page`. Paging uses the ``before`` and ``after`` query
|
Wraps :func:`fetch_page`. Paging uses the ``before`` and ``after`` query
|
||||||
parameters, if available in the request.
|
parameters, if available in the request.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
collection (str): ``followers`` or ``following``
|
collection (str): ``followers`` or ``following``
|
||||||
|
user (User)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
(list of Follower, str, str) tuple: results, annotated with an extra
|
(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_
|
filter_prop = Follower.to if collection == 'followers' else Follower.from_
|
||||||
query = Follower.query(
|
query = Follower.query(
|
||||||
Follower.status == 'active',
|
Follower.status == 'active',
|
||||||
filter_prop == g.user.key,
|
filter_prop == user.key,
|
||||||
).order(-Follower.updated)
|
).order(-Follower.updated)
|
||||||
|
|
||||||
followers, before, after = fetch_page(query, Follower, by=Follower.updated)
|
followers, before, after = fetch_page(query, Follower, by=Follower.updated)
|
||||||
|
|
8
pages.py
8
pages.py
|
@ -53,6 +53,9 @@ def load_user(protocol, id):
|
||||||
protocol (str):
|
protocol (str):
|
||||||
id (str):
|
id (str):
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
models.User:
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
:class:`werkzeug.exceptions.HTTPException` on error or redirect
|
: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)
|
error(f'{protocol} user {id} not found', status=404)
|
||||||
|
|
||||||
assert not g.user.use_instead
|
assert not g.user.use_instead
|
||||||
|
return g.user
|
||||||
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
|
@ -158,9 +162,9 @@ def notifications(protocol, id):
|
||||||
@app.get(f'/<any({",".join(PROTOCOLS)}):protocol>/<id>/<any(followers,following):collection>')
|
@app.get(f'/<any({",".join(PROTOCOLS)}):protocol>/<id>/<any(followers,following):collection>')
|
||||||
@canonicalize_request_domain(common.PROTOCOL_DOMAINS, common.PRIMARY_DOMAIN)
|
@canonicalize_request_domain(common.PROTOCOL_DOMAINS, common.PRIMARY_DOMAIN)
|
||||||
def followers_or_following(protocol, id, collection):
|
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()
|
num_followers, num_following = g.user.count_followers()
|
||||||
return render_template(
|
return render_template(
|
||||||
f'{collection}.html',
|
f'{collection}.html',
|
||||||
|
|
Ładowanie…
Reference in New Issue