Exemplo n.º 1
0
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")
Exemplo n.º 2
0
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")
Exemplo n.º 3
0
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")
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
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")
Exemplo n.º 6
0
def leaveCourses():
    courseId = courses.getId(request.form["name"])
    userId = users.getId(session["username"])
    courses.leaveCourse(userId, courseId[0])
    return redirect("/loggedIn")