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 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 profile(id): user_data = list(User.get_user_info(id))[0] user_data["birth"] = datetime.now().year - user_data["birth"].year return render_template( "profile.html", auth=current_user.role, name=current_user.name, user=user_data, id=current_user.id, )
def edit_cs_course_info(): course_json = request.get_json() course_id = course_json['course_id'] name = course_json['name'] start_time = course_json['start_time'] course_time = course_json['course_time'] old_teacher_id = course_json['old_teacher'] #改成id new_teacher_id = course_json['new_teacher'] summary = course_json['summary'] #current_lesson_id="" #!!!!!!!!!!!!!!!!!先設null有用到再說 #student_list=course_json['student_list'] classroom = course_json['classroom'] #course_id, name, start_time, course_time, teacher不得為空 if course_id == "" or name == "" or start_time == "" or course_time == "" or new_teacher_id == "": return jsonify({'message': '資料不得為空'}) old_teacher_data = user.get_user_info(old_teacher_id) new_teacher_data = user.get_user_info(new_teacher_id) start_time = start_time.split("T")[0] #拿到日期 start_time = datetime.strptime(start_time, '%Y-%m-%d') courseid = {'course_id': course_id} coursedict = { 'course_id': course_id, 'name': name, 'start_time': start_time, 'course_time': course_time, 'teacher': new_teacher_data['name'], 'summary': summary, 'classroom': classroom } course.update_course(courseid, coursedict) if old_teacher_id != "": #把course從原teacher course_list中刪除 temp = old_teacher_data['course_list'] temp.remove(course_id) user.update_user({'user_id': old_teacher_id}, {'course_list': temp}) #把course加入新teacher course_list中 temp = new_teacher_data['course_list'] temp.append(course_id) user.update_user({'user_id': new_teacher_id}, {'course_list': temp}) return jsonify({'0': 0}) #之後redirect
def test_get_user_info(self, mockdb): tmp = list(user.get_user_info("5dd8a604371301b428df5602")) assert tmp == [ { "_id": ObjectId("5dd8a604371301b428df5602"), "userName": "******", "gender": "female", "phone": "0920198409", "email": "*****@*****.**", "birth": datetime.datetime(1999, 11, 21, 23, 10, 42, 908000), "avatar": "64c4638b-b6ae-4335-80ec-1441e346b4e9", "state": "activate", } ]
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 cs_reschedule_info(): weekday = request.values.get('weekday') time = request.values.get('time') #weekday, time不得為空 if weekday == "" or time == "": return jsonify({'message': '資料不得為空'}) data = reschedule.get_day_reservation(weekday, time) temp = [] if data: for i in data['reservation_list']: user_name = user.get_user_info(i['user_id'])['name'] lesson_time = lesson.get_lesson_info(i['lesson_id'])['lesson_time'] temp.append({ 'course_name': i['course_name'], 'lesson_time': lesson_time, 'name': user_name }) return jsonify( temp) #某星期該時段的reservation_list,reservation_list記該時段所有學生的補課資訊(dict) else: return jsonify({'0': 0}) #要處理null問題
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 get_friend_list(uid): info = user.get_user_info(uid, ['friends']) if 'friends' in info.keys(): return info['friends'] return []