def course_grade(): course_id = request.values.get('course_id') target_course = course.get_by_courseid(course_id) all_lessons = lesson.get_by_courseid(course_id) whole_list = [] for l in all_lessons: if len(l['quiz']['grade_list']) == 0: student_list = [] for student_id in target_course['student_list']: s = user.get_by_userid(student_id) each_student = { "student_name": s['name'], "student_grade": None } student_list.append(jsonify(each_student)) each_quiz = { "lesson_id": l['lesson_id'], "lesson_time": datetime.strftime(l['lesson_time'], "%Y-%m-%d"), "quiz_name": l['quiz']['quiz_name'], "grade_list": student_list } else: each_quiz = { "lesson_id": l['lesson_id'], "lesson_time": datetime.strftime(l['lesson_time'], "%Y-%m-%d"), "quiz_name": l['quiz']['quiz_name'], "grade_list": l['quiz']['grade_list'] } whole_list.append(each_quiz) whole_list = sorted(whole_list, key=lambda k: k['lesson_time']) return jsonify(whole_list)
def course_communication_book(): course_id = request.values.get('course_id') items = lesson.get_by_courseid(course_id) com_book_list = [] for i in items: try: each_com_book = { "lesson_id": i['lesson_id'], "lesson_time": datetime.strftime(i['lesson_time'], "%Y-%m-%d"), "progress": i['progress'], "deadline": datetime.strftime(i['homework']['deadline'], "%Y-%m-%d"), "context": i['homework']['context'] } except: each_com_book = { "lesson_id": i['lesson_id'], "lesson_time": datetime.strftime(i['lesson_time'], "%Y-%m-%d"), "progress": i['progress'], "deadline": "", "context": i['homework']['context'] } com_book_list.append(each_com_book) return jsonify(com_book_list)
def stu_course_progress(): course_id = request.values.get('course_id') items = lesson.get_by_courseid(course_id) progress_list = [] for i in items: each_progress = { "lesson_time" : i['lesson_time'].date(), "progress" : i['progress'] } progress_list.append(each_progress) progress_list = sorted(progress_list,key=lambda k: k['lesson_time']) return jsonify(progress_list)
def stu_course_attendence(): course_id = request.values.get('course_id') items = lesson.get_by_courseid(course_id) attendence_list = [] for i in items: each_attendence = { "lesson_time" : i['lesson_time'], "progress" : i['progress'], "state" : current_user.user_id in i['attendence'] } attendence_list.append(each_attendence) attendence_list = sorted(attendence_list,key=lambda k: k['lesson_time']) return jsonify(attendence_list)
def stu_course_homework(): course_id = request.values.get('course_id') items = lesson.get_by_courseid(course_id) homework_list = [] for i in items: each_homework = { "lesson_time" : i['lesson_time'].date(), "homework" : i['homework']['context'], "deadline" : i['homework']['deadline'], "progress" : i['progress'] } homework_list.append(each_homework) homework_list = sorted(homework_list,key=lambda k: k['lesson_time']) return jsonify(homework_list)
def stu_course_grade(): course_id = request.values.get('course_id') items = lesson.get_by_courseid(course_id) quiz_list = [] for i in items: if current_user.user_id in i['attendence']: grade_dict = next((g for g in i['quiz']['grade_list'] if g['student_name'] == current_user.user_id), None) each_quiz = { "quiz_date" : i['lesson_time'].date(), "quiz_name" : i['quiz']['quiz_name'], "grade" : grade_dict['student_grade'] } quiz_list.append(each_quiz) quiz_list = sorted(quiz_list,key=lambda k: k['quiz_date']) return jsonify(quiz_list)
def teacher_no_plan_lesson_time(): course_id = request.values.get('course_id') student_id = request.values.get('student_id') items = lesson.get_by_courseid(course_id) target_student = user.get_by_userid(student_id) lesson_time_list = [] for i in items: exist = False for p in target_student['personal_plan']: if p['lesson_id'] == i['lesson_id']: exist = True break if exist == False: each_loss = { "lesson_id": i['lesson_id'], "lesson_time": datetime.strftime(i['lesson_time'], "%Y-%m-%d") } lesson_time_list.append(each_loss) return jsonify(lesson_time_list)
def stu_miss_lesson(): whole_list = [] for course_id in current_user.course_list : c = course.get_by_courseid(course_id) ls = lesson.get_by_courseid(course_id) miss_lessons = [] for l in ls: if current_user.user_id not in l['attendence']: each_lesson = { "lesson_id" : l['lesson_id'], "progress" : l['progress'], } miss_lessons.append(each_lesson) each_course = { "course_name" : c['name'], "miss_lessons" : miss_lessons } if len(each_course['miss_lessons']) > 0 : whole_list.append(each_course) return jsonify(whole_list)
def course_attendence(): course_id = request.values.get('course_id') target_course = course.get_by_courseid(course_id) items = lesson.get_by_courseid(course_id) whole_list = [] for i in items: attendence_list = [] for student_id in target_course['student_list']: s = user.get_by_userid(student_id) each_student = { "student_name": s['name'], "student_id": s['user_id'], "email": s['email'], "phone": s['phone'], "state": s['user_id'] in i['attendence'] } attendence_list.append(each_student) each_day = { "lesson_time": datetime.strftime(i['lesson_time'], "%Y-%m-%d"), "attendence_list": attendence_list } whole_list.append(each_day) whole_list = sorted(whole_list, key=lambda k: k['lesson_time']) return jsonify(whole_list)