def user_detail_info(): name = request.values.get('name') #name不能為空 if name == "": return jsonify({'message': '資料不得為空'}) user_detail_info_list = [] if len(user.get_user_info_by_name(name)) == 0: return jsonify({'message': '此人不存在'}) for i in user.get_user_info_by_name(name): course_name_list = [] course_list = i['course_list'] for j in course_list: course_name_list.append( course.get_course_info(j)['name']) #course_list中的id應該不會有錯 user_detail_info_list.append({ 'course_list': i['course_list'], 'email': i['email'], 'name': i['name'], 'phone': i['phone'], 'role': i['role'], 'user_id': i['user_id'], 'course_name_list': course_name_list }) return jsonify(user_detail_info_list)
def cs_course_attendence(): lesson_id = request.values.get('lesson_id') #lesson_id不得為空 if lesson_id == "": return jsonify({'message': '資料不得為空'}) lesson_attendence = lesson.get_lesson_info(lesson_id)[ 'attendence'] #該lesson有出席的學生 all_student = course.get_course_info( lesson.get_lesson_info(lesson_id)['course_id'])[ 'student_list'] #該course的所有學生 temp = [] for i in all_student: user_info = user.get_user_info(i) if i in lesson_attendence: temp.append({ user_info['name']: '出席', 'user_id': user_info['user_id'] }) else: temp.append({ user_info['name']: '缺席', 'user_id': user_info['user_id'] }) return jsonify(temp)
def edit_user_detail_info(): user_json = request.get_json() #password personal_plan role不會改 user_id = user_json['user_id'] name = user_json['name'] delete_from_course_list = user_json[ 'delete_from_course_list'] #要刪掉的course之id course_list = user_json['course_list'] #所有的course,含原本有的與要新增的 phone = user_json['phone'] email = user_json['email'] major = [user_json['major']] #user_id, name不得為空 if user_id == "" or name == "": return jsonify({'message': '資料不得為空'}) if major[0] == "": major = [] userid = {'user_id': user_id} userdict = { 'user_id': user_id, 'name': name, 'course_list': course_list, 'phone': phone, 'email': email, 'major': major } user.update_user(userid, userdict) #將學生加入course的student_list中,會很慢????? for i in course_list: student_list = course.get_course_info( i )['student_list'] #從course_list刪除course,也要把student從course中的student_list刪除 if user_id not in student_list: student_list.append(user_id) course.update_course({'course_id': i}, {'student_list': student_list}) #從course_list刪除course,也要把student從course中的student_list刪除 for i in delete_from_course_list: student_list = course.get_course_info(i)['student_list'] student_list.remove(user_id) course.update_course({'course_id': i}, {'student_list': student_list}) return jsonify({'0': 0}) #之後redirect
def cs_course_student_list(): course_id = request.values.get('course_id') temp = [] #course_id不得為空 if course_id == "": return jsonify({'message': '資料不得為空'}) for i in course.get_course_info(course_id)['student_list']: temp.append(user.get_user_info(i)['name']) return jsonify(temp)
def cs_lesson_id_and_time(): course_id = request.values.get('course_id') #course_id不得為空 if course_id == "": return jsonify({'message': '資料不得為空'}) temp = [] for i in course.get_course_info(course_id)['lesson_list']: lesson_info = lesson.get_lesson_info(i) temp.append({ 'lesson_id': i, 'lesson_time': lesson_info['lesson_time'] }) return jsonify(temp)
def delete_user_detail_info(): user_id = request.values.get('user_id') #user_id不得為空 if user_id == "": return jsonify({'message': '資料不得為空'}) userid = {'user_id': user_id} #先把該成員從所有course的list中刪掉 for i in user.get_user_info(user_id)['course_list']: temp = course.get_course_info(i)['student_list'] temp.remove(user_id) coursedict = {'student_list': temp} course.update_course({'course_id': i}, coursedict) user.delete_user(userid) return jsonify({'0': 0}) #之後redirect
def delete_cs_course_info(): course_id = request.values.get('course_id') course_info = course.get_course_info(course_id) #course_id不得為空 if course_id == "": return jsonify({'message': '資料不得為空'}) #把student的course_list中的該course刪除 for i in course_info['student_list']: temp = user.get_user_info(i)['course_list'] temp.remove(course_id) user.update_user({'user_id': i}, {'course_list': temp}) #把teacher的course_list中的該course刪除 teacher_info = user.get_user_info_by_name(course_info['teacher']) temp = teacher_info[0]['course_list'] #老師沒有名字重複的問題 temp.remove(course_id) user.update_user({'user_id': teacher_info[0]['user_id']}, {'course_list': temp}) courseid = {'course_id': course_id} course.delete_course(courseid) return jsonify({'0': 0}) #之後redirect
def insert_user_detail_info(): user_json = request.get_json() password = user_json['password'] name = user_json['name'] course_list = user_json['course_list'] #一開始只能新增一堂課 [0] course_id = course_list[0] phone = user_json['phone'] email = user_json['email'] major = [user_json['major']] #前端只會給字串,為了資料庫型態一致(array)自己包成list personal_plan = [] role = user_json['role'] #password, name, role不得為空 if password == "" or name == "" or role == "": return jsonify({'message': '資料不得為空'}) if major[0] == "": major = [] user_id = user.insert_user(password, name, course_list, phone, email, major, personal_plan, role) #將該成員選的course加入該course的list temp = course.get_course_info(course_id)['student_list'] temp.append(user_id) course.update_course({'course_id': course_id}, {'student_list': temp}) return jsonify({'0': 0}) #之後redirect