From 37b27d779129d2e1b63000dbaf4496f2e45fe1d5 Mon Sep 17 00:00:00 2001 From: Kyle Raftogianis Date: Wed, 4 May 2016 16:53:17 -0700 Subject: [PATCH] Add "before" query param to get_submissions (#734) --- server/app/api.py | 11 +++-------- server/app/models.py | 7 +++++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/server/app/api.py b/server/app/api.py index d460f2150..a5995a094 100644 --- a/server/app/api.py +++ b/server/app/api.py @@ -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': { @@ -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): """ diff --git a/server/app/models.py b/server/app/models.py index 9593ec4a8..87d7d6dc8 100644 --- a/server/app/models.py +++ b/server/app/models.py @@ -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."""