本文整理汇总了Python中oasis.lib.Topics.get_name方法的典型用法代码示例。如果您正苦于以下问题:Python Topics.get_name方法的具体用法?Python Topics.get_name怎么用?Python Topics.get_name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oasis.lib.Topics
的用法示例。
在下文中一共展示了Topics.get_name方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_topic
# 需要导入模块: from oasis.lib import Topics [as 别名]
# 或者: from oasis.lib.Topics import get_name [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)
示例2: practice_do_question
# 需要导入模块: from oasis.lib import Topics [as 别名]
# 或者: from oasis.lib.Topics import get_name [as 别名]
def practice_do_question(topic_id, qt_id):
""" Show them a question and allow them to fill in some answers """
user_id = session['user_id']
try:
course_id = Topics.get_course_id(topic_id)
except KeyError:
course_id = None
abort(404)
try:
course = Courses2.get_course(course_id)
except KeyError:
course = None
abort(404)
topictitle = "UNKNOWN"
try:
topictitle = Topics.get_name(topic_id)
except KeyError:
abort(404)
try:
qtemplate = DB.get_qtemplate(qt_id)
except KeyError:
qtemplate = None
abort(404)
questions = Practice.get_sorted_questions(course_id, topic_id, user_id)
q_title = qtemplate['title']
q_pos = DB.get_qtemplate_topic_pos(qt_id, topic_id)
blocked = Practice.is_q_blocked(user_id, course_id, topic_id, qt_id)
if blocked:
return render_template(
"practicequestionblocked.html",
mesg=blocked,
topictitle=topictitle,
topic_id=topic_id,
qt_id=qt_id,
course=course,
q_title=q_title,
questions=questions,
q_pos=q_pos,
)
try:
q_id = Practice.get_practice_q(qt_id, user_id)
except (ValueError, TypeError), err:
log(ERROR,
"ERROR 1001 (%s,%s) %s" % (qt_id, user_id, err))
return render_template(
"practicequestionerror.html",
mesg="Error generating question.",
topictitle=topictitle,
topic_id=topic_id,
qt_id=qt_id,
course=course,
q_title=q_title,
questions=questions,
q_pos="?",
)
示例3: practice_mark_question
# 需要导入模块: from oasis.lib import Topics [as 别名]
# 或者: from oasis.lib.Topics import get_name [as 别名]
def practice_mark_question(topic_id, question_id):
""" Mark the submitted question answersjust wa """
user_id = session['user_id']
course_id = Topics.get_course_id(topic_id)
if not course_id:
abort(404)
course = Courses2.get_course(course_id)
if not course:
abort(404)
topictitle = "UNKNOWN"
try:
topictitle = Topics.get_name(topic_id)
except KeyError:
abort(404)
qt_id = DB.get_q_parent(question_id)
q_title = DB.get_qt_name(qt_id)
questions = Practice.get_sorted_questions(course_id, topic_id, user_id)
q_pos = DB.get_qtemplate_topic_pos(qt_id, topic_id)
blocked = Practice.is_q_blocked(user_id, course_id, topic_id, qt_id)
if blocked:
return render_template(
"practicequestionblocked.html",
mesg=blocked,
topictitle=topictitle,
topic_id=topic_id,
qt_id=qt_id,
course=course,
q_title=q_title,
questions=questions,
q_pos=q_pos,
)
marking = Practice.mark_q(user_id, topic_id, question_id, request)
prev_id, next_id = Practice.get_next_prev(qt_id, topic_id)
return render_template(
"practicemarkquestion.html",
topictitle=topictitle,
topic_id=topic_id,
qt_id=qt_id,
course=course,
q_title=q_title,
questions=questions,
q_pos=q_pos,
q_id=question_id,
marking=marking,
next_id=next_id,
prev_id=prev_id
)
示例4: cadmin_view_qtemplate_history
# 需要导入模块: from oasis.lib import Topics [as 别名]
# 或者: from oasis.lib.Topics import get_name [as 别名]
def cadmin_view_qtemplate_history(course_id, topic_id, qt_id):
""" Show the practice history of the question template. """
if not course_id:
abort(404)
course = Courses2.get_course(course_id)
topic = {"id": topic_id, "position": Topics.get_pos(topic_id), "name": Topics.get_name(topic_id)}
qtemplate = DB.get_qtemplate(qt_id)
year = datetime.now().year
years = range(year, year - 6, -1)
return render_template(
"courseadmin_viewqtemplate.html", course=course, topic=topic, qtemplate=qtemplate, years=years
)
示例5: cadmin_edit_topic
# 需要导入模块: from oasis.lib import Topics [as 别名]
# 或者: from oasis.lib.Topics import get_name [as 别名]
def cadmin_edit_topic(course_id, topic_id):
""" Present a page to view and edit a topic, including adding/editing
questions and setting some parameters.
"""
user_id = session['user_id']
if not course_id:
abort(404)
course = Courses2.get_course(course_id)
topic = {
'id': topic_id,
'position': Topics.get_pos(topic_id),
'name': Topics.get_name(topic_id)
}
questions = [question
for question in Topics.get_qts(topic_id).values()]
for question in questions:
question['embed_id'] = DB.get_qt_embedid(question['id'])
if question['embed_id']:
question['embed_url'] = "%s/embed/question/%s/question.html" % \
(OaConfig.parentURL, question['embed_id'])
else:
question['embed_url'] = None
question['editor'] = DB.get_qt_editor(question['id'])
all_courses = Courses2.get_course_list()
all_courses = [crse
for crse in all_courses
if satisfy_perms(user_id, int(crse['id']),
("questionedit", "courseadmin",
"sysadmin"))]
all_courses.sort(lambda f, s: cmp(f['name'], s['name']))
all_course_topics = []
for crse in all_courses:
topics = Courses.get_topics_all(crse['id'], numq=False)
if topics:
all_course_topics.append({'course': crse['name'], 'topics': topics})
questions.sort(key=lambda k: k['position'])
return render_template(
"courseadmin_edittopic.html",
course=course,
topic=topic,
questions=questions,
all_course_topics=all_course_topics
)
示例6: practice_choose_question
# 需要导入模块: from oasis.lib import Topics [as 别名]
# 或者: from oasis.lib.Topics import get_name [as 别名]
def practice_choose_question(topic_id):
""" Present a list of questions for them to choose from the given topic """
user_id = session['user_id']
try:
course_id = Topics.get_course_id(topic_id)
except KeyError:
course_id = None
abort(404)
topics = []
try:
topics = Courses2.get_topics_list(course_id)
except KeyError:
abort(404)
try:
course = Courses2.get_course(course_id)
except KeyError:
course = None
abort(404)
topictitle = Topics.get_name(topic_id)
questions = Practice.get_sorted_questions(course_id, topic_id, user_id)
thistopic = Topics.get_topic(topic_id)
members = []
if thistopic['visibility'] == 2: # course only
if not members:
members = Courses.get_users(course_id)
if not user_id in members:
abort(404)
for topic in topics:
if topic['visibility'] == 2: # course only
if not members:
members = Courses.get_users(course_id)
if not user_id in members:
topics.remove(topic)
return render_template(
"practicetopic.html",
canpreview=check_perm(user_id, course_id, "questionpreview"),
topics=topics,
topic_id=topic_id,
course=course,
topictitle=topictitle,
questions=questions
)
示例7: cadmin_view_topic
# 需要导入模块: from oasis.lib import Topics [as 别名]
# 或者: from oasis.lib.Topics import get_name [as 别名]
def cadmin_view_topic(course_id, topic_id):
""" Present a page to view a topic, including basic stats """
user_id = session["user_id"]
if not course_id:
abort(404)
course = Courses2.get_course(course_id)
topic = {"id": topic_id, "position": Topics.get_pos(topic_id), "name": Topics.get_name(topic_id)}
questions = [question for question in Topics.get_qts(topic_id).values()]
for question in questions:
question["embed_id"] = DB.get_qt_embedid(question["id"])
if question["embed_id"]:
question["embed_url"] = "%s/embed/question/%s/question.html" % (OaConfig.parentURL, question["embed_id"])
else:
question["embed_url"] = None
question["editor"] = DB.get_qt_editor(question["id"])
all_courses = Courses2.get_course_list()
all_courses = [
crse
for crse in all_courses
if satisfy_perms(user_id, int(crse["id"]), ("questionedit", "courseadmin", "sysadmin"))
]
all_courses.sort(lambda f, s: cmp(f["name"], s["name"]))
all_course_topics = []
for crse in all_courses:
topics = Courses.get_topics_all(crse["id"], numq=False)
if topics:
all_course_topics.append({"course": crse["name"], "topics": topics})
questions.sort(key=lambda k: k["position"])
return render_template(
"courseadmin_viewtopic.html",
course=course,
topic=topic,
questions=questions,
all_course_topics=all_course_topics,
)
示例8: get_topic_list
# 需要导入模块: from oasis.lib import Topics [as 别名]
# 或者: from oasis.lib.Topics import get_name [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
示例9: practice_choose_question_stats
# 需要导入模块: from oasis.lib import Topics [as 别名]
# 或者: from oasis.lib.Topics import get_name [as 别名]
def practice_choose_question_stats(topic_id):
""" Present a list of questions for them to choose from the given topic,
and show some statistics on how they're doing.
"""
user_id = session['user_id']
course_id = Topics.get_course_id(topic_id)
if not course_id:
abort(404)
topics = Courses2.get_topics_list(course_id)
course = Courses2.get_course(course_id)
topictitle = Topics.get_name(topic_id)
questions = Practice.get_sorted_qlist_wstats(course_id, topic_id, user_id)
return render_template(
"practicetopicstats.html",
canpreview=check_perm(user_id, course_id, "questionpreview"),
topics=topics,
topic_id=topic_id,
course=course,
topictitle=topictitle,
questions=questions
)
示例10: do_topic_page_commands
# 需要导入模块: from oasis.lib import Topics [as 别名]
# 或者: from oasis.lib.Topics import get_name [as 别名]
def do_topic_page_commands(request, topic_id, user_id):
"""We've been asked to perform some operations on the Topic page.
Expecting form fields:
selected_QTID
position_QTID
name_QTID
where QTID is a question template id. May receive many.
new_position
new_name
new_type
select_cmd = 'copy' | 'move'
select_target = TOPICID of target topic
"""
form = request.form
mesg = []
# Make a list of all the commands to run
cmdlist = []
for command in request.form.keys():
(cmd, data) = command.split('_', 2)
value = form[command]
if not value == "none":
cmdlist += [{'cmd': cmd, 'data': data, 'value': value}]
# Now run them:
# Titles first
for command in [cmd for cmd in cmdlist if cmd['cmd'] == 'name']:
qid = int(command['data'])
title = command['value']
DB.update_qt_title(qid, title)
# Then positions
for command in [cmd for cmd in cmdlist if cmd['cmd'] == 'position']:
qtid = int(command['data'])
try:
position = int(command['value'])
except ValueError:
position = 0
DB.update_qt_pos(qtid, topic_id, position)
# Then commands on selected questions
target_cmd = form.get('target_cmd', None)
if target_cmd:
qtids = [int(cmd['data']) for cmd in cmdlist if cmd['cmd'] == 'select']
try:
target_topic = int(form.get('target_topic', 0))
except ValueError:
target_topic = None
if target_cmd == 'move':
if target_topic:
for qtid in qtids:
qt_title = DB.get_qt_name(qtid)
topic_title = Topics.get_name(target_topic)
flash("Moving %s to %s" % (qt_title, topic_title))
DB.move_qt_to_topic(qtid, target_topic)
Topics.flush_num_qs(topic_id)
Topics.flush_num_qs(target_topic)
if target_cmd == 'copy':
if target_topic:
for qtid in qtids:
qt_title = DB.get_qt_name(qtid)
topic_title = Topics.get_name(target_topic)
flash("Copying %s to %s" % (qt_title, topic_title))
newid = DB.copy_qt_all(qtid)
DB.add_qt_to_topic(newid, target_topic)
Topics.flush_num_qs(target_topic)
if target_cmd == 'hide':
for qtid in qtids:
position = DB.get_qtemplate_topic_pos(qtid, topic_id)
if position > 0: # If visible, make it hidden
DB.update_qt_pos(qtid, topic_id, -position)
title = DB.get_qt_name(qtid)
flash("Made '%s' Hidden" % title)
Topics.flush_num_qs(topic_id)
if target_cmd == 'show':
for qtid in qtids:
position = DB.get_qtemplate_topic_pos(qtid, topic_id)
if position == 0: # If hidden, make it visible
newpos = DB.get_qt_max_pos_in_topic(topic_id)
DB.update_qt_pos(qtid, topic_id, newpos + 1)
Topics.flush_num_qs(topic_id)
title = DB.get_qt_name(qtid)
flash("Made '%s' Visible" % title)
if position < 0: # If hidden, make it visible
DB.update_qt_pos(qtid, topic_id, -position)
Topics.flush_num_qs(topic_id)
title = DB.get_qt_name(qtid)
flash("Made '%s' Visible" % title)
if target_cmd == "export":
if len(qtids) < 1:
#.........这里部分代码省略.........
示例11: practice_do_question_id
# 需要导入模块: from oasis.lib import Topics [as 别名]
# 或者: from oasis.lib.Topics import get_name [as 别名]
def practice_do_question_id(topic_id, qt_id):
""" Show them a question and allow them to fill in some answers """
user_id = session['user_id']
try:
course_id = Topics.get_course_id(topic_id)
except KeyError:
course_id = None
abort(404)
try:
course = Courses2.get_course(course_id)
except KeyError:
course = None
abort(404)
topictitle = "UNKNOWN"
try:
topictitle = Topics.get_name(topic_id)
except KeyError:
abort(404)
qtemplate = DB.get_qtemplate(qt_id)
questions = Practice.get_sorted_questions(course_id, topic_id, user_id)
q_title = qtemplate['title']
q_pos = DB.get_qtemplate_topic_pos(qt_id, topic_id)
blocked = Practice.is_q_blocked(user_id, course_id, topic_id, qt_id)
if blocked:
return render_template(
"practicequestionblocked.html",
mesg=blocked,
topictitle=topictitle,
topic_id=topic_id,
qt_id=qt_id,
course=course,
q_title=q_title,
questions=questions,
q_pos=q_pos,
)
try:
q_id = Practice.get_practice_q(qt_id, user_id)
except (ValueError, TypeError) as err:
L.error("ERROR 1001 (%s,%s) %s" % (qt_id, user_id, err))
return render_template(
"practicequestionerror.html",
mesg="Error generating question.",
topictitle=topictitle,
topic_id=topic_id,
qt_id=qt_id,
course=course,
q_title=q_title,
questions=questions,
q_pos=q_pos,
)
if not q_id > 0:
L.error("ERROR 1002 (%s,%s) Question not generated" % (qt_id, user_id))
return render_template(
"practicequestionerror.html",
mesg="Error generating question.",
topictitle=topictitle,
topic_id=topic_id,
qt_id=qt_id,
course=course,
q_title=q_title,
questions=questions,
q_pos=q_pos,
)
q_body = General.render_q_html(q_id)
q_body = q_body.replace(r"\240", u" ") # TODO: why is this here?
return render_template(
"practicedoquestion.html",
q_body=q_body,
topictitle=topictitle,
topic_id=topic_id,
qt_id=qt_id,
course=course,
q_title=q_title,
questions=questions,
q_pos=q_pos,
q_id=q_id,
)
示例12: practice_do_question
# 需要导入模块: from oasis.lib import Topics [as 别名]
# 或者: from oasis.lib.Topics import get_name [as 别名]
def practice_do_question(topic_id, position):
""" Show them a question and allow them to fill in some answers """
user_id = session['user_id']
try:
course_id = Topics.get_course_id(topic_id)
except KeyError:
course_id = None
abort(404)
try:
course = Courses2.get_course(course_id)
except KeyError:
course = None
abort(404)
topictitle = "UNKNOWN"
try:
topictitle = Topics.get_name(topic_id)
except KeyError:
abort(404)
try:
choices = DB.get_qtemplates_in_topic_position(topic_id, position)
except KeyError:
choices = None
abort(404)
if len(choices) == 1:
qt_id = choices[0]
elif len(choices) > 1:
L.debug("Practice choosing random from: %s" % repr(choices))
qt_id = random.choice(choices)
else:
L.warn("Access to non existent practice topic %s question %s" % (topic_id, position))
return render_template(
"practicequestionerror.html",
mesg="Error accessing question.",
topic_id=topic_id,
course=course,
q_pos=position
)
qtemplate = DB.get_qtemplate(qt_id)
questions = Practice.get_sorted_questions(course_id, topic_id, user_id)
q_title = qtemplate['title']
q_pos = DB.get_qtemplate_topic_pos(qt_id, topic_id)
blocked = Practice.is_q_blocked(user_id, course_id, topic_id, qt_id)
if blocked:
return render_template(
"practicequestionblocked.html",
mesg=blocked,
topictitle=topictitle,
topic_id=topic_id,
qt_id=qt_id,
course=course,
q_title=q_title,
questions=questions,
q_pos=q_pos,
)
try:
q_id = Practice.get_practice_q(qt_id, user_id)
except (ValueError, TypeError) as err:
L.error("ERROR 1001 (%s,%s) %s" % (qt_id, user_id, err))
return render_template(
"practicequestionerror.html",
mesg="Error generating question.",
topictitle=topictitle,
topic_id=topic_id,
qt_id=qt_id,
course=course,
q_title=q_title,
questions=questions,
q_pos=q_pos,
)
if not q_id > 0:
L.error("ERROR 1002 (%s,%s) Question not generated" % (qt_id, user_id))
return render_template(
"practicequestionerror.html",
mesg="Error generating question.",
topictitle=topictitle,
topic_id=topic_id,
qt_id=qt_id,
course=course,
q_title=q_title,
questions=questions,
q_pos=q_pos,
)
q_body = General.render_q_html(q_id)
q_body = q_body.replace(r"\240", u" ") # TODO: why is this here?
return render_template(
"practicedoquestion.html",
q_body=q_body,
topictitle=topictitle,
topic_id=topic_id,
qt_id=qt_id,
course=course,
q_title=q_title,
#.........这里部分代码省略.........
示例13: do_topic_page_commands
# 需要导入模块: from oasis.lib import Topics [as 别名]
# 或者: from oasis.lib.Topics import get_name [as 别名]
def do_topic_page_commands(request, topic_id, user_id):
"""We've been asked to perform some operations on the Topic page.
Expecting form fields:
selected_QTID
position_QTID
name_QTID
where QTID is a question template id. May receive many.
new_position
new_name
new_type
select_cmd = 'copy' | 'move'
select_target = TOPICID of target topic
"""
form = request.form
files = request.files
mesg = []
# Make a list of all the commands to run
cmdlist = []
for command in request.form.keys():
if '_' in command:
(cmd, data) = command.split('_', 2)
value = form[command]
if not value == "none":
cmdlist += [{'cmd': cmd, 'data': data, 'value': value}]
# Now run them:
# Titles first
for command in [cmd for cmd in cmdlist if cmd['cmd'] == 'name']:
qid = int(command['data'])
title = command['value']
DB.update_qt_title(qid, title)
# Then positions
for command in [cmd for cmd in cmdlist if cmd['cmd'] == 'position']:
qtid = int(command['data'])
try:
position = int(command['value'])
except ValueError:
position = 0
DB.update_qt_practice_pos(qtid, position)
# Then commands on selected questions
target_cmd = form.get('target_cmd', None)
if target_cmd:
qtids = [int(cmd['data']) for cmd in cmdlist if cmd['cmd'] == 'select']
try:
target_topic = int(form.get('target_topic', 0))
except ValueError:
target_topic = None
if target_cmd == 'move':
if target_topic:
for qtid in qtids:
qt_title = DB.get_qt_name(qtid)
topic_title = Topics.get_name(target_topic)
flash("Moving %s to %s" % (qt_title, topic_title))
DB.move_qt_to_topic(qtid, target_topic)
Topics.flush_num_qs(target_topic)
if target_cmd == 'copy':
if target_topic:
for qtid in qtids:
qt_title = DB.get_qt_name(qtid)
topic_title = Topics.get_name(target_topic)
flash("Copying %s to %s" % (qt_title, topic_title))
position = DB.get_qtemplate_practice_pos(qtid)
newid = DB.copy_qt_all(qtid)
DB.move_qt_to_topic(newid, target_topic, position)
Topics.flush_num_qs(target_topic)
if target_cmd == 'hide':
for qtid in qtids:
position = DB.get_qtemplate_practice_pos(qtid)
if position > 0: # If visible, make it hidden
DB.update_qt_practice_pos(qtid, -position)
title = DB.get_qt_name(qtid)
flash("Made '%s' Hidden" % title)
if target_cmd == 'show':
for qtid in qtids:
position = DB.get_qtemplate_practice_pos(qtid)
if position == 0: # If hidden, make it visible
newpos = DB.get_qt_max_pos_in_topic(topic_id)
DB.update_qt_practice_pos(qtid, newpos + 1)
title = DB.get_qt_name(qtid)
flash("Made '%s' Visible" % title)
if position < 0: # If hidden, make it visible
DB.update_qt_practice_pos(qtid, -position)
title = DB.get_qt_name(qtid)
flash("Made '%s' Visible" % title)
if target_cmd == "export":
if len(qtids) < 1:
#.........这里部分代码省略.........