예제 #1
0
def exercise(id):
    user_id = users.user_id()
    exercise = exercises.get_exercise_by_id(id)
    if user_id == 0 or not registrations.check_registration(
            user_id, exercise[2]) and users.user_is_admin() != True:
        return redirect("/")
    course = courses.get_course_by_id(exercise[2])
    if user_id == course[2]:
        question_list = get_list_of_questions_and_answers(id)
        return render_template("exercise_teacher.html",
                               questions=question_list,
                               exercise=exercise,
                               course=course)
    result = results.get_result(id, user_id)
    if result != None:
        answer_list = answers.get_answers(id, user_id)
        return render_template("result.html",
                               answers=answer_list,
                               points=result[0],
                               max_points=result[1],
                               course=course)
    question_list = get_list_of_questions_and_answers(id)
    return render_template("exercise.html",
                           questions=question_list,
                           exercise=exercise,
                           course=course)
예제 #2
0
def answer():
    if session["csrf_token"] != request.form["csrf_token"]:
        abort(403)
    user_id = users.user_id()
    if user_id == 0:
        return redirect("/")
    exercise_id = request.form["exercise_id"]
    course_id = exercises.get_course_id_by_exercise(exercise_id)
    course = courses.get_course_by_id(course_id)
    question_list = questions.get_question_list(exercise_id)
    points = 0
    max_points = 0
    user_answers = []
    for question in question_list:
        answer = request.form.get("answer_" + str(question[0]))
        if answer == None:
            answer = ""
        user_answers.append([question[1], question[3], answer])
        max_points += question[4]
        answers.add_answer(answer, question[0], user_id)
        if answer.upper() == question[3].upper():
            points += question[4]
    results.add_result(points, max_points, exercise_id, user_id)
    return render_template("result.html",
                           answers=user_answers,
                           points=points,
                           max_points=max_points,
                           course=course)
예제 #3
0
def attendees(id):
    course = courses.get_course_by_id(id)
    if users.user_id() != course[2] and users.user_is_admin() != True:
        return redirect("/")
    attendees = users.get_attendees(course[0])
    return render_template("attendees_teacher.html",
                           attendees=attendees,
                           course=course)
예제 #4
0
def search_attendees(id):
    course = courses.get_course_by_id(id)
    if users.user_id() != course[2] and users.user_is_admin() != True:
        return redirect("/")
    searchword = request.args["searchword"]
    attendee_list = users.search_attendees(id, searchword)
    return render_template("attendees_teacher.html",
                           attendees=attendee_list,
                           course=course)
예제 #5
0
def edit_exercises(id):
    course = courses.get_course_by_id(id)
    if users.user_id() != course[2] and users.user_is_admin() != True:
        return redirect("/")
    exercise_list = exercises.get_exercise_list(id)
    return render_template("course.html",
                           exercises=exercise_list,
                           course=course,
                           remove_exercises=True)
예제 #6
0
def attendee_results(course_id, user_id):
    session_id = users.user_id()
    course = courses.get_course_by_id(course_id)
    if session_id != course[2] and session_id != user_id:
        return redirect("/")
    result_list = results.get_course_results(user_id, course_id)
    return render_template("attendee_results.html",
                           results=result_list,
                           course=course,
                           user_id=user_id)
예제 #7
0
def new_exercise():
    if session["csrf_token"] != request.form["csrf_token"]:
        abort(403)
    course_id = request.form["course_id"]
    course = courses.get_course_by_id(course_id)
    if users.user_id() != course[2]:
        return redirect("/")
    exercise_name = request.form["exercise_name"].strip()
    exercises.add_exercise(exercise_name, course_id)
    return redirect("/course/" + str(course_id))
예제 #8
0
def attendee_answers(course_id, user_id, exercise_id):
    session_id = users.user_id()
    course = courses.get_course_by_id(course_id)
    if session_id != course[2] and session_id != user_id:
        return redirect("/")
    result = results.get_result(exercise_id, user_id)
    answer_list = answers.get_answers(exercise_id, user_id)
    return render_template("result.html",
                           answers=answer_list,
                           points=result[0],
                           max_points=result[1],
                           course=course)
예제 #9
0
def remove_exercises(id):
    if session["csrf_token"] != request.form["csrf_token"]:
        abort(403)
    course = courses.get_course_by_id(id)
    if users.user_id() != course[2] and users.user_is_admin() != True:
        return redirect("/")
    exercise_list = exercises.get_exercise_list(id)
    for exercise in exercise_list:
        remove_exercise = request.form.get("exercise_" + str(exercise[0]) +
                                           "_remove")
        if remove_exercise == "1":
            exercises.hide_exercise(exercise[0])
    return redirect("/course/" + str(id))
예제 #10
0
def course(id):
    if users.user_id() == 0:
        return redirect("/")
    user_id = users.user_id()
    course = courses.get_course_by_id(id)
    if not registrations.check_registration(user_id,
                                            id) and session["admin"] == False:
        if course[3] == None:
            return render_template("registration.html", course=course)
        return render_template("registration.html",
                               course=course,
                               course_key=True)
    exercise_list = exercises.get_exercise_list(id)
    return render_template("course.html",
                           exercises=exercise_list,
                           course=course)
예제 #11
0
def new_questions(id):
    user_id = users.user_id()
    course_id = exercises.get_course_id_by_exercise(id)
    course = courses.get_course_by_id(course_id)
    exercise = exercises.get_exercise_by_id(id)
    if user_id != course[2]:
        return redirect("/")
    choice_questions = int(request.form["choice_question_count"])
    text_questions = int(request.form["text_question_count"])
    if choice_questions == 0 and text_questions == 0:
        return redirect("/exercise/" + str(id) + "/")
    return render_template("newquestions.html",
                           choice_question_count=choice_questions,
                           text_question_count=text_questions,
                           exercise=exercise,
                           course=course)
예제 #12
0
def register(id):
    if session["csrf_token"] != request.form["csrf_token"]:
        abort(403)
    user_id = users.user_id()
    if user_id == 0:
        return redirect("/")
    course = courses.get_course_by_id(id)
    if course[3] == None:
        registrations.add_registration(user_id, course[0])
        return redirect("/course/" + str(id))
    course_key = request.form.get("course_key")
    if check_password_hash(course[3], course_key):
        registrations.add_registration(user_id, course[0])
        return redirect("/course/" + str(id))
    return render_template("registration.html",
                           course=course,
                           course_key=True,
                           course_key_error=True)