rename chapter/lesson
This commit is contained in:
@@ -92,6 +92,44 @@ def add_material_chapter(material_id, chapter_name, teacher_id):
|
||||
{'$push': {'chapters': {'chapter_name': chapter_name, 'lessons': []}}})
|
||||
return True
|
||||
|
||||
def rename_material_structure(material_id, is_chapter, chapter_name, lesson_name, new_name):
|
||||
mongo = current_app.extensions["mongo"]
|
||||
material = mongo.db.materials.find_one({'_id': ObjectId(material_id)})
|
||||
# 先检查是否存在
|
||||
if is_chapter:
|
||||
for chapter in material['chapters']:
|
||||
if chapter['chapter_name'] == chapter_name:
|
||||
break
|
||||
return False
|
||||
for chapter in material['chapters']:
|
||||
if chapter['chapter_name'] == new_name:
|
||||
return False
|
||||
else:
|
||||
for chapter in material['chapters']:
|
||||
if chapter['chapter_name'] == chapter_name:
|
||||
break
|
||||
return False
|
||||
for lesson in chapter['lessons']:
|
||||
if lesson['lesson_name'] == lesson_name:
|
||||
break
|
||||
for lesson in chapter['lessons']:
|
||||
if lesson['lesson_name'] == new_name:
|
||||
return False
|
||||
|
||||
if is_chapter:
|
||||
mongo.db.materials.update_one(
|
||||
{'_id': ObjectId(material_id)},
|
||||
{'$set': {'chapters.$[c].chapter_name': new_name}},
|
||||
array_filters=[{'c.chapter_name': chapter_name}]
|
||||
)
|
||||
else:
|
||||
mongo.db.materials.update_one(
|
||||
{'_id': ObjectId(material_id)},
|
||||
{'$set': {'chapters.$[c].lessons.$[l].lesson_name': new_name}},
|
||||
array_filters=[{'c.chapter_name': chapter_name}, {'l.lesson_name': lesson_name}]
|
||||
)
|
||||
return True
|
||||
|
||||
def delete_material_chapter_lesson(material_id, chapter_name, lesson_name, teacher_id):
|
||||
"""
|
||||
删除指定课程的课时。
|
||||
|
||||
Reference in New Issue
Block a user