コード例 #1
0
def course_page(course_id):
    user_id = users.get_user_id()
    if user_id == 0:
        return render_template("error.html", message="Kirjaudu sisään nähdäksesi sisältöä!")

    fail = False
    if request.method == "POST":
        if session["csrf_token"] != request.form["csrf_token"]:
            abort(403)
        update_type = request.form["update_type"]
        if update_type == "intro_update":
            if not courses.update_intro(course_id, request.form["content"]):
                fail = True
        if update_type == "material_update":
            if not coursematerials.update_material(request.form["material_id"], request.form["title"], request.form["content"]):
                fail = True
    if fail:
        return render_template("error.html", message="Kurssimateriaalin päivittäminen ei onnistunut!")
    else:
        course = courses.get_course(course_id)
        course_published = course[5]
        course_visible = course[6]
        course_owner = courses.check_for_ownership(user_id, course_id)
        coursematerial = coursematerials.get_all_coursematerials(course_id)
        course_statistics = statistics.get_course_status(user_id, course_id)
        no_material = (len(coursematerial) == 0)
        no_more_material = (coursematerials.get_amount_of_material_slots(course_id) == 10)
        return render_template("course.html", course=course, course_published=course_published, course_visible=course_visible, course_owner=course_owner,
            coursematerial=coursematerial, course_statistics=course_statistics, no_material=no_material, no_more_material=no_more_material)
コード例 #2
0
def exercise_page(id):
    user_id = users.get_user_id()
    if user_id == 0:
        return render_template("error.html", message="Kirjaudu sisään nähdäksesi sisältöä!")

    fail = False
    if request.method == "POST":
        if session["csrf_token"] != request.form["csrf_token"]:
            abort(403)
        exercise_type = int(request.form["exercise_type"])
        if exercise_type == 1:
            right_choice = request.form["right_choice"]
            wrong_choices = request.form.getlist("wrong_choice")
            if not exercises.add_quiz_exercise(id, exercise_type, int(request.form["points"]), request.form["question"],
                request.form["right_feedback"], request.form["false_feedback"], right_choice, wrong_choices):
                fail = True
        if exercise_type == 2:
            if not exercises.add_text_exercise(id, exercise_type, int(request.form["points"]), request.form["question"],
                request.form["right_text"], request.form["right_feedback"], request.form["false_feedback"]):
                fail = True
    if fail:
        return render_template("error.html", message="Tehtävän lisääminen ei onnistunut!")
    else:
        course = courses.get_course(id)
        quiz_exercises = exercises.get_all_quiz_exercises(id)
        quizzes_and_choises = []
        for quiz in quiz_exercises:
            choices = exercises.get_all_choises(quiz[0])
            quizzes_and_choises.append((quiz, choices))
        text_exercises = exercises.get_all_text_exercises(id)

        no_quizzes = (len(quizzes_and_choises) == 0)
        no_text_exercises = (len(text_exercises) == 0)
        course_visible = course[6]
        course_published = course[5]
        course_owner = courses.check_for_ownership(user_id, id)
        student_signedup = courses.check_for_signup(user_id, id)

        all_quizzes_answered = statistics.all_exercises_answered(user_id, id, 1)
        all_text_exercises_answered = statistics.all_exercises_answered(user_id, id, 2)
        course_statistics = statistics.get_course_status(user_id, id)

        correct_quiz_answers = []
        correct_text_exercise_answers = []
        all_quiz_answers = []
        all_text_exercise_answers = []
        if all_quizzes_answered:
            correct_quiz_answers = answers.get_correct_answers(user_id, id, 1)
            all_quiz_answers = answers.get_all_answers(user_id, id, 1)
        if all_text_exercises_answered:
            all_text_exercise_answers = answers.get_all_answers(user_id, id, 2)
        
        return render_template("exercises.html",
            course=course, quizzes_and_choises=quizzes_and_choises, text_exercises=text_exercises,
            no_quizzes=no_quizzes, no_text_exercises=no_text_exercises, course_visible=course_visible,
            course_published=course_published, course_owner=course_owner, student_signedup=student_signedup,
            all_quizzes_answered=all_quizzes_answered, all_text_exercises_answered=all_text_exercises_answered,
            course_statistics=course_statistics, correct_quiz_answers=correct_quiz_answers,
            all_quiz_answers=all_quiz_answers, all_text_exercise_answers=all_text_exercise_answers)
コード例 #3
0
def hide_course(course_id):
    user_id = users.get_user_id()
    if user_id == 0:
        return render_template("error.html", message="Kirjaudu sisään nähdäksesi sisältöä!")
    course_owner = courses.check_for_ownership(user_id, course_id)
    if not course_owner:
        return render_template("error.html", message="Et ole kurssin opettaja!")

    courses.hide_course(course_id)
    return redirect("/")
コード例 #4
0
def update_material(course_id, material_id):
    user_id = users.get_user_id()
    if user_id == 0:
        return render_template("error.html", message="Kirjaudu sisään nähdäksesi sisältöä!")
    course_owner = courses.check_for_ownership(user_id, course_id)
    if not course_owner:
        return render_template("error.html", message="Et ole kurssin opettaja!")

    course = courses.get_course(course_id)
    material = coursematerials.get_material(material_id)
    return render_template("updatematerial.html", course=course, material=material)
コード例 #5
0
def modify_coursematerial_order(course_id, material_id, modify_type):
    user_id = users.get_user_id()
    if user_id == 0:
        return render_template("error.html", message="Kirjaudu sisään nähdäksesi sisältöä!")
    course_owner = courses.check_for_ownership(user_id, course_id)
    if not course_owner:
        return render_template("error.html", message="Et ole kurssin opettaja!")

    slotcount = coursematerials.get_amount_of_material_slots(course_id)
    if modify_type != "delete" and slotcount >= 10:
        return render_template("error.html", message="Et voi lisätä uusia osioita, maksimimäärä on 10!")
    if coursematerials.modify_material_order(course_id, material_id, modify_type):
        return redirect(f"/course/{course_id}")
    else:
        return render_template("error.html", message="Materiaalin lisääminen ei onnistunut!")
コード例 #6
0
def update_passgrade():
    user_id = users.get_user_id()
    if user_id == 0:
        return render_template("error.html", message="Kirjaudu sisään nähdäksesi sisältöä!")
    course_id = request.form["course_id"]
    course_owner = courses.check_for_ownership(user_id, course_id)
    if not course_owner:
        return render_template("error.html", message="Et ole kurssin opettaja!")
    if session["csrf_token"] != request.form["csrf_token"]:
        abort(403)
    
    new_passgrade = request.form["passgrade"]
    if courses.update_passgrade(course_id, new_passgrade):
        return redirect(f"course/{course_id}")
    else:
        return render_template("error.html", message="Läpipääsyrajan päivittäminen ei onnistunut!")