本文整理汇总了Python中oasis.lib.Courses.get_course方法的典型用法代码示例。如果您正苦于以下问题:Python Courses.get_course方法的具体用法?Python Courses.get_course怎么用?Python Courses.get_course使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oasis.lib.Courses
的用法示例。
在下文中一共展示了Courses.get_course方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: admin_course_save
# 需要导入模块: from oasis.lib import Courses [as 别名]
# 或者: from oasis.lib.Courses import get_course [as 别名]
def admin_course_save(course_id):
""" accept saved settings """
form = request.form
cancel_edit = form.get("cancel_edit", False)
if cancel_edit:
flash("Course edits cancelled")
return redirect(url_for("admin_courses"))
changed = False
course = Courses.get_course(course_id)
groups = Courses.get_groups(course_id)
for g_id, group in groups.iteritems():
if form.get('delgroup_%s' % g_id):
changed = True
flash("Removing group %s" % group.name, "info")
Courses.del_group(int(g_id), course_id)
if 'course_name' in form:
name = form['course_name']
if not name == course['name']:
changed = True
Courses.set_name(course_id, name)
if 'course_title' in form:
title = form['course_title']
if not title == course['title']:
changed = True
Courses.set_title(course_id, title)
if 'course_active' in form:
active = form['course_active']
if active == '1' or active == 1:
active = True
else:
active = False
if not (active == course['active']):
changed = True
Courses.set_active(course_id, active)
addbtn = form.get('group_addbtn')
if addbtn:
newgroup = form.get('addgroup', None)
if newgroup:
Courses.add_group(newgroup, course_id)
changed = True
group = Groups.Group(newgroup)
flash("Group %s added." % group.name)
if changed:
flash("Course changes saved!")
return redirect(url_for("admin_course", course_id=course_id))
course = Courses.get_course(course_id)
course['size'] = len(Courses.get_users(course_id))
return redirect(url_for("admin_courses"))
示例2: practice_choose_topic
# 需要导入模块: from oasis.lib import Courses [as 别名]
# 或者: from oasis.lib.Courses import get_course [as 别名]
def practice_choose_topic(course_id):
""" Present a list of topics for them to choose from the given course """
user_id = session['user_id']
try:
course = Courses.get_course(course_id)
except KeyError:
course = None
abort(404)
try:
topics = Courses.get_topics_list(course_id)
except KeyError:
topics = []
abort(404)
members = None
for topic in topics:
if topic['visibility'] == 2: # course only
if not members:
members = Courses.get_users(course_id)
if user_id not in members:
topics.remove(topic)
return render_template(
"practicecourse.html",
courses=Setup.get_sorted_courselist(),
canpreview=check_perm(user_id, course_id, "questionpreview"),
topics=topics,
course=course
)
示例3: cadmin_assign_coord
# 需要导入模块: from oasis.lib import Courses [as 别名]
# 或者: from oasis.lib.Courses import get_course [as 别名]
def cadmin_assign_coord(course_id):
""" Set someone as course coordinator
"""
cur_user = session['user_id']
course = Courses.get_course(course_id)
if not course:
abort(404)
if "coord" not in request.form:
abort(400)
new_uname = sanitize_username(request.form['coord'])
try:
new_uid = Users2.uid_by_uname(new_uname)
except KeyError:
flash("User '%s' Not Found" % new_uname)
else:
if not new_uid:
flash("User '%s' Not Found" % new_uname)
else:
L.info("courseadmin: user %s assigned as coordinator to course %s by %s" % (new_uid, course_id, cur_user))
Permissions.add_perm(new_uid, course_id, 3) # courseadmin
Permissions.add_perm(new_uid, course_id, 4) # coursecoord
flash("%s can now control the course." % (new_uname,))
return redirect(url_for('cadmin_config', course_id=course_id))
示例4: cadmin_create_exam
# 需要导入模块: from oasis.lib import Courses [as 别名]
# 或者: from oasis.lib.Courses import get_course [as 别名]
def cadmin_create_exam(course_id):
""" Provide a form to create/edit a new assessment """
course = Courses.get_course(course_id)
if not course:
abort(404)
topics = CourseAdmin.get_create_exam_q_list(course_id)
today = datetime.now()
return render_template(
"exam_edit.html",
course=course,
topics=topics,
# defaults
exam={
'id': 0,
'start_date': int(date_from_py2js(today)+86400000), # tomorrow
'end_date': int(date_from_py2js(today)+90000000), # tomorrow + hour
'start_hour': int(today.hour),
'end_hour': int(today.hour + 1),
'start_minute': int(today.minute),
'end_minute': int(today.minute),
'duration': 60,
'title': "Assessment",
'archived': 1
}
)
示例5: cadmin_edit_exam
# 需要导入模块: from oasis.lib import Courses [as 别名]
# 或者: from oasis.lib.Courses import get_course [as 别名]
def cadmin_edit_exam(course_id, exam_id):
""" Provide a form to edit an assessment """
course = Courses.get_course(course_id)
if not course:
abort(404)
exam = Exams.get_exam_struct(exam_id, course_id)
if not exam:
abort(404)
if not int(exam['cid']) == int(course_id):
flash("Assessment %s does not belong to this course." % int(exam_id))
return redirect(url_for('cadmin_top', course_id=course_id))
exam['start_date'] = int(date_from_py2js(exam['start']))
exam['end_date'] = int(date_from_py2js(exam['end']))
exam['start_hour'] = int(exam['start'].hour)
exam['end_hour'] = int(exam['end'].hour)
exam['start_minute'] = int(exam['start'].minute)
exam['end_minute'] = int(exam['end'].minute)
return render_template(
"exam_edit.html",
course=course,
exam=exam
)
示例6: cadmin_top
# 需要导入模块: from oasis.lib import Courses [as 别名]
# 或者: from oasis.lib.Courses import get_course [as 别名]
def cadmin_top(course_id):
""" Present top level course admin page """
course = Courses.get_course(course_id)
if not course:
abort(404)
user_id = session['user_id']
is_sysadmin = check_perm(user_id, -1, 'sysadmin')
topics = Courses.get_topics_list(course_id)
exams = [Exams.get_exam_struct(exam_id, course_id)
for exam_id in Courses.get_exams(course_id, prev_years=False)]
exams.sort(key=lambda y: y['start_epoch'], reverse=True)
groups = Courses.get_groups(course_id)
choosegroups = [group
for group in Groups.all_groups()
if group.id not in groups]
return render_template(
"courseadmin_top.html",
course=course,
topics=topics,
exams=exams,
choosegroups=choosegroups,
groups=groups,
is_sysadmin=is_sysadmin
)
示例7: practice_mark_question
# 需要导入模块: from oasis.lib import Courses [as 别名]
# 或者: from oasis.lib.Courses import get_course [as 别名]
def practice_mark_question(topic_id, question_id):
""" Mark the submitted question answers """
user_id = session['user_id']
course_id = Topics.get_course_id(topic_id)
if not course_id:
abort(404)
course = Courses.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_practice_pos(qt_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_pos, next_pos = Practice.get_next_prev_pos(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_pos=next_pos,
prev_pos=prev_pos
)
示例8: cadmin_exam_viewmarked
# 需要导入模块: from oasis.lib import Courses [as 别名]
# 或者: from oasis.lib.Courses import get_course [as 别名]
def cadmin_exam_viewmarked(course_id, exam_id, student_uid):
""" Show a student's marked assessment results """
course = Courses.get_course(course_id)
try:
exam = Exams.get_exam_struct(exam_id, course_id)
except KeyError:
exam = {}
abort(404)
results, examtotal = Assess.render_own_marked_exam(student_uid, exam_id)
if examtotal is False:
status = 0
else:
status = 1
mark_time = Exams.get_mark_time(exam_id, student_uid)
first_view = Exams.get_student_start_time(exam_id, student_uid)
submit_time = Exams.get_submit_time(exam_id, student_uid)
try:
datemarked = General.human_date(mark_time)
except AttributeError:
datemarked = None
try:
datefirstview = General.human_date(first_view)
except AttributeError:
datefirstview = None
try:
datesubmit = General.human_date(submit_time)
except AttributeError:
datesubmit = None
user = Users2.get_user(student_uid)
if submit_time and first_view:
taken = submit_time-first_view
taken_mins = (taken.seconds/60)
else:
taken_mins = None
return render_template(
"cadmin_markedresult.html",
course=course,
exam=exam,
results=results,
examtotal=examtotal,
datesubmit=datesubmit,
datemarked=datemarked,
datefirstview=datefirstview,
taken=taken_mins,
user=user,
status=status
)
示例9: cadmin_exam_results
# 需要导入模块: from oasis.lib import Courses [as 别名]
# 或者: from oasis.lib.Courses import get_course [as 别名]
def cadmin_exam_results(course_id, exam_id):
""" View the results of an assessment """
course = Courses.get_course(course_id)
if not course:
abort(404)
exam = Exams.get_exam_struct(exam_id, course_id)
if not exam:
abort(404)
if not int(exam['cid']) == int(course_id):
flash("Assessment %s does not belong to this course." % int(exam_id))
return redirect(url_for('cadmin_top', course_id=course_id))
exam['start_date'] = int(date_from_py2js(exam['start']))
exam['end_date'] = int(date_from_py2js(exam['end']))
exam['start_hour'] = int(exam['start'].hour)
exam['end_hour'] = int(exam['end'].hour)
exam['start_minute'] = int(exam['start'].minute)
exam['end_minute'] = int(exam['end'].minute)
groups = [Groups.Group(g_id=g_id)
for g_id
in Groups.active_by_course(course_id)]
results = {}
uids = set([])
totals = {}
for group in groups:
results[group.id] = Exams.get_marks(group, exam_id)
for user_id in results[group.id]:
uids.add(user_id)
if user_id not in totals:
totals[user_id] = 0.0
for qt, val in results[group.id][user_id].iteritems():
totals[user_id] += val['score']
questions = Exams.get_qts_list(exam_id)
users = {}
for uid in uids:
users[uid] = Users2.get_user(uid)
return render_template(
"cadmin_examresults.html",
course=course,
exam=exam,
results=results,
groups=groups,
users=users,
questions=questions,
when=datetime.now().strftime("%H:%m, %a %d %b %Y"),
totals=totals
)
示例10: setup_myprofile
# 需要导入模块: from oasis.lib import Courses [as 别名]
# 或者: from oasis.lib.Courses import get_course [as 别名]
def setup_myprofile():
""" Show an account summary for the current user account. """
user_id = session['user_id']
user = Users2.get_user(user_id)
course_ids = Users2.get_courses(user_id)
courses = []
for course_id in course_ids:
courses.append(Courses.get_course(course_id))
return render_template(
'setup_myprofile.html',
user=user,
courses=courses
)
示例11: cadmin_edittopics
# 需要导入模块: from oasis.lib import Courses [as 别名]
# 或者: from oasis.lib.Courses import get_course [as 别名]
def cadmin_edittopics(course_id):
""" Present a page to view and edit all topics, including hidden. """
course = None
try:
course = Courses.get_course(course_id)
except KeyError:
abort(404)
if not course:
abort(404)
topics = Courses.get_topics_list(course_id)
return render_template("courseadmin_edittopics.html",
course=course,
topics=topics)
示例12: admin_course
# 需要导入模块: from oasis.lib import Courses [as 别名]
# 或者: from oasis.lib.Courses import get_course [as 别名]
def admin_course(course_id):
""" Present page to administer settings for a given course"""
course = Courses.get_course(course_id)
course['size'] = len(Courses.get_users(course_id))
groups = Courses.get_groups(course_id)
choosegroups = [group
for g_id, group in Groups.enrolment_groups().iteritems()
if g_id not in groups]
return render_template(
"cadmin_course.html",
course=course,
groups=groups,
choosegroups=choosegroups
)
示例13: cadmin_activate
# 需要导入模块: from oasis.lib import Courses [as 别名]
# 或者: from oasis.lib.Courses import get_course [as 别名]
def cadmin_activate(course_id):
""" Mark the course as active
"""
course = None
try:
course = Courses.get_course(course_id)
except KeyError:
abort(404)
if not course:
abort(404)
Courses.set_active(course_id, True)
flash("Course %s marked as active" % (course['name']))
return redirect(url_for("cadmin_config", course_id=course_id))
示例14: cadmin_group_detach
# 需要导入模块: from oasis.lib import Courses [as 别名]
# 或者: from oasis.lib.Courses import get_course [as 别名]
def cadmin_group_detach(course_id, group_id):
""" Mark the course as inactive
"""
course = None
try:
course = Courses.get_course(course_id)
except KeyError:
abort(404)
if not course:
abort(404)
group = Groups.Group(g_id=group_id)
Courses.del_group(group_id, course_id)
flash("Group %s removed from course" % (group.name,))
return redirect(url_for("cadmin_config", course_id=course_id))
示例15: cadmin_edit_topic
# 需要导入模块: from oasis.lib import Courses [as 别名]
# 或者: from oasis.lib.Courses import get_course [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 = Courses.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 = [crse
for crse in Courses.get_course_list()
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
)