本文整理汇总了Python中oasis.lib.Topics.get_num_qs方法的典型用法代码示例。如果您正苦于以下问题:Python Topics.get_num_qs方法的具体用法?Python Topics.get_num_qs怎么用?Python Topics.get_num_qs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oasis.lib.Topics
的用法示例。
在下文中一共展示了Topics.get_num_qs方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_topics_all
# 需要导入模块: from oasis.lib import Topics [as 别名]
# 或者: from oasis.lib.Topics import get_num_qs [as 别名]
def get_topics_all(course, archived=2, numq=True):
""" Return a summary of all topics in the course.
if archived=0, only return non archived courses
if archived=1, only return archived courses
if archived=2, return all courses
if numq is true then include the number of questions in the topic
"""
ret = None
if archived == 0:
ret = run_sql("""SELECT topic, title, position, visibility, archived
FROM topics
WHERE course=%s
AND (archived='0' OR archived IS NULL)
ORDER BY position, topic;""", (course,))
elif archived == 1:
ret = run_sql("""SELECT topic, title, position, visibility, archived
FROM topics
WHERE course=%s
AND archived='1'
ORDER BY position, topic;""", (course,))
elif archived == 2:
ret = run_sql("""SELECT topic, title, position, visibility, 0
FROM topics
WHERE course=%s
ORDER BY position, topic;""", (course,))
info = {}
if ret:
count = 0
for row in ret:
info[count] = {'id': int(row[0]),
'title': row[1],
'position': row[2],
'visibility': row[3],
'archived': row[4]}
if info[count]['position'] is None or info[count]['position'] is "None":
info[count]['position'] = 0
if numq:
info[count]['numquestions'] = Topics.get_num_qs(int(row[0]))
count += 1
else: # we probably don't have the archived flag in the Db yet
ret = run_sql(
"""SELECT topic, title, position, visibility
FROM topics
WHERE course=%s
ORDER BY position, topic;""", (course,))
if ret:
count = 0
for row in ret:
info[count] = {'id': int(row[0]),
'title': row[1],
'position': row[2],
'visibility': row[3]}
if info[count]['position'] is None or info[count]['position'] is "None":
info[count]['position'] = 0
if numq:
info[count]['numquestions'] = Topics.get_num_qs(int(row[0]))
count += 1
return info
示例2: test_create_topic
# 需要导入模块: from oasis.lib import Topics [as 别名]
# 或者: from oasis.lib.Topics import get_num_qs [as 别名]
def test_create_topic(self):
""" Fetch a topic back and check it
"""
course_id = Courses.create("TEST101", "Test topic position logic", 1, 1)
self.assertDictContainsSubset(
{course_id:
{'active': 1,
'assess_visibility': 'enrol',
'id': course_id,
'name': 'TEST101',
'owner': 1,
'practice_visibility': 'all',
'title': 'Test topic position logic',
'type': 1
}
},
Courses.get_courses_dict(),
)
topic1_id = Topics.create(course_id, "TESTTOPIC1", 1, 2)
topic2_id = Topics.create(course_id, "TESTTOPIC2", 3, 3)
self.assertGreater(topic1_id, 0)
self.assertIsInstance(topic1_id, int)
self.assertGreater(topic2_id, 0)
self.assertIsInstance(topic2_id, int)
self.assertNotEqual(topic1_id, topic2_id)
topic1 = Topics.get_topic(topic1_id)
topic2 = Topics.get_topic(topic2_id)
self.assertEqual(topic1['id'], topic1_id)
self.assertEqual(topic2['id'], topic2_id)
self.assertEqual(topic1['title'], "TESTTOPIC1")
self.assertEqual(topic2['title'], "TESTTOPIC2")
self.assertEqual(topic1['visibility'], 1)
self.assertEqual(topic2['visibility'], 3)
self.assertEqual(Topics.get_name(topic1_id), topic1['title'])
Topics.set_name(topic1_id, "NEWNAME1")
self.assertEqual(Topics.get_name(topic1_id), "NEWNAME1")
self.assertEqual(Topics.get_num_qs(topic1_id), 0)
self.assertEqual(Topics.get_pos(topic1_id), 2)
Topics.set_pos(topic1_id, 8)
self.assertEqual(Topics.get_pos(topic1_id), 8)
示例3: get_topic_list
# 需要导入模块: from oasis.lib import Topics [as 别名]
# 或者: from oasis.lib.Topics import get_num_qs [as 别名]
def get_topic_list(cid, numq=True):
""" Return a list of dicts with topic information for the given course.
[{ tid: int Topic ID
name: string Name of Topic
num: int Number of questions (if numq is false, then None)
visibility: int Who can see the topic. 0 = Noone, 1 = Staff,
2 = Course, 3 = Student,
4 = Guest
},]
""" # TODO: magic numbers!
tlist = []
topics = Courses.get_topics(int(cid))
for topic in topics:
if numq:
num = Topics.get_num_qs(topic)
else:
num = None
tlist.append({'tid': topic,
'name': Topics.get_name(topic),
'num': num,
'visibility': Topics.get_vis(topic)})
return tlist