From 7460c775595b237aad74eeddd8a35d018b39040d Mon Sep 17 00:00:00 2001 From: Tim Krones Date: Wed, 19 Aug 2015 18:35:26 +0200 Subject: [PATCH] Allow instructors to search for answers from multiple users simultaneously. --- problem_builder/instructor_tool.py | 19 ++++++++++++------- problem_builder/public/js/instructor_tool.js | 4 ++-- problem_builder/tasks.py | 11 ++++++++--- .../templates/html/instructor_tool.html | 4 ++-- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/problem_builder/instructor_tool.py b/problem_builder/instructor_tool.py index 4b413a81..4b3cb255 100644 --- a/problem_builder/instructor_tool.py +++ b/problem_builder/instructor_tool.py @@ -282,7 +282,7 @@ def _delete_export(self): def start_export(self, data, suffix=''): """ Start a new asynchronous export """ block_types = data.get('block_types', None) - username = data.get('username', None) + usernames = data.get('usernames', None) root_block_id = data.get('root_block_id', None) match_string = data.get('match_string', None) @@ -295,12 +295,17 @@ def start_export(self, data, suffix=''): user_service = self.runtime.service(self, 'user') if not self.user_is_staff(): return {'error': 'permission denied'} - if not username: - user_id = None + if not usernames: + user_ids = None else: - user_id = user_service.get_anonymous_user_id(username, unicode(self.runtime.course_id)) - if user_id is None: - self.raise_error(404, _("Could not find the specified username.")) + user_ids = [] + for username in usernames.split(','): + username = username.strip() + user_id = user_service.get_anonymous_user_id(username, unicode(self.runtime.course_id)) + if user_id: + user_ids.append(user_id) + if not user_ids: + self.raise_error(404, _("Could not find any of the specified usernames.")) if not root_block_id: root_block_id = self.scope_ids.usage_id @@ -317,7 +322,7 @@ def start_export(self, data, suffix=''): unicode(getattr(self.runtime, 'course_id', 'course_id')), root_block_id, block_types, - user_id, + user_ids, match_string, ) if async_result.ready(): diff --git a/problem_builder/public/js/instructor_tool.js b/problem_builder/public/js/instructor_tool.js index c1e9c8a7..1a4dc74c 100644 --- a/problem_builder/public/js/instructor_tool.js +++ b/problem_builder/public/js/instructor_tool.js @@ -225,7 +225,7 @@ function InstructorToolBlock(runtime, element) { var $deleteButton = $element.find('.data-export-delete'); var $blockTypes = $element.find("select[name='block_types']"); var $rootBlockId = $element.find("select[name='root_block_id']"); - var $username = $element.find("input[name='username']"); + var $usernames = $element.find("input[name='usernames']"); var $matchString = $element.find("input[name='match_string']"); var $resultTable = $element.find('.data-export-results'); @@ -335,7 +335,7 @@ function InstructorToolBlock(runtime, element) { data = { block_types: $blockTypes.val(), root_block_id: $rootBlockId.val(), - username: $username.val(), + usernames: $usernames.val(), match_string: $matchString.val() }; data = JSON.stringify(data); diff --git a/problem_builder/tasks.py b/problem_builder/tasks.py index 5a3380d8..8439d784 100644 --- a/problem_builder/tasks.py +++ b/problem_builder/tasks.py @@ -20,7 +20,7 @@ @task() -def export_data(course_id, source_block_id_str, block_types, user_id, match_string): +def export_data(course_id, source_block_id_str, block_types, user_ids, match_string): """ Exports student answers to all MCQ questions to a CSV file. """ @@ -64,8 +64,13 @@ def scan_for_blocks(block): # Collect results for each block in blocks_to_include for block in blocks_to_include: - results = _extract_data(course_key_str, block, user_id, match_string) - rows += results + if not user_ids: + results = _extract_data(course_key_str, block, None, match_string) + rows += results + else: + for user_id in user_ids: + results = _extract_data(course_key_str, block, user_id, match_string) + rows += results # Generate the CSV: filename = u"pb-data-export-{}.csv".format(time.strftime("%Y-%m-%d-%H%M%S", time.gmtime(start_timestamp))) diff --git a/problem_builder/templates/html/instructor_tool.html b/problem_builder/templates/html/instructor_tool.html index 8b579dc5..9420220c 100644 --- a/problem_builder/templates/html/instructor_tool.html +++ b/problem_builder/templates/html/instructor_tool.html @@ -9,8 +9,8 @@

{% trans "Filters" %}