Exemple #1
0
def result(subject_id):
    username = request.get_cookie("username")
    print(username)
    subject = Subject.get(Subject.id == subject_id)
    user = User.get(User.id == int(username))
    responses = Response.select().where(Response.user == user,
                                        Response.subject_code == subject)
    result = Result.get(Result.username == user,
                        Result.subject_code == subject)
    return {"result": result, "subject": subject, "responses": responses}
Exemple #2
0
def sub2(subject_id):

    username = request.get_cookie("username")
    subject = Subject.get(Subject.id == subject_id)
    user = User.get(User.id == int(username))
    print(user)

    result = Result.select().where(Result.username == int(username))
    if (len(result) != 0) and (result[0].is_taken == True):
        return redirect("/result")

    for question in Question.filter(Question.subject_code == subject):
        res = request.forms.get(f"question-{question.id}")
        response = Response(qid=question.id,
                            subject_code=subject_id,
                            user=user,
                            response=res)
        response.save()

        try:
            result = Result.get(Result.username == user,
                                Result.subject_code == subject)
        except:
            result = Result(username=user, subject_code=subject, is_taken=True)

        if int(res) == question.right_option:
            result.marks_obtained += 1

            if result.marks_obtained == 20:
                result.grade = "A"
                result.state = "Outstanding!"

            elif result.marks_obtained > 13:
                result.grade = "B"
                result.state = "Good!"

            elif result.marks_obtained > 7:
                result.grade = "C"
                result.state = "Average!"

            else:
                result.grade = "D"
                result.state = "Poor!"
        else:
            result.marks_obtained += 0

        result.save()
        subject = subject.select()[0]

    return redirect("/choosesub")
Exemple #3
0
def add_grade_():
    form = AddGradeForm()
    if form.validate_on_submit():
        try:
            with db.transaction():
                grade = Grade.create(
                    student=Student.get(Student.username == form.student_select.data),
                    subject=Subject.get(Subject.name == form.subject_select.data),
                    teacher=get_current_user(),
                    grade=form.grade.data
                )
        except DatabaseError:
            flash('An error occurred while adding a grade')
        else:
            flash('Grade ' + str(grade.grade) + ' assigned to student ' + str(grade.student))
            return redirect(url_for('groups', group=grade.student.username))
    flash_errors(form)
    students = Student.select()
    subjects = Subject.select()
    return render_template('add_grade.html', students=students, subjects=subjects, form=form)
Exemple #4
0
def sub2(subject_id):
    subject = Subject.get(Subject.id == subject_id)
    questions = Question.filter(Question.subject_code == subject)
    return {"subject": subject, "questions": questions}