parent
36fa93a0fb
commit
1eec6f53b2
4 changed files with 27 additions and 14 deletions
|
@ -1,4 +1,4 @@
|
|||
def paginate(query, model, descending=False, page_token=None, limit=50):
|
||||
def paginate(query, model, descending=False, page_token=None, limit=50, id_field='id'):
|
||||
""" Paginates the given query using an ID range, starting at the optional page_token.
|
||||
Returns a *list* of matching results along with an unencrypted page_token for the
|
||||
next page, if any. If descending is set to True, orders by the ID descending rather
|
||||
|
@ -7,9 +7,9 @@ def paginate(query, model, descending=False, page_token=None, limit=50):
|
|||
query = query.limit(limit + 1)
|
||||
|
||||
if descending:
|
||||
query = query.order_by(model.id.desc())
|
||||
query = query.order_by(getattr(model, id_field).desc())
|
||||
else:
|
||||
query = query.order_by(model.id)
|
||||
query = query.order_by(getattr(model, id_field))
|
||||
|
||||
if page_token is not None:
|
||||
start_id = page_token.get('start_id')
|
||||
|
|
|
@ -231,10 +231,10 @@ def get_visible_repositories(username, namespace=None, include_public=False):
|
|||
""" Returns the repositories visible to the given user (if any).
|
||||
"""
|
||||
if not include_public and not username:
|
||||
return []
|
||||
return Repository.select().where(Repository.id == -1)
|
||||
|
||||
query = (Repository
|
||||
.select(Repository.name, Repository.id.alias('id'), Repository.description, Namespace.username,
|
||||
.select(Repository.name, Repository.id.alias('rid'), Repository.description, Namespace.username,
|
||||
Repository.visibility)
|
||||
.distinct()
|
||||
.switch(Repository)
|
||||
|
|
Reference in a new issue