def show_submissions(id): if not authentication.user_is_logged_in(): return redirect("/login") menu = get_menu_info(id) username = authentication.get_logged_user() submissions = submissionDAO.get_submissions_by_user_id_and_exercise_id(username, id) return render_template("exercises/submissions.html", id=id, heading=menu[0], solved=menu[1], admin=menu[2], submissions=submissions)
def show_all_submissions(id): if not authentication.is_admin(): abort(403) menu = get_menu_info(id) username = authentication.get_logged_user() submissions = submissionDAO.get_submissions_by_exercise_id(id) return render_template("exercises/submissions.html", id=id, heading=menu[0], solved=menu[1], admin=menu[2], submissions=submissions)
def list_exercises(): admin = authentication.is_admin() username = authentication.get_logged_user() topic1 = exerciseDAO.get_exercises_by_topic_in_order(1, username) topic2 = exerciseDAO.get_exercises_by_topic_in_order(2, username) return render_template("exercises/exerciselist.html", topic1=topic1, topic2=topic2, admin=admin)
def profile(username): profile = userDAO.get_profile(username) topic1 = exerciseDAO.get_exercises_by_topic_in_order(1, username) topic2 = exerciseDAO.get_exercises_by_topic_in_order(2, username) logged_in = authentication.get_logged_user() friends = False if logged_in != username and userDAO.are_friends(logged_in, username): friends = True return render_template("profile/profile.html", username=username, introduction=profile[0], joined=profile[1], friends=friends, topic1=topic1, topic2=topic2)
def post_comment(id): token = request.form["csrf_token"] if not (authentication.user_is_logged_in() and authentication.correct_csrf_token(token)): abort(403) if not(is_solved or authentication.is_admin()): abort(403) username = authentication.get_logged_user() comment = request.form["comment"] if len(comment) <= 10000: submissionDAO.post_comment(username, comment, id) return redirect("/comments/" + str(id) + "/ok")
def save_submission(submission, exercise_id, verdict): username = authentication.get_logged_user() submissionDAO.save_submission(username, submission, exercise_id, verdict)
def is_solved(id): username = authentication.get_logged_user() if username == None: return False return submissionDAO.is_exercise_solved(username, id)
def delete_friend(username): logged_in = authentication.get_logged_user() if logged_in != None and userDAO.are_friends(logged_in, username): userDAO.delete_friends(logged_in, username) return redirect("/profile/" + username)
def add_friends(username): logged_in = authentication.get_logged_user() if logged_in != None or not userDAO.are_friends(logged_in, username): userDAO.add_friends(logged_in, username) return redirect("/profile/" + username)
def friends(username): if authentication.get_logged_user() != username: abort(403) friends = userDAO.get_friends(username) return render_template("profile/friends.html", friends=friends, username=username)