示例#1
0
def get_lesson_by_reference(student_id):
    student = db.student.find_one({'_id': ObjectId(str(student_id))})
    teacher = db.teacher.find_one(
        {'_id': ObjectId(str(student['teachers_id']))})
    data_to_send = []
    for i in teacher['courses_enrolled_in']:
        lesson_data = get_original_lesson_by_reference(ObjectId(str(i)))
        if lesson_data != None:
            for j in lesson_data:
                j['status'] = check_lesson_status(student_id, j['lesson_id'])
                j['grade'] = get_total_grade_from_lesson_id(
                    student_id, j['lesson_id'])
            data_to_send.append({
                "course_id":
                i,
                "course_name":
                get_course_title(str(i)),
                "teacher_id":
                ObjectId(str(student['teachers_id'])),
                "lesson_data":
                lesson_data
            })
        else:
            data_to_send.append({
                "course_id":
                str(i),
                "teacher_id":
                ObjectId(str(student['teachers_id'])),
                "lesson_data": [""]
            })
    return (JSONEncoder().encode(data_to_send))
示例#2
0
def authenticate_student():
    email = request.json['Email']
    password = request.json['Password']
    x = db.student.find_one({'email': email})
    if x != None:
        if x['password'] == password:
            return JSONEncoder().encode((x['_id']))
    return "0"
示例#3
0
def get_student_answers_from_teacher(student_exercise_id, question_id, index):
    answer_details = get_student_answers(student_exercise_id)
    if answer_details != "0" and len(
            answer_details) != 0 and answer_details != None and len(
                answer_details) > int(index):
        return (JSONEncoder().encode(answer_details[int(index)]))
    else:
        new_question_id = ObjectId()
    return "0"
示例#4
0
def get_students_by_course(course_id):
    cursor_array = []
    x = (db.student.find(
        {'courses_enrolled_in': {
            '$all': [ObjectId(str(course_id))]
        }}))
    for i in x:
        cursor_array.append(i)
    return JSONEncoder().encode(cursor_array)
示例#5
0
def get_teacher_courses(teacher_id):
    x = db.teacher.find_one({'_id': ObjectId(str(teacher_id))})

    array = []
    for i in x["courses_enrolled_in"]:
        newObj = {}
        newObj['course_id'] = i
        newObj['course_name'] = get_course_title(str(i))
        array.append(newObj)

    return JSONEncoder().encode(array)
示例#6
0
def get_student_lesson_details_if_complete(course_id, student_id):
    lessons_in_course = get_lesson_ids_by_course_id(course_id)
    print(lessons_in_course)
    lessons_in_course_array = []
    student = db.student.find_one({'_id': ObjectId(str(student_id))})
    lesson_reference = student['course_details'][0]['lesson_reference']
    lesson_details = db.studentLessons.find_one(
        {'_id': ObjectId(str(lesson_reference))})
    lesson_details = lesson_details['lesson_details']
    for i in lesson_details:
        if str(i['original_lesson_reference']) in str(lessons_in_course):
            lessons_in_course_array.append(i)
    return JSONEncoder().encode(lessons_in_course_array)
示例#7
0
def get_student_answer_details(student_exercise_id, question_id, index):
    answer_details = get_student_answers(student_exercise_id)

    if answer_details != "0" and len(
            answer_details) != 0 and answer_details != None and len(
                answer_details) > int(index):
        return (JSONEncoder().encode(answer_details[int(index)]))
    else:
        new_question_id = ObjectId()
        post_answer_template(
            student_exercise_id,
            new_question_id)  #This needs to be changed to post_template.
        return "1"
    return "0"
示例#8
0
def get_student_details_by_course(student_id, course_id):
    x = db.student.find_one({
        '$and': [{
            '_id': ObjectId(str(student_id))
        }, {
            'course_details.course_id': ObjectId(str(course_id))
        }]
    })
    if (x):
        for i in x['course_details']:
            if (i['course_id'] == ObjectId(str(course_id))):
                return JSONEncoder().encode(
                    get_lesson_detail_by_id(i['lesson_reference']))
    else:
        return "0"
