Change group.users pagination to use slices

This commit is contained in:
Nathan Barber
2021-04-15 12:27:13 -04:00
parent 7f006726e7
commit 63b53162f8
2 changed files with 6 additions and 8 deletions

View File

@@ -104,6 +104,9 @@ class GroupAPIHandler(_GroupAPIHandler):
group = self.find_group(name)
users_slice = None
print(type(group.users))
print(group.users)
if offset is not None:
try:
offset = int(offset)
@@ -112,7 +115,7 @@ class GroupAPIHandler(_GroupAPIHandler):
400, "Invalid argument type, offset must be an integer"
)
users_slice = group.users.offset(int(offset))
group.users = group.users[offset:]
if limit is not None:
try:
@@ -122,10 +125,7 @@ class GroupAPIHandler(_GroupAPIHandler):
400, "Invalid argument type, limit must be an integer"
)
if users_slice is not None:
users_slice = users_slice.limit(int(limit))
else:
users_slice = group.users.limit(int(limit))
group.users = group.users[:limit]
group_model = self.group_model(group)

View File

@@ -128,9 +128,7 @@ class Group(Base):
__tablename__ = 'groups'
id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(Unicode(255), unique=True)
users = relationship(
'User', secondary='user_group_map', backref='groups', lazy="dynamic"
)
users = relationship('User', secondary='user_group_map', backref='groups')
def __repr__(self):
return "<%s %s (%i users)>" % (