本文整理汇总了Python中oasis.lib.Courses2类的典型用法代码示例。如果您正苦于以下问题:Python Courses2类的具体用法?Python Courses2怎么用?Python Courses2使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Courses2类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: practice_choose_topic
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 = Courses2.get_course(course_id)
except KeyError:
course = None
abort(404)
try:
topics = Courses2.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 not user_id 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
)
示例2: cadmin_top
def cadmin_top(course_id):
""" Present top level course admin page """
course = Courses2.get_course(course_id)
if not course:
abort(404)
user_id = session['user_id']
is_sysadmin = check_perm(user_id, -1, 'sysadmin')
topics = Courses2.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
)
示例3: admin_course_save
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 = Courses2.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:
Courses2.reload_if_needed()
flash("Course changes saved!")
return redirect(url_for("admin_course", course_id=course_id))
course = Courses2.get_course(course_id)
course['size'] = len(Courses.get_users(course_id))
return redirect(url_for("admin_courses"))
示例4: cadmin_edittopics
def cadmin_edittopics(course_id):
""" Present a page to view and edit all topics, including hidden. """
course = None
try:
course = Courses2.get_course(course_id)
except KeyError:
abort(404)
if not course:
abort(404)
topics = Courses2.get_topics_list(course_id)
return render_template("courseadmin_edittopics.html", course=course, topics=topics)
示例5: cadmin_edit_topic
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: cadmin_assign_coord
def cadmin_assign_coord(course_id):
""" Set someone as course coordinator
"""
course = Courses2.get_course(course_id)
if not course:
abort(404)
if not "coord" in request.form:
abort(400)
new_uname = request.form["coord"]
# TODO: Sanitize username
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:
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))
示例7: cadmin_export_csv
def cadmin_export_csv(course_id, exam_id, group_id):
""" Send the group results as a CSV file """
course = Courses2.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))
group = Groups.Group(g_id=group_id)
output = Spreadsheets.exam_results_as_spreadsheet(course_id, group, exam_id)
response = make_response(output)
response.headers.add(
"Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=utf-8"
)
response.headers.add(
"Content-Disposition", 'attachment; filename="OASIS_%s_%s_Results.xlsx"' % (course["title"], exam["title"])
)
return response
示例8: cadmin_edit_exam
def cadmin_edit_exam(course_id, exam_id):
""" Provide a form to edit an assessment """
course = Courses2.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
)
示例9: cadmin_assign_coord
def cadmin_assign_coord(course_id):
""" Set someone as course coordinator
"""
cur_user = session['user_id']
course = Courses2.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))
示例10: cadmin_create_exam
def cadmin_create_exam(course_id):
""" Provide a form to create/edit a new assessment """
course = Courses2.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,
}
)
示例11: practice_choose_question
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
)
示例12: practice_do_question
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="?",
)
示例13: practice_mark_question
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
)
示例14: cadmin_exam_viewmarked
def cadmin_exam_viewmarked(course_id, exam_id, student_uid):
""" Show a student's marked assessment results """
course = Courses2.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
marktime = Exams.get_mark_time(exam_id, student_uid)
firstview = Exams.get_student_start_time(exam_id, student_uid)
submittime = Exams.get_submit_time(exam_id, student_uid)
try:
datemarked = General.human_date(marktime)
except AttributeError:
datemarked = None
try:
datefirstview = General.human_date(firstview)
except AttributeError:
datefirstview = None
try:
datesubmit = General.human_date(submittime)
except AttributeError:
datesubmit = None
user = Users2.get_user(student_uid)
if submittime and firstview:
taken = submittime-firstview
takenmins = (taken.seconds/60)
else:
takenmins = None
return render_template(
"cadmin_markedresult.html",
course=course,
exam=exam,
results=results,
examtotal=examtotal,
datesubmit=datesubmit,
datemarked=datemarked,
datefirstview=datefirstview,
taken=takenmins,
user=user,
status=status
)
示例15: cadmin_view_topic
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,
)