本文整理汇总了Python中oasis.lib.DB.get_qt_num_variations方法的典型用法代码示例。如果您正苦于以下问题:Python DB.get_qt_num_variations方法的具体用法?Python DB.get_qt_num_variations怎么用?Python DB.get_qt_num_variations使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oasis.lib.DB
的用法示例。
在下文中一共展示了DB.get_qt_num_variations方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gen_q
# 需要导入模块: from oasis.lib import DB [as 别名]
# 或者: from oasis.lib.DB import get_qt_num_variations [as 别名]
def gen_q(qtid, student=0, exam=0, position=0):
""" Given a qtemplate, will generate a question instance.
If student and/or exam is supplied it will be assigned appropriately.
If exam is supplied, position must also be supplied.
Will return the ID of the created instance.
"""
# Pick a variation randomly
version = DB.get_qt_version(qtid)
numvars = DB.get_qt_num_variations(qtid, version)
if numvars > 0:
variation = random.randint(1, numvars)
else:
L.warn("No question variations (qtid=%d)" % qtid)
return False
return gen_q_from_var(qtid, student, exam, position, version, variation)
示例2: gen_q
# 需要导入模块: from oasis.lib import DB [as 别名]
# 或者: from oasis.lib.DB import get_qt_num_variations [as 别名]
def gen_q(qtid, student=0, exam=0, position=0, variation=None):
""" Given a qtemplate, will generate a question instance.
If student and/or exam is supplied it will be assigned appropriately.
If exam is supplied, position must also be supplied.
Will return the ID of the created instance.
"""
# Pick a variation randomly if not supplied
version = DB.get_qt_version(qtid)
numvars = DB.get_qt_num_variations(qtid, version)
if variation is None and numvars > 0:
variation = random.randint(1, numvars)
if numvars == 0:
L.warn("No question variations (qtid=%d)" % qtid)
Audit.audit(3, student, qtid, "General", "Failed to generate question %s for %s, exam %s" % (qtid, student, exam))
return False
q_id = gen_q_from_var(qtid, student, exam, position, version, variation)
if not q_id:
Audit.audit(3, student, qtid, "General", "Failed to generate instance of %s for %s, exam %s" % (qtid, student, exam))
return q_id