mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-18 07:23:00 +00:00
Paginate listing users and groups
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -29,3 +29,4 @@ htmlcov
|
||||
pip-wheel-metadata
|
||||
docs/source/reference/metrics.rst
|
||||
oldest-requirements.txt
|
||||
jupyterhub-proxy.pid
|
||||
|
@@ -37,7 +37,17 @@ class GroupListAPIHandler(_GroupAPIHandler):
|
||||
@admin_only
|
||||
def get(self):
|
||||
"""List groups"""
|
||||
data = [self.group_model(g) for g in self.db.query(orm.Group)]
|
||||
offset = self.get_argument("offset", None)
|
||||
limit = self.get_argument("limit", None)
|
||||
|
||||
groups_query = self.db.query(orm.Group)
|
||||
|
||||
if offset is not None or limit is not None:
|
||||
offset = 0 if not offset else int(offset)
|
||||
limit = None if not limit else int(limit)
|
||||
groups_query = groups_query.offset(offset).limit(limit)
|
||||
|
||||
data = [self.group_model(g) for g in groups_query]
|
||||
self.write(json.dumps(data))
|
||||
|
||||
@admin_only
|
||||
@@ -76,7 +86,8 @@ class GroupAPIHandler(_GroupAPIHandler):
|
||||
@admin_only
|
||||
def get(self, name):
|
||||
group = self.find_group(name)
|
||||
self.write(json.dumps(self.group_model(group)))
|
||||
group_model = self.group_model(group)
|
||||
self.write(json.dumps(group_model))
|
||||
|
||||
@admin_only
|
||||
async def post(self, name):
|
||||
|
@@ -55,6 +55,8 @@ class UserListAPIHandler(APIHandler):
|
||||
@admin_only
|
||||
def get(self):
|
||||
state_filter = self.get_argument("state", None)
|
||||
offset = self.get_argument("offset", None)
|
||||
limit = self.get_argument("limit", None)
|
||||
|
||||
# post_filter
|
||||
post_filter = None
|
||||
@@ -95,11 +97,18 @@ class UserListAPIHandler(APIHandler):
|
||||
# no filter, return all users
|
||||
query = self.db.query(orm.User)
|
||||
|
||||
# Apply offset and limit for request pagination
|
||||
if offset is not None or limit is not None:
|
||||
offset = 0 if not offset else int(offset)
|
||||
limit = None if not limit else int(limit)
|
||||
query = query.offset(offset).limit(limit)
|
||||
|
||||
data = [
|
||||
self.user_model(u, include_servers=True, include_state=True)
|
||||
for u in query
|
||||
if (post_filter is None or post_filter(u))
|
||||
]
|
||||
|
||||
self.write(json.dumps(data))
|
||||
|
||||
@admin_only
|
||||
|
Reference in New Issue
Block a user