def courseInfo(): if request.method == "GET": return render_template("courseInfo.html") if request.method == "POST": courseName = request.form["name"] session["teacher"] = users.getCourseTeacher(courseName) session["courseName"] = courseName usersCourse = courses.getCoursesById(users.getId(session["username"])) session["notOnCourse"] = True for course in usersCourse: if course[0] == courseName: session["notOnCourse"] = False t = tasks.getTasks(courseName) tas = [] ta = [] for task in t: answer = tasks.getAnswers(task[0], users.getId(session["username"])) tas.append(task[0]) if answer == None: ta.append(task[0] + ", Not done") elif answer[0] == True: ta.append(task[0] + ", Correct answer") else: ta.append(task[0] + ", Wrong answer") session["desc"] = courses.getCourseDescription(courseName) session["task"] = tas session["taskAnswers"] = ta return render_template("courseInfo.html")
def joinCourse(): courseName = request.form["courseName"] username = request.form["username"] courseId = courses.getId(courseName) userId = users.getId(username) courses.addToCourse(userId, courseId) return redirect("/loggedIn")
def checkAnswer(): answer = request.form["answer"] cAnswer = request.form["canswer"] taskname = request.form["taskname"] result = False if answer == cAnswer: result = True idTask = tasks.getTaskId(taskname) userId = users.getId(session["username"]) tasks.addGradeToUserTask(idTask, userId, result) return redirect("/courseInfo")
def loggedIn(): name = session["username"] userId = users.getId(name) cours = [] userCourses = [] for row in courses.getCourses(): cours += row for row in courses.getCoursesById(userId): userCourses += row session["courses"] = cours session["usercourses"] = userCourses return render_template("menu.html", courses=cours, userCourses=userCourses, teacherCourses=userCourses)
def course(): if request.method == "GET": session["error"] = "" return render_template("newCourse.html") if request.method == "POST": name = request.form["name"] description = request.form["desc"] teach = request.form["teach"] idTeach = users.getId(teach) if courses.createCourse(name, description, idTeach): return redirect("/loggedIn") else: session["error"] = "Course with this name exists" return render_template("newCourse.html")
def leaveCourses(): courseId = courses.getId(request.form["name"]) userId = users.getId(session["username"]) courses.leaveCourse(userId, courseId[0]) return redirect("/loggedIn")