本文整理汇总了Python中courseware.models.BaseStudentModuleHistory.get_history方法的典型用法代码示例。如果您正苦于以下问题:Python BaseStudentModuleHistory.get_history方法的具体用法?Python BaseStudentModuleHistory.get_history怎么用?Python BaseStudentModuleHistory.get_history使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类courseware.models.BaseStudentModuleHistory
的用法示例。
在下文中一共展示了BaseStudentModuleHistory.get_history方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_history_false_true
# 需要导入模块: from courseware.models import BaseStudentModuleHistory [as 别名]
# 或者: from courseware.models.BaseStudentModuleHistory import get_history [as 别名]
def test_get_history_false_true(self):
student_module = StudentModule.objects.all()
history = BaseStudentModuleHistory.get_history(student_module)
self.assertEquals(len(history), 3)
self.assertEquals({'type': 'csmh', 'order': 3}, json.loads(history[0].state))
self.assertEquals({'type': 'csmh', 'order': 2}, json.loads(history[1].state))
self.assertEquals({'type': 'csmh', 'order': 1}, json.loads(history[2].state))
示例2: test_get_history_true_false
# 需要导入模块: from courseware.models import BaseStudentModuleHistory [as 别名]
# 或者: from courseware.models.BaseStudentModuleHistory import get_history [as 别名]
def test_get_history_true_false(self):
student_module = StudentModule.objects.all()
history = BaseStudentModuleHistory.get_history(student_module)
self.assertEquals(len(history), 3)
self.assertEquals({"type": "csmhe", "order": 3}, json.loads(history[0].state))
self.assertEquals({"type": "csmhe", "order": 2}, json.loads(history[1].state))
self.assertEquals({"type": "csmhe", "order": 1}, json.loads(history[2].state))
示例3: test_show_answer_doesnt_write_to_csm
# 需要导入模块: from courseware.models import BaseStudentModuleHistory [as 别名]
# 或者: from courseware.models.BaseStudentModuleHistory import get_history [as 别名]
def test_show_answer_doesnt_write_to_csm(self):
self.basic_setup()
self.submit_question_answer('p1', {'2_1': u'Correct'})
# Now fetch the state entry for that problem.
student_module = StudentModule.objects.filter(
course_id=self.course.id,
student=self.student_user
)
# count how many state history entries there are
baseline = BaseStudentModuleHistory.get_history(student_module)
self.assertEqual(len(baseline), 3)
# now click "show answer"
self.show_question_answer('p1')
# check that we don't have more state history entries
csmh = BaseStudentModuleHistory.get_history(student_module)
self.assertEqual(len(csmh), 3)
示例4: get_history
# 需要导入模块: from courseware.models import BaseStudentModuleHistory [as 别名]
# 或者: from courseware.models.BaseStudentModuleHistory import get_history [as 别名]
def get_history(self, username, block_key, scope=Scope.user_state):
"""
Retrieve history of state changes for a given block for a given
student. We don't guarantee that history for many blocks will be fast.
If the specified block doesn't exist, raise :class:`~DoesNotExist`.
Arguments:
username: The name of the user whose history should be retrieved.
block_key: The key identifying which xblock history to retrieve.
scope (Scope): The scope to load data from.
Yields:
XBlockUserState entries for each modification to the specified XBlock, from latest
to earliest.
"""
if scope != Scope.user_state:
raise ValueError("Only Scope.user_state is supported")
student_modules = list(
student_module
for student_module, usage_id
in self._get_student_modules(username, [block_key])
)
if len(student_modules) == 0:
raise self.DoesNotExist()
history_entries = BaseStudentModuleHistory.get_history(student_modules)
# If no history records exist, raise an error
if not history_entries:
raise self.DoesNotExist()
for history_entry in history_entries:
state = history_entry.state
# If the state is serialized json, then load it
if state is not None:
state = json.loads(state)
# If the state is empty, then for the purposes of `get_history`, it has been
# deleted, and so we list that entry as `None`.
if state == {}:
state = None
block_key = history_entry.csm.module_state_key
block_key = block_key.map_into_course(
history_entry.csm.course_id
)
yield XBlockUserState(username, block_key, state, history_entry.created, scope)
示例5: test_get_history_false_false
# 需要导入模块: from courseware.models import BaseStudentModuleHistory [as 别名]
# 或者: from courseware.models.BaseStudentModuleHistory import get_history [as 别名]
def test_get_history_false_false(self):
student_module = StudentModule.objects.all()
history = BaseStudentModuleHistory.get_history(student_module)
self.assertEquals(len(history), 0)