本文整理汇总了Python中oasis.lib.DB.get_topic_for_qtemplate方法的典型用法代码示例。如果您正苦于以下问题:Python DB.get_topic_for_qtemplate方法的具体用法?Python DB.get_topic_for_qtemplate怎么用?Python DB.get_topic_for_qtemplate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oasis.lib.DB
的用法示例。
在下文中一共展示了DB.get_topic_for_qtemplate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_topic_position
# 需要导入模块: from oasis.lib import DB [as 别名]
# 或者: from oasis.lib.DB import get_topic_for_qtemplate [as 别名]
def test_topic_position(self):
""" Test putting qtemplates into topics and moving them around
"""
course_id = Courses.create("TEST101", "Test topic position logic", 1, 1)
topic1_id = Topics.create(course_id, "TESTTOPIC1", 1, 2)
topic2_id = Topics.create(course_id, "TESTTOPIC2", 3, 3)
qt1_id = DB.create_qt(1, "TESTQ1", "Test question 1", 0, 5.0, 1)
qt2_id = DB.create_qt(1, "TESTQ2", "Test question 2", 0, 4.1, 2, topic1_id)
DB.move_qt_to_topic(qt1_id, topic1_id)
self.assertEqual(DB.get_qtemplate_practice_pos(qt1_id), 0)
self.assertEqual(DB.get_qtemplate_practice_pos(qt2_id), 0)
self.assertEqual(DB.get_topic_for_qtemplate(qt1_id), topic1_id)
self.assertEqual(DB.get_topic_for_qtemplate(qt2_id), topic1_id)
DB.update_qt_practice_pos(qt1_id, 3)
DB.update_qt_practice_pos(qt2_id, 2)
self.assertEqual(DB.get_qtemplate_practice_pos(qt1_id), 3)
self.assertEqual(DB.get_qtemplate_practice_pos(qt2_id), 2)
self.assertEqual(DB.get_qtemplate_practice_pos(qt1_id), 3, "Broken cache?")
self.assertEqual(DB.get_qtemplate_practice_pos(qt2_id), 2, "Broken cache?")
DB.update_qt_practice_pos(qt1_id, 0)
DB.update_qt_practice_pos(qt2_id, -1)
self.assertEqual(DB.get_qtemplate_practice_pos(qt1_id), 0)
self.assertEqual(DB.get_qtemplate_practice_pos(qt2_id), -1)
self.assertEqual(DB.get_qtemplate_practice_pos(qt1_id), 0, "Broken cache?")
self.assertEqual(DB.get_qtemplate_practice_pos(qt2_id), -1, "Broken cache?")
qts = Topics.get_qts(topic1_id)
self.assertIn(qt1_id, qts)
self.assertIn(qt2_id, qts)
self.assertEqual(len(qts), 2)
DB.move_qt_to_topic(qt1_id, topic2_id)
qts = Topics.get_qts(topic1_id)
self.assertNotIn(qt1_id, qts)
self.assertIn(qt2_id, qts)
self.assertEqual(len(qts), 1)
示例2: test_create_qtemplate
# 需要导入模块: from oasis.lib import DB [as 别名]
# 或者: from oasis.lib.DB import get_topic_for_qtemplate [as 别名]
def test_create_qtemplate(self):
""" Test qtemplates creation
"""
qt1_id = DB.create_qt(1, "TESTQ1", "Test question 1", 0, 5.0, 1)
qt2_id = DB.create_qt(1, "TESTQ2", "Test question 2", 0, 4.1, 2)
self.assertIsInstance(qt1_id, int)
self.assertIsInstance(qt2_id, int)
qt1 = DB.get_qtemplate(qt1_id)
qt2 = DB.get_qtemplate(qt2_id)
self.assertEqual(qt1['title'], "TESTQ1")
self.assertEqual(qt2['title'], "TESTQ2")
self.assertEqual(qt1['description'], "Test question 1")
self.assertEqual(qt2['description'], "Test question 2")
course_id = Courses.create("TEST107", "Test create qtemplate", 1, 1)
topic1_id = Topics.create(course_id, "TESTTOPIC9", 1, 2)
qt3_id = DB.create_qt(1, "TESTQ3", "Test question 3", 0, 5.0, 1, topic1_id)
self.assertIsInstance(qt3_id, int)
qt3 = DB.get_qtemplate(qt3_id)
self.assertEqual(qt3['title'], "TESTQ3")
self.assertEqual(qt3['description'], "Test question 3")
self.assertEqual(DB.get_topic_for_qtemplate(qt3_id), topic1_id)
示例3: api_qedit2_get_qtemplate_json
# 需要导入模块: from oasis.lib import DB [as 别名]
# 或者: from oasis.lib.DB import get_topic_for_qtemplate [as 别名]
def api_qedit2_get_qtemplate_json(qt_id):
""" Present a list of qtemplates that are available for use in the exam."""
if 'user_id' not in session:
abort(401)
user_id = session['user_id']
topic_id = DB.get_topic_for_qtemplate(qt_id)
course_id = Topics.get_course_id(topic_id)
if not satisfy_perms(user_id, course_id, ("questionedit",)):
abort(401)
# test data while we're building the frontend
return jsonify(result={
'type': "qtemplate data",
'title': "Test QE2 Question",
'embed_id': "aaaaaaaaa3",
'maxscore': 3,
'pre_vars': [
{'id': 1, 'name': "a", 'type': 'List', 'value': "2,3,4,5,6,7"},
{'id': 2, 'name': "b", 'type': 'Range', 'value': "1-10"},
{'id': 3, 'name': "a1", 'type': 'Calculation', 'value': "$a+$b"},
{'id': 4, 'name': "a2", 'type': 'Calculation', 'value': "$a*$b"},
],
'qtext': "What is $a + $b ? <answer1>\nWhat is $a * $b? <answer2> ",
'answers': [
{'id': 1, 'source': 'Variable', 'value': '$a1', 'tolerance': 0, 'score': 1},
{'id': 2, 'source': 'Variable', 'value': '$a2', 'tolerance': 0, 'score': 1}
]
})