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")
def get_result(res_id: str) -> Result: return Result.select().where(Result.id == res_id).get()