Skip to content

Commit

Permalink
Add "before" query param to get_submissions (#734)
Browse files Browse the repository at this point in the history
  • Loading branch information
knrafto authored and Sumukh committed May 4, 2016
1 parent f0fec60 commit 37b27d7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
11 changes: 3 additions & 8 deletions server/app/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,16 +534,10 @@ class UserAPI(APIResource):
'methods': set(['GET']),
'web_args': {
'assignment': KeyArg('Assignment', required=True),
'before': DateTimeArg(),
'quantity': Arg(int, default=10)
}
},
'timed_submission': {
'methods': set(['GET']),
'web_args': {
'assignment': KeyArg('Assignment', required=True),
'before': DateTimeArg()
}
},
'merge_user': {
'methods': set(['POST']),
'web_args': {
Expand Down Expand Up @@ -688,7 +682,8 @@ def get_backups(self, obj, user, data):
return obj.get_backups(data['assignment'], data['quantity'])

def get_submissions(self, obj, user, data):
return obj.get_submissions(data['assignment'], data['quantity'])
return obj.get_submissions(data['assignment'],
num_submissions=data['quantity'], before=data.get('before'))

def merge_user(self, obj, user, data):
"""
Expand Down
7 changes: 5 additions & 2 deletions server/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,12 @@ def submissions(self, group, assignment):
Submission.assignment == assignment
).order(-Backup.server_time)

def get_submissions(self, assignment, num_submissions=10):
def get_submissions(self, assignment, num_submissions=10, before=None):
group = self.get_group(assignment)
return self.submissions(group, assignment).fetch(num_submissions)
query = self.submissions(group, assignment)
if before:
query = query.filter(Backup.server_time <= before)
return query.fetch(num_submissions)

def group(self, assignment_key):
"""Return a query that fetches the group for this user for an assignment."""
Expand Down

0 comments on commit 37b27d7

Please sign in to comment.