def updateCidBylessonid(cid): data = request.get_json(force=True) courseid = int(cid) # step1 reset courseid to 0 for current all lesson # courseid = 0 , it mean no correlation for this lesson for lesson in LessonModel.GetLessonsByCourseid(courseid): LessonModel.UpdateCidByLid(0, lesson['id']) # step2 update courseid according to lessonid for lid in data['corLessonids']: errcode = LessonModel.UpdateCidByLid(courseid, int(lid)) return utils.jsonresp(jsonobj={'errcode': errcode})
def get_lessons(): limit = int(request.args.get('limit')) page = int(request.args.get('page')) name = request.args.get('lessonname') if name: total, lessons = LessonModel.SearchLessonByName(page, limit, name) else: total, lessons = LessonModel.GetLessons(page, limit) return utils.jsonresp(jsonobj={ 'total': total, 'limit': limit, 'lessons': lessons })
def delete_lessons(names): errcode = 0 #nameList = names.split(',') for name in names.split(','): ret = LessonModel.DeleteLessonByname(name) if ret != 0: errcode = 1 return utils.jsonresp(jsonobj={'errcode': errcode})
def get_courses(): limit = int(request.args.get('limit')) page = int(request.args.get('page')) name = request.args.get('name') if name: total, courses = CourseModel.SearchCourseByName(page, limit, name) else: total, courses = CourseModel.GetCourses(page, limit) # get relation lessons information for i in range(len(courses)): courses[i]['lessonInfo'] = [] #query student according members[i]['id'] lessons = LessonModel.GetLessonsByCourseid(courses[i]['id']) for lesson in lessons: # get lesson information courses[i]['lessonInfo'].append(lesson) courses[i]['teacherInfo'] = [] teachers = CTeacherModel.GetTeacherByCourseid(courses[i]['id']) for th in teachers: courses[i]['teacherInfo'].append({'teacher_id':th['teacher_id'],'teacher_name':th['teacher_name'],'teacher_mobile':th['teacher_mobile']}) return utils.jsonresp(jsonobj={'total':total, 'limit':limit, 'courses':courses})
def delete_lesson(name): errcode = LessonModel.DeleteLessonByname(name) return utils.jsonresp(jsonobj={'errcode': errcode})
def update_lesson(name): data = request.get_json(force=True) errcode = LessonModel.UpdateLessonByName(data) return utils.jsonresp(jsonobj={'errcode': errcode})
def create_lesson(): data = request.get_json('content') errcode = LessonModel.CreateLesson(data) return utils.jsonresp(jsonobj={'errcode': errcode})
def get_lessonsByName(name): lessons = LessonModel.GetLessonsByName(name) for i in range(len(lessons)): cName = CourseModel.GetNameById(lessons[i]['course_id']) lessons[i]['coursename'] = cName return utils.jsonresp(jsonobj={'lessons': lessons})
def get_lessonById(lid): return utils.jsonresp( jsonobj={'lesson': LessonModel.GetLessonsBylessonid(lid)})