本文整理汇总了Python中oasis.lib.Courses.create方法的典型用法代码示例。如果您正苦于以下问题:Python Courses.create方法的具体用法?Python Courses.create怎么用?Python Courses.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oasis.lib.Courses
的用法示例。
在下文中一共展示了Courses.create方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_course_config
# 需要导入模块: from oasis.lib import Courses [as 别名]
# 或者: from oasis.lib.Courses import create [as 别名]
def test_course_config(self):
""" Test course configuration templates
"""
course1_id = Courses.create("TEMPL01", "Test course templates", 1, 1)
period = Periods.Period(name="TEMPL01",
title="Template 01",
start=datetime.datetime.now(),
finish=datetime.datetime.now(),
code="TMPL1"
)
period.save()
period2 = Periods.Period(code="TMPL1")
Courses.create_config(course1_id, "large", period2.id)
groups = Courses.get_groups(course1_id)
self.assertEqual(len(groups), 1)
course2_id = Courses.create("TEMPL02", "Test course standard", 1, 1)
Courses.create_config(course2_id, "standard", period2.id)
groups = Courses.get_groups(course2_id)
self.assertEqual(len(groups), 2)
course3_id = Courses.create("TEMPL03", "Test course demo", 1, 1)
Courses.create_config(course3_id, "demo", period2.id)
groups = Courses.get_groups(course3_id)
self.assertEqual(len(groups), 3)
self.assertListEqual(groups.keys(), [4, 5, 6])
self.assertEqual(groups[4].members(), [])
self.assertEqual(groups[5].members(), [])
self.assertEqual(groups[6].members(), [])
groups[4].add_member(1)
self.assertEqual(groups[4].members(), [1])
self.assertEqual(groups[5].members(), [])
self.assertEqual(groups[6].members(), [])
groups[4].add_member(1)
groups[5].add_member(1)
self.assertEqual(groups[4].members(), [1])
self.assertEqual(groups[5].members(), [1])
groups[4].remove_member(1)
self.assertEqual(groups[4].members(), [])
self.assertEqual(groups[5].members(), [1])
self.assertListEqual(groups[4].member_unames(), [])
self.assertListEqual(groups[5].member_unames(), ["admin"])
self.assertEqual(groups[4].size(), 0)
self.assertEqual(groups[5].size(), 1)
groups[5].flush_members()
self.assertEqual(groups[5].members(), [])
示例2: test_practice_course_list
# 需要导入模块: from oasis.lib import Courses [as 别名]
# 或者: from oasis.lib.Courses import create [as 别名]
def test_practice_course_list(self):
""" Check the list of courses is reasonably ok
:return:
"""
with self.app.test_client() as c:
self.login(ADMIN_UNAME, self.adminpass, client=c)
s = c.get('/practice/top', follow_redirects=True)
self.assertEqual(s.status, "200 OK")
self.assertIn("Choose A Course", s.data)
self.assertNotIn("TESTCOURSE1", s.data)
# create a course, set it visible, is it there?
course_id = Courses.create("TESTCOURSE1", "unit tests", 1, 1)
Courses.create_config(course_id, "casual", 1)
Courses.set_active(course_id, True)
Courses.set_prac_vis(course_id, "all")
s = c.get('/practice/top', follow_redirects=True)
self.assertEqual(s.status, "200 OK")
self.assertIn("Choose A Course", s.data)
self.assertIn("TESTCOURSE1", s.data)
self.assertNotIn("TESTCOURSE2", s.data)
# create a second course, set it visible, is it there?
course_id = Courses.create("TESTCOURSE2", "unit tests", 1, 1)
Courses.create_config(course_id, "casual", 1)
Courses.set_active(course_id, True)
Courses.set_prac_vis(course_id, "all")
s = c.get('/practice/top', follow_redirects=True)
self.assertEqual(s.status, "200 OK")
self.assertIn("Choose A Course", s.data)
self.assertIn("TESTCOURSE1", s.data)
self.assertIn("TESTCOURSE2", s.data)
# create a third course, set it not visible
course_id = Courses.create("TESTCOURSE3", "unit tests", 1, 1)
Courses.create_config(course_id, "casual", 1)
Courses.set_active(course_id, True)
Courses.set_prac_vis(course_id, "none")
s = c.get('/practice/top', follow_redirects=True)
self.assertEqual(s.status, "200 OK")
self.assertIn("Choose A Course", s.data)
self.assertIn("TESTCOURSE1", s.data)
self.assertIn("TESTCOURSE2", s.data)
# admin can still see it
self.assertIn("TESTCOURSE3", s.data)
示例3: test_assess_create
# 需要导入模块: from oasis.lib import Courses [as 别名]
# 或者: from oasis.lib.Courses import create [as 别名]
def test_assess_create(self):
""" Create an empty assessment"""
course_id = Courses.create("TESTCOURSE5", "unit tests for assessment", 1, 1)
Courses.create_config(course_id, "casual", 1)
Courses.set_active(course_id, True)
Courses.set_prac_vis(course_id, "none")
Courses.set_assess_vis(course_id, "none")
title = "Test Assessment 1"
atype = 2 # assignment
duration = 60
code = "123456"
instant = 1
instructions = "These are the instructions"
astart = datetime.datetime.utcnow()
aend = astart + datetime.timedelta(hours=2)
exam_id = Exams.create(course_id, 1, title, atype, duration, astart,
aend, instructions, code=code, instant=instant)
self.assertGreater(exam_id, 0)
topic1_id = Topics.create(course_id, "TESTASSESS1", 1, 1)
self.assertGreater(topic1_id, 0)
data = open(self.test_question_fname).read()
numread = External.import_qts_from_zip(data, topic1_id)
self.assertEqual(numread, 3)
示例4: test_practice_topic_list
# 需要导入模块: from oasis.lib import Courses [as 别名]
# 或者: from oasis.lib.Courses import create [as 别名]
def test_practice_topic_list(self):
with self.app.test_client() as c:
self.login(ADMIN_UNAME, self.adminpass, client=c)
s = c.get('/practice/top', follow_redirects=True)
self.assertEqual(s.status, "200 OK")
self.assertIn("Choose A Course", s.data)
self.assertNotIn("TESTCOURSE10", s.data)
course_id = Courses.create("TESTCOURSE10", "unit tests", 1, 1)
Courses.create_config(course_id, "casual", 1)
Courses.set_active(course_id, True)
Courses.set_prac_vis(course_id, "all")
s = c.get('/practice/top', follow_redirects=True)
self.assertEqual(s.status, "200 OK")
self.assertIn("Choose A Course", s.data)
self.assertIn("TESTCOURSE10", s.data)
s = c.get('/practice/coursequestions/%s' % course_id)
self.assertIn("<h2>TESTCOURSE10 (unit tests)</h2>", s.data)
self.assertIn("Select a Topic", s.data)
示例5: test_do_question
# 需要导入模块: from oasis.lib import Courses [as 别名]
# 或者: from oasis.lib.Courses import create [as 别名]
def test_do_question(self):
""" Do a question"""
course_id = Courses.create("TEST102", "Test question logic", 1, 1)
self.assertGreater(course_id, 0)
topic1_id = Topics.create(course_id, "TESTQUESTIONS1", 1, 2)
self.assertGreater(topic1_id, 0)
qt1_id = DB.create_qt(1, "TESTQ9", "Test question 9", 0, 5.0, 1, topic_id=topic1_id)
self.assertIsNotNone(qt1_id)
ver = DB.get_qt_version(qt1_id)
self.assertGreater(ver, 0)
data = "2\n|1\n|2\n"
qvars = [{'A1': "2"}, {'A1': "3"}]
for row in range(0, len(qvars)):
DB.add_qt_variation(qt1_id, row + 1, qvars[row], ver)
DB.create_qt_att(qt1_id, "datfile.dat", "text/plain", data , ver)
DB.create_qt_att(qt1_id, "qtemplate.html", "text/html", "What is <VAL A1>? <ANSWER 1>", ver)
q_id = DB.get_q_by_qt_student(qt1_id, 1)
self.assertFalse(q_id) # Not generated yet
q_id = General.gen_q(qt1_id, 1)
self.assertGreater(q_id, 0)
q_id = DB.get_q_by_qt_student(qt1_id, 1)
self.assertTrue(qt1_id) # Better be there now
DB.update_qt_maxscore(qt1_id, 7.0)
score = DB.get_qt_maxscore(qt1_id)
self.assertEqual(score, 7.0)
DB.set_q_viewtime(q_id)
self.assertIsNotNone(DB.get_q_viewtime(q_id))
示例6: test_create_qtemplate
# 需要导入模块: from oasis.lib import Courses [as 别名]
# 或者: from oasis.lib.Courses import create [as 别名]
def test_create_qtemplate(self):
""" Test qtemplates creation
"""
qt1_id = DB.create_qt(1, "TESTQ1", "Test question 1", 0, 5.0, 1)
qt2_id = DB.create_qt(1, "TESTQ2", "Test question 2", 0, 4.1, 2)
self.assertIsInstance(qt1_id, int)
self.assertIsInstance(qt2_id, int)
qt1 = DB.get_qtemplate(qt1_id)
qt2 = DB.get_qtemplate(qt2_id)
self.assertEqual(qt1['title'], "TESTQ1")
self.assertEqual(qt2['title'], "TESTQ2")
self.assertEqual(qt1['description'], "Test question 1")
self.assertEqual(qt2['description'], "Test question 2")
course_id = Courses.create("TEST107", "Test create qtemplate", 1, 1)
topic1_id = Topics.create(course_id, "TESTTOPIC9", 1, 2)
qt3_id = DB.create_qt(1, "TESTQ3", "Test question 3", 0, 5.0, 1, topic1_id)
self.assertIsInstance(qt3_id, int)
qt3 = DB.get_qtemplate(qt3_id)
self.assertEqual(qt3['title'], "TESTQ3")
self.assertEqual(qt3['description'], "Test question 3")
self.assertEqual(DB.get_topic_for_qtemplate(qt3_id), topic1_id)
示例7: test_import_questions
# 需要导入模块: from oasis.lib import Courses [as 别名]
# 或者: from oasis.lib.Courses import create [as 别名]
def test_import_questions(self):
""" Import the questions made in export_questions"""
course_id = Courses.create("TEST103", "Test import questions", 1, 1)
self.assertGreater(course_id, 0)
topic1_id = Topics.create(course_id, "TESTQUESTIONS1", 1, 2)
self.assertGreater(topic1_id, 0)
data = open(self.test_question_fname).read()
numread = External.import_qts_from_zip(data, topic1_id)
self.assertEqual(numread, 3)
示例8: test_create_topic
# 需要导入模块: from oasis.lib import Courses [as 别名]
# 或者: from oasis.lib.Courses import create [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)
示例9: test_export_questions
# 需要导入模块: from oasis.lib import Courses [as 别名]
# 或者: from oasis.lib.Courses import create [as 别名]
def test_export_questions(self):
""" Make some questions and export them."""
course_id = Courses.create("TEST106", "Test Question Export", 1, 1)
self.assertGreater(course_id, 0)
topic1_id = Topics.create(course_id, "TESTEXPORT1", 1, 2)
self.assertGreater(topic1_id, 0)
qt1_id = DB.create_qt(1, "TESTQ1", "Test question 1", 0, 5.0, 1, topic_id=topic1_id)
self.assertIsNotNone(qt1_id)
ver = DB.get_qt_version(qt1_id)
self.assertGreater(ver, 0)
data = "2\n|1\n|2\n"
qvars = [{'A1': "2"}, {'A1': "3"}]
for row in range(0, len(qvars)):
DB.add_qt_variation(qt1_id, row + 1, qvars[row], ver)
DB.create_qt_att(qt1_id, "datfile.dat", "text/plain", data, ver)
DB.create_qt_att(qt1_id, "qtemplate.html", "text/html", "What is <VAL A1>? <ANSWER 1>", ver)
qt2_id = DB.create_qt(1, "TESTQ2", "Test question 2", 0, 5.0, 1, topic_id=topic1_id)
self.assertIsNotNone(qt2_id)
ver = DB.get_qt_version(qt2_id)
self.assertGreater(ver, 0)
data = "2\n|6\n|7\n"
qvars = [{'A1': "6"}, {'A1': "7"}]
for row in range(0, len(qvars)):
DB.add_qt_variation(qt2_id, row + 1, qvars[row], ver)
DB.create_qt_att(qt2_id, "datfile.dat", "text/plain", data, ver)
DB.create_qt_att(qt2_id, "qtemplate.html", "text/html", "Question 2: What is <VAL A1>? <ANSWER 1>", ver)
qt3_id = DB.create_qt(1, "TESTQ3", "Test question 3", 0, 5.0, 1, topic_id=topic1_id)
self.assertIsNotNone(qt3_id)
ver = DB.get_qt_version(qt3_id)
self.assertGreater(ver, 0)
data = "3\n|9\n|10\n|11\n"
qvars = [{'A1': "9"}, {'A1': "10"}, {'A1': "11"}]
for row in range(0, len(qvars)):
DB.add_qt_variation(qt3_id, row + 1, qvars[row], ver)
DB.create_qt_att(qt3_id, "datfile.dat", "text/plain", data, ver)
DB.create_qt_att(qt3_id, "qtemplate.html", "text/html", "Question 3: What is <VAL A1>? <ANSWER 1>", ver)
data = External.topic_to_zip(topic1_id)
f = open("%s" % self.test_question_fname, mode='w')
f.write(data)
f.close()
示例10: test_topic_position
# 需要导入模块: from oasis.lib import Courses [as 别名]
# 或者: from oasis.lib.Courses import create [as 别名]
def test_topic_position(self):
""" Test putting qtemplates into topics and moving them around
"""
course_id = Courses.create("TEST101", "Test topic position logic", 1, 1)
topic1_id = Topics.create(course_id, "TESTTOPIC1", 1, 2)
topic2_id = Topics.create(course_id, "TESTTOPIC2", 3, 3)
qt1_id = DB.create_qt(1, "TESTQ1", "Test question 1", 0, 5.0, 1)
qt2_id = DB.create_qt(1, "TESTQ2", "Test question 2", 0, 4.1, 2, topic1_id)
DB.move_qt_to_topic(qt1_id, topic1_id)
self.assertEqual(DB.get_qtemplate_practice_pos(qt1_id), 0)
self.assertEqual(DB.get_qtemplate_practice_pos(qt2_id), 0)
self.assertEqual(DB.get_topic_for_qtemplate(qt1_id), topic1_id)
self.assertEqual(DB.get_topic_for_qtemplate(qt2_id), topic1_id)
DB.update_qt_practice_pos(qt1_id, 3)
DB.update_qt_practice_pos(qt2_id, 2)
self.assertEqual(DB.get_qtemplate_practice_pos(qt1_id), 3)
self.assertEqual(DB.get_qtemplate_practice_pos(qt2_id), 2)
self.assertEqual(DB.get_qtemplate_practice_pos(qt1_id), 3, "Broken cache?")
self.assertEqual(DB.get_qtemplate_practice_pos(qt2_id), 2, "Broken cache?")
DB.update_qt_practice_pos(qt1_id, 0)
DB.update_qt_practice_pos(qt2_id, -1)
self.assertEqual(DB.get_qtemplate_practice_pos(qt1_id), 0)
self.assertEqual(DB.get_qtemplate_practice_pos(qt2_id), -1)
self.assertEqual(DB.get_qtemplate_practice_pos(qt1_id), 0, "Broken cache?")
self.assertEqual(DB.get_qtemplate_practice_pos(qt2_id), -1, "Broken cache?")
qts = Topics.get_qts(topic1_id)
self.assertIn(qt1_id, qts)
self.assertIn(qt2_id, qts)
self.assertEqual(len(qts), 2)
DB.move_qt_to_topic(qt1_id, topic2_id)
qts = Topics.get_qts(topic1_id)
self.assertNotIn(qt1_id, qts)
self.assertIn(qt2_id, qts)
self.assertEqual(len(qts), 1)
示例11: test_topic_nextprev
# 需要导入模块: from oasis.lib import Courses [as 别名]
# 或者: from oasis.lib.Courses import create [as 别名]
def test_topic_nextprev(self):
""" Do the "next/previous" options in practice work?
"""
course_id = Courses.create("TEST101", "Test topic next/prev logic", 1, 1)
topic1_id = Topics.create(course_id, "TESTTOPIC1", 1, 2)
qt1_id = DB.create_qt(1, "TESTQ1", "Test question 1", 0, 5.0, 1)
qt2_id = DB.create_qt(1, "TESTQ2", "Test question 2", 0, 4.1, 2)
qt3_id = DB.create_qt(1, "TESTQ3", "Test question 3", 0, 0.0, 2)
qt4_id = DB.create_qt(1, "TESTQ4", "Test question 4", 0, 2.0, 2)
DB.move_qt_to_topic(qt1_id, topic1_id)
DB.move_qt_to_topic(qt2_id, topic1_id)
DB.move_qt_to_topic(qt3_id, topic1_id)
DB.move_qt_to_topic(qt4_id, topic1_id)
DB.update_qt_practice_pos(qt1_id, 1)
DB.update_qt_practice_pos(qt2_id, 2)
DB.update_qt_practice_pos(qt3_id, 3)
DB.update_qt_practice_pos(qt4_id, 4)
qts = Topics.get_qts(topic1_id)
self.assertIn(qt1_id, qts)
self.assertIn(qt2_id, qts)
self.assertIn(qt3_id, qts)
self.assertIn(qt4_id, qts)
self.assertEqual(len(qts), 4)
self.assertTupleEqual(Practice.get_next_prev_pos(qt1_id, topic1_id), (None, 2))
self.assertTupleEqual(Practice.get_next_prev_pos(qt2_id, topic1_id), (1, 3))
self.assertTupleEqual(Practice.get_next_prev_pos(qt3_id, topic1_id), (2, 4))
self.assertTupleEqual(Practice.get_next_prev_pos(qt4_id, topic1_id), (3, None))
DB.update_qt_practice_pos(qt2_id, 3)
self.assertEqual(DB.get_qtemplate_practice_pos(qt1_id), 1)
self.assertEqual(DB.get_qtemplate_practice_pos(qt2_id), 3)
self.assertEqual(DB.get_qtemplate_practice_pos(qt3_id), 3)
self.assertEqual(DB.get_qtemplate_practice_pos(qt4_id), 4)
self.assertTupleEqual(Practice.get_next_prev_pos(qt1_id, topic1_id), (None, 3))
self.assertTupleEqual(Practice.get_next_prev_pos(qt2_id, topic1_id), (1, 4))
self.assertTupleEqual(Practice.get_next_prev_pos(qt3_id, topic1_id), (1, 4))
self.assertTupleEqual(Practice.get_next_prev_pos(qt4_id, topic1_id), (3, None))
self.assertTupleEqual(Practice.get_next_prev_pos(qt4_id, None), (None, None))
示例12: cadmin_add_course_save
# 需要导入模块: from oasis.lib import Courses [as 别名]
# 或者: from oasis.lib.Courses import create [as 别名]
def cadmin_add_course_save():
""" accept saved settings for a new course"""
user_id = session["user_id"]
form = request.form
if "cancel_edit" in form:
flash("Course creation cancelled")
return redirect(url_for("setup_courses"))
if not "save_changes" in form:
abort(400)
if not "name" in form:
flash("You must give the course a name!")
return redirect(url_for("cadmin_add_course"))
if not "title" in form:
flash("You must give the course a title!")
return redirect(url_for("cadmin_add_course"))
name = form.get("name", "")
title = form.get("title", "")
coursetemplate = form.get("coursetemplate", "casual")
courserepeat = form.get("courserepeat", "eternal")
course = {"name": name, "title": title, "coursetemplate": coursetemplate, "courserepeat": courserepeat}
if len(name) < 1:
flash("You must give the course a name!")
return render_template("cadmin_add_course.html", course=course)
existing = Courses.get_course_by_name(name)
if existing:
flash("There is already a course called %(name)s" % existing)
return render_template("cadmin_add_course.html", course=course)
if len(title) < 1:
flash("You must give the course a title!")
return render_template("cadmin_add_course.html", course=course)
course_id = Courses.create(name, title, user_id, 1)
if not course_id:
flash("Error Adding Course!")
return render_template("cadmin_add_course.html", course=course)
Courses.create_config(course_id, coursetemplate, int(courserepeat))
flash("Course %s added!" % name)
return redirect(url_for("cadmin_top", course_id=course_id))
示例13: create_exported_questions
# 需要导入模块: from oasis.lib import Courses [as 别名]
# 或者: from oasis.lib.Courses import create [as 别名]
def create_exported_questions(fname):
""" Make some questions and export them."""
# Not really related to assessment, but can use this to create some questions to import and use multiple times
course_id = Courses.create("TEST106", "Test Question Export", 1, 1)
topic1_id = Topics.create(course_id, "TESTEXPORT1", 1, 2)
qt1_id = DB.create_qt(1, "TESTQ1", "Test question 1", 0, 5.0, 1, topic_id=topic1_id)
ver = DB.get_qt_version(qt1_id)
data = "2\n|1\n|2\n"
qvars = [{'A1': "2"}, {'A1': "3"}]
for row in range(0, len(qvars)):
DB.add_qt_variation(qt1_id, row + 1, qvars[row], ver)
DB.create_qt_att(qt1_id, "datfile.dat", "text/plain", data, ver)
DB.create_qt_att(qt1_id, "qtemplate.html", "text/html", "What is <VAL A1>? <ANSWER 1>", ver)
qt2_id = DB.create_qt(1, "TESTQ2", "Test question 2", 0, 5.0, 1, topic_id=topic1_id)
ver = DB.get_qt_version(qt2_id)
data = "2\n|6\n|7\n"
qvars = [{'A1': "6"}, {'A1': "7"}]
for row in range(0, len(qvars)):
DB.add_qt_variation(qt2_id, row + 1, qvars[row], ver)
DB.create_qt_att(qt2_id, "datfile.dat", "text/plain", data, ver)
DB.create_qt_att(qt2_id, "qtemplate.html", "text/html", "Question 2: What is <VAL A1>? <ANSWER 1>", ver)
qt3_id = DB.create_qt(1, "TESTQ3", "Test question 3", 0, 5.0, 1, topic_id=topic1_id)
ver = DB.get_qt_version(qt3_id)
data = "3\n|9\n|10\n|11\n"
qvars = [{'A1': "9"}, {'A1': "10"}, {'A1': "11"}]
for row in range(0, len(qvars)):
DB.add_qt_variation(qt3_id, row + 1, qvars[row], ver)
DB.create_qt_att(qt3_id, "datfile.dat", "text/plain", data, ver)
DB.create_qt_att(qt3_id, "qtemplate.html", "text/html", "Question 3: What is <VAL A1>? <ANSWER 1>", ver)
data = External.topic_to_zip(topic1_id)
f = open("%s" % fname, mode='w')
f.write(data)
f.close()
示例14: cadmin_add_course_save
# 需要导入模块: from oasis.lib import Courses [as 别名]
# 或者: from oasis.lib.Courses import create [as 别名]
def cadmin_add_course_save():
""" accept saved settings for a new course"""
user_id = session['user_id']
form = request.form
if 'cancel_edit' in form:
flash("Course creation cancelled")
return redirect(url_for("setup_courses"))
if 'save_changes' not in form:
abort(400)
if 'name' not in form:
flash("You must give the course a name!")
return redirect(url_for("cadmin_add_course"))
if 'title' not in form:
flash("You must give the course a title!")
return redirect(url_for("cadmin_add_course"))
name = form.get('name', '')
title = form.get('title', '')
coursetemplate = form.get('coursetemplate', 'casual')
courserepeat = form.get('courserepeat', 1)
course = {
'name': name,
'title': title,
'coursetemplate': coursetemplate,
'courserepeat': courserepeat
}
if len(name) < 1:
flash("You must give the course a name!")
return render_template(
"cadmin_add_course.html",
course=course
)
existing = Courses.get_course_by_name(name)
if existing:
flash("There is already a course called %(name)s" % existing)
return render_template(
"cadmin_add_course.html",
course=course
)
if len(title) < 1:
flash("You must give the course a title!")
return render_template(
"cadmin_add_course.html",
course=course
)
course_id = Courses.create(name, title, user_id, 1)
if not course_id:
flash("Error Adding Course!")
return render_template(
"cadmin_add_course.html",
course=course
)
Courses.create_config(course_id, coursetemplate, int(courserepeat))
flash("Course %s added!" % name)
return redirect(url_for("cadmin_top", course_id=course_id))