Skip to content

Commit

Permalink
Add count method for girder count header
Browse files Browse the repository at this point in the history
  • Loading branch information
eagw committed Aug 10, 2022
1 parent d350560 commit 0e1adec
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions girder_annotation/girder_large_image_annotation/rest/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ def deleteItemAnnotations(self, item):
return count

def getFolderAnnotations(self, id, recurse, user, limit=False, offset=False, sort=False,
sortDir=False):
sortDir=False, count=False):
recursivePipeline = [
{'$graphLookup': {
'from': 'folder',
Expand Down Expand Up @@ -614,9 +614,12 @@ def getFolderAnnotations(self, id, recurse, user, limit=False, offset=False, sor
] + accessPipeline
}},
]
pipeline = pipeline + [{'$sort': {sort: sortDir}}] if sort else pipeline
pipeline = pipeline + [{'$skip': offset}] if offset else pipeline
pipeline = pipeline + [{'$limit': limit}] if limit else pipeline
if count:
pipeline += [{'$count': 'count'}]
else:
pipeline = pipeline + [{'$sort': {sort: sortDir}}] if sort else pipeline
pipeline = pipeline + [{'$skip': offset}] if offset else pipeline
pipeline = pipeline + [{'$limit': limit}] if limit else pipeline

return Annotation().collection.aggregate(pipeline)

Expand Down Expand Up @@ -646,8 +649,19 @@ def existFolderAnnotations(self, id, recurse):
)
@access.public
def returnFolderAnnotations(self, id, recurse, limit, offset, sort):
return self.getFolderAnnotations(id, recurse, self.getCurrentUser(), limit, offset,
sort[0][0], sort[0][1])
annotations = self.getFolderAnnotations(id, recurse, self.getCurrentUser(), limit, offset,
sort[0][0], sort[0][1])

def count():
try:
return next(self.getFolderAnnotations(id, recurse, self.getCurrentUser(),
count=True))['count']
except StopIteration:
# If there are no values to iterate over, the count is 0 and should be returned
return 0

annotations.count = count
return annotations

@autoDescribeRoute(
Description('Report on old annotations.')
Expand Down

0 comments on commit 0e1adec

Please sign in to comment.