示例#9
0
def show_dash_board(teacher_id):
    teacher = db.teacher.find_one({'_id': ObjectId(str(teacher_id))})
    teacher_courses = teacher['courses_enrolled_in']
    recent_submissions = teacher['recent_submissions']
    dash = {}
    for i in teacher_courses:
        dash[str(i)] = []

    array_to_send = []
    for i in recent_submissions:
        if i['course_id'] in dash.keys():
            dash[i['course_id']].append(i)

    new_dict = {}
    for i in dash.values():
        new_dict[get_course_title(get_key(i, dash))] = i

    return JSONEncoder().encode([new_dict])
示例#10
0
def get_student_lesson_by_reference(student_id, original_lesson_reference):
    x = db.student.find_one({'_id': ObjectId(str(student_id))})
    array_to_send = []
    lesson_reference = ""

    lesson_reference = (x['course_details'][0]['lesson_reference'])
    array_to_send.append(lesson_reference)
    lesson = db.studentLessons.find_one(
        {'_id': ObjectId(str(lesson_reference))})

    new_obj = {}
    found = 0
    lesson_details = lesson['lesson_details']
    for i in lesson_details:
        if str(i['original_lesson_reference']) == str(
                original_lesson_reference):
            array_to_send.append(i['student_exercises_reference'])
            found = 1

    if found == 0:
        new_exercise_id = ObjectId()
        new_question_id = ObjectId()
        new_obj['status'] = "in-progress"
        new_obj['original_lesson_reference'] = ObjectId(
            str(original_lesson_reference))
        new_obj['student_exercises_reference'] = ObjectId(str(new_exercise_id))
        lesson_details.append(new_obj)
        db.studentLessons.update_one(
            {'_id': ObjectId(str(lesson_reference))},
            {'$set': {
                'lesson_details': lesson_details
            }})
        db.studentExercises.insert_one({
            '_id': ObjectId(str(new_exercise_id)),
            'details': []
        })
        post_answer_template(new_exercise_id, new_question_id)
        return "0"

    if (len(array_to_send) != 0):
        return JSONEncoder().encode(array_to_send)
    else:
        return ("0")
示例#11
0
def get_student_details_from_array(array):
    student_detail_array = []
    new_obj = {}
    for i in array:
        get_student_name = db.student.find_one({'_id': i})
        get_student_obj = db.student.find_one({'_id': i})
        print("00000000")
        print("00000000")
        print("00000000")
        print(i)
        print("00000000")
        print("00000000")
        print("00000000")
        new_obj["student_id"] = i
        new_obj["fullname"] = get_student_name["fullname"]

        new_obj["course_details"] = get_student_obj["course_details"]
        student_detail_array.append(new_obj)
        new_obj = {}

    print("==-=-===-=")
    print(student_detail_array)
    print("==-=-===-=")
    return JSONEncoder().encode(student_detail_array)
示例#12
0
def get_course_title(course_id):
    x = db.admin.find_one({'_id': ObjectId(str(course_id))})
    return JSONEncoder().encode(x["course_title"])
示例#13
0
def get_lesson_from_course(course_id, lesson_id):
    lessons = get_original_lesson_by_reference(course_id)
    for i in lessons:
        if str(i['lesson_id']) == str(lesson_id):
            return (JSONEncoder().encode(i['exercises']))
    return "0"
示例#14
0
def get_lesson_from_course_for_prepare(course_id):
    return JSONEncoder().encode(get_original_lesson_by_reference(course_id))
示例#15
0
def get_exercise_by_reference(exercise_reference):
    x = db.studentExercises.find_one(
        {'exercise_id': ObjectId(str(exercise_reference))})
    return (JSONEncoder().encode(x['exercise_details']))
示例#16
0
def get_student_details(student_id):
    x = db.student.find_one({'_id': ObjectId(str(student_id))})
    return JSONEncoder().encode(x["course_details"])
示例#17
0
def get_student_exercises_by_lesson_id(exercise_reference):
    x = db.studentExercises.find_one(
        {'_id': ObjectId(str(exercise_reference))})
    return (JSONEncoder().encode(x))
示例#18
0
def get_student_fullname(student_id):
    x = db.student.find_one({'_id': ObjectId(str(student_id))})
    return JSONEncoder().encode(x["fullname"])