Exemple #1
0
def give_second_access_to_exam(organization, course, exam):
    token = get_jwt_identity()
    if not check_auth(token, organization, "lecturer"):
        return jsonify("Unauthorized access!")
    if check_lecture_permission(organization, token, course):
        exam = Exam(exam, organization, db)
        return jsonify(exam.give_second_access(request.form["student_user"]))
Exemple #2
0
def add_exam(organization, course):
    token = get_jwt_identity()
    if not check_auth(token, organization, "lecturer"):
        return jsonify("Unauthorized access!")
    if check_lecture_permission(organization, token, course):
        name = request.form["name"]
        time = request.form["time"]
        duration = request.form["duration"]
        status = request.form["status"]
        exam = Exam(name, organization, db)
        rtn = jsonify(exam.save(course, time, duration, status))
        log_activity(request.remote_addr, token["username"], request.endpoint)
        return rtn
    print "that"
    return jsonify("Unauthorized access!")
Exemple #3
0
def get_exam(organization, course, name):
    token = get_jwt_identity()
    if not check_auth(token, organization, "student"):
        return jsonify("Unauthorized access!")
    if check_lecture_permission(organization, token, course):
        exam = Exam(name, organization, db)
        rtn = exam.get()
        if token["role"] == "student":
            if not exam.check_first_enter(token["username"]):
                return jsonify("You already sit the exam!")
            print rtn["Status"] != "active"
            if not (rtn["Status"] == "active" or rtn["Status"] == "graded"):
                return jsonify("Cannot access to exam.")
        log_activity(request.remote_addr, token["username"], request.endpoint,
                     name)
        return jsonify(rtn)
    return jsonify("Unauthorized access!")
Exemple #4
0
def get_grades(organization, course, exam_name, student_id):
    token = get_jwt_identity()
    if not check_auth(token, organization, "lecturer"):
        return jsonify("Unauthorized access!")
    if check_lecture_permission(organization, token, course):
        log_activity(request.remote_addr, token["username"], request.endpoint)
        return DecimalEncoder().encode(
            Exam(exam_name, organization, db).get_grades(student_id))
    return "Unauthorized access."
Exemple #5
0
def delete_exam(organization, course, exam):
    token = get_jwt_identity()
    if not check_auth(token, organization, "lecturer"):
        return jsonify("Unauthorized access!")
    if check_lecture_permission(organization, token, course):
        rtn = jsonify(Exam(exam, organization, db).delete_exam())
        log_activity(request.remote_addr, token["username"], request.endpoint)
        return rtn
    return jsonify("Unauthorized access!")
Exemple #6
0
def upload_keystroke(organization, course, exam):
    token = get_jwt_identity()
    student = request.form["student_id"]
    if not check_lecture_permission(organization, token,
                                    course) or not check_auth(
                                        token, organization, "lecturer"):
        rtn = "Unauthorized access."
    else:
        rtn = Exam(exam, organization,
                   db).get_live_exam_keystrokes(course, student)
    return jsonify(rtn)
Exemple #7
0
def change_status_of_exam(organization, course, exam_name):
    token = get_jwt_identity()
    role = token["role"]
    if role != "lecturer" and check_lecture_permission(organization, token,
                                                       course):
        return jsonify("Unauthorized access!")
    rtn = jsonify(
        Exam(exam_name, organization,
             db).change_status(request.form["status"]))
    log_activity(request.remote_addr, token["username"], request.endpoint)
    return rtn
Exemple #8
0
def exam_data(organization, course, username, exam):
    token = get_jwt_identity()
    username = token["username"]
    if not check_auth(token, organization,
                      "student") or not check_lecture_permission(
                          organization, token, course):
        rtn = "Unauthorized access"
    else:
        data = request.form
        Exam(exam, organization, db=db).save_exam_data(username, course, data)
        rtn = "Done"
    return jsonify(rtn)
Exemple #9
0
def edit_question(organization, course, exam_name, question_id):
    token = get_jwt_identity()
    role = token["role"]
    if role != "lecturer" and check_lecture_permission(organization, token,
                                                       course):
        return jsonify("Unauthorized access!")
    rtn = jsonify(
        Exam(exam_name, organization,
             db).edit_a_question(question_id,
                                 json.loads(request.form["data"])))
    log_activity(request.remote_addr, token["username"], request.endpoint)
    return rtn
Exemple #10
0
def upload_extra_materials(organization, course, exam):
    token = get_jwt_identity()
    if not check_auth(token, organization,
                      "lecturer") or not check_lecture_permission(
                          organization, token, course):
        rtn = "Unauthorized access."
    else:
        rtn = Exam(exam, organization,
                   db).upload_extra_materials(request.files["file"], course,
                                              exam,
                                              request.form["question_id"],
                                              request.form["purpose"])
    return jsonify(rtn)
Exemple #11
0
def add_questions_to_exam(organization, course, name):
    token = get_jwt_identity()
    if not check_auth(token, organization, "lecturer"):
        return jsonify("Unauthorized access!")
    if check_lecture_permission(organization, token, course):
        info = json.loads(request.form["data"])
        rtn = Exam(name, organization,
                   db=db).add_question(info["type"], info["subject"],
                                       info["text"], info["answer"],
                                       info["inputs"], info["outputs"],
                                       info["value"], info["t"
                                                           "ags"])
        log_activity(request.remote_addr, token["username"], request.endpoint)
        return jsonify(rtn)
    return jsonify("Unauthorized access!")