From 1252760de4858efb3e2d99d9bac6b9fe5efcbe30 Mon Sep 17 00:00:00 2001 From: Kshitij Sobti Date: Sat, 24 Mar 2018 02:12:06 +0530 Subject: [PATCH] Allow list_problem_responses to limit the number of responses Allow problem_location to be a UsageKey or string in list_problem_responses --- lms/djangoapps/instructor_analytics/basic.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lms/djangoapps/instructor_analytics/basic.py b/lms/djangoapps/instructor_analytics/basic.py index 237e030ccd..0851f4a6ac 100644 --- a/lms/djangoapps/instructor_analytics/basic.py +++ b/lms/djangoapps/instructor_analytics/basic.py @@ -406,7 +406,7 @@ def coupon_codes_features(features, coupons_list, course_id): return [extract_coupon(coupon, features) for coupon in coupons_list] -def list_problem_responses(course_key, problem_location): +def list_problem_responses(course_key, problem_location, limit_responses=None): """ Return responses to a given problem as a dict. @@ -421,7 +421,10 @@ def list_problem_responses(course_key, problem_location): where `state` represents a student's response to the problem identified by `problem_location`. """ - problem_key = UsageKey.from_string(problem_location) + if isinstance(problem_location, UsageKey): + problem_key = problem_location + else: + problem_key = UsageKey.from_string(problem_location) # Are we dealing with an "old-style" problem location? run = problem_key.run if not run: @@ -434,6 +437,8 @@ def list_problem_responses(course_key, problem_location): module_state_key=problem_key ) smdat = smdat.order_by('student') + if limit_responses is not None: + smdat = smdat[:limit_responses] return [ {'username': response.student.username, 'state': response.state}