Commit b2993702 by Will Daly

Merge pull request #159 from edx/will/anonymize-student-ids

Use anonymous student ID if available
parents 96d76652 14462cc4
...@@ -221,23 +221,6 @@ class OpenAssessmentBlock( ...@@ -221,23 +221,6 @@ class OpenAssessmentBlock(
help="Saved response submission for the current user." help="Saved response submission for the current user."
) )
def get_xblock_trace(self):
"""Uniquely identify this XBlock by context.
Every XBlock has a scope_ids, which is a NamedTuple describing
important contextual information. Per @nedbat, the usage_id attribute
uniquely identifies this block in this course, and the user_id uniquely
identifies this student. With the two of them, we can trace all the
interactions emanating from this interaction.
Useful for logging, debugging, and uniqueification.
"""
return (
unicode(self.scope_ids.usage_id),
unicode(self.scope_ids.user_id) if self.scope_ids.user_id is not None else None,
)
def get_student_item_dict(self): def get_student_item_dict(self):
"""Create a student_item_dict from our surrounding context. """Create a student_item_dict from our surrounding context.
...@@ -247,14 +230,19 @@ class OpenAssessmentBlock( ...@@ -247,14 +230,19 @@ class OpenAssessmentBlock(
(dict): The student item associated with this XBlock instance. This (dict): The student item associated with this XBlock instance. This
includes the student id, item id, and course id. includes the student id, item id, and course id.
""" """
item_id, student_id = self.get_xblock_trace() item_id = unicode(self.scope_ids.usage_id)
# This is not the real way course_ids should work, but this is a # This is not the real way course_ids should work, but this is a
# temporary expediency for LMS integratino # temporary expediency for LMS integratino
if hasattr(self, "xmodule_runtime"): if hasattr(self, "xmodule_runtime"):
course_id = self.xmodule_runtime.course_id course_id = self.xmodule_runtime.course_id
student_id = self.xmodule_runtime.anonymous_student_id
else: else:
course_id = "edX/Enchantment_101/April_1" course_id = "edX/Enchantment_101/April_1"
if self.scope_ids.user_id is None:
student_id = None
else:
student_id = unicode(self.scope_ids.user_id)
student_item_dict = dict( student_item_dict = dict(
student_id=student_id, student_id=student_id,
...@@ -278,11 +266,9 @@ class OpenAssessmentBlock( ...@@ -278,11 +266,9 @@ class OpenAssessmentBlock(
(Fragment): The HTML Fragment for this XBlock, which determines the (Fragment): The HTML Fragment for this XBlock, which determines the
general frame of the Open Ended Assessment Question. general frame of the Open Ended Assessment Question.
""" """
trace = self.get_xblock_trace()
ui_models = self._create_ui_models() ui_models = self._create_ui_models()
# All data we intend to pass to the front end. # All data we intend to pass to the front end.
context_dict = { context_dict = {
"xblock_trace": trace,
"title": self.title, "title": self.title,
"question": self.prompt, "question": self.prompt,
"rubric_criteria": self.rubric_criteria, "rubric_criteria": self.rubric_criteria,
...@@ -366,8 +352,6 @@ class OpenAssessmentBlock( ...@@ -366,8 +352,6 @@ class OpenAssessmentBlock(
if not context_dict: if not context_dict:
context_dict = {} context_dict = {}
context_dict["xblock_trace"] = self.get_xblock_trace()
if self.start: if self.start:
context_dict["formatted_start_date"] = self.start.strftime("%A, %B %d, %Y") context_dict["formatted_start_date"] = self.start.strftime("%A, %B %d, %Y")
context_dict["formatted_start_datetime"] = self.start.strftime("%A, %B %d, %Y %X") context_dict["formatted_start_datetime"] = self.start.strftime("%A, %B %d, %Y %X")
......
...@@ -94,6 +94,18 @@ class TestOpenAssessment(XBlockHandlerTestCase): ...@@ -94,6 +94,18 @@ class TestOpenAssessment(XBlockHandlerTestCase):
self.assertEqual(student_item['student_id'], '2') self.assertEqual(student_item['student_id'], '2')
self.assertIsInstance(student_item['item_id'], unicode) self.assertIsInstance(student_item['item_id'], unicode)
@scenario('data/basic_scenario.xml', user_id='Bob')
def test_use_xmodule_runtime(self, xblock):
# Prefer course ID and student ID provided by the XModule runtime
xblock.xmodule_runtime = Mock(
course_id='test_course',
anonymous_student_id='test_student'
)
student_item = xblock.get_student_item_dict()
self.assertEqual(student_item['course_id'], 'test_course')
self.assertEqual(student_item['student_id'], 'test_student')
class TestDates(XBlockHandlerTestCase): class TestDates(XBlockHandlerTestCase):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment