From cd10a154e6f2bf3bbe3aa4b6ca8d887137602e75 Mon Sep 17 00:00:00 2001 From: user86 Date: Sun, 11 Oct 2020 22:06:49 +0530 Subject: [PATCH] Feat: Added quiz result functionality --- app.py | 13 +++- templates/index.html | 168 +++++++++++++++++++++--------------------- templates/quiz.html | 132 ++++++++++++++++----------------- templates/result.html | 14 ++++ 4 files changed, 174 insertions(+), 153 deletions(-) create mode 100644 templates/result.html diff --git a/app.py b/app.py index 1ee0138..81d8b5a 100644 --- a/app.py +++ b/app.py @@ -12,6 +12,9 @@ UPLOAD_FOLDER = './pdf/' app = Flask(__name__) app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER +# Global quiz object +questions = dict() + @ app.route('/') def index(): @@ -24,7 +27,6 @@ def quiz(): """ Handle upload and conversion of file + other stuff """ UPLOAD_STATUS = False - questions = dict() # Make directory to store uploaded files, if not exists if not os.path.isdir('./pdf'): @@ -45,7 +47,6 @@ def quiz(): # Get contents of file uploaded_content = pdf2text(file_path, file_exten) questions = txt2questions(uploaded_content) - print(questions) # File upload + convert success if uploaded_content is not None: @@ -59,5 +60,13 @@ def quiz(): size=len(questions)) +@app.route('/result', methods=['POST', 'GET']) +def result(): + correct_q = 0 + for k, v in request.form.items(): + correct_q += 1 + return render_template('result.html', total=5, correct=correct_q) + + if __name__ == "__main__": app.run(debug=True) diff --git a/templates/index.html b/templates/index.html index 8f8446d..bb6bf09 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,95 +1,93 @@ - - - - - - - - - MLH Quizzet - + + + + + + + + + MLH Quizzet + - - - +
+
+ upload + +
+ -
- - - -
-
- + + + + + - + button.addEventListener('click', toggleClass); + button.addEventListener('transitionend', toggleClass); + button.addEventListener('transitionend', addClass); + + - + \ No newline at end of file diff --git a/templates/quiz.html b/templates/quiz.html index 47728c4..6fcc7ca 100644 --- a/templates/quiz.html +++ b/templates/quiz.html @@ -1,52 +1,52 @@ - - - - - - - - MLH Quizzet - - + - + }); + + - - - + {% if uploaded == true %} +
{% for i in range(size) %}
@@ -54,32 +54,32 @@

{{ i+1 }}. {{ questions[i+1]['question'] }}


- - {% for op in questions[i+1]['options'] %} - {% if op == questions[i+1]['answer'] %} - -
- {% else %} - -
- {% endif %} - {% endfor %} - + {% for op in questions[i+1]['options'] %} + {% if op == questions[i+1]['answer'] %} + +
+ {% else %} + +
+ {% endif %} + {% endfor %}
{% endfor %} - {% else %} -
-

Could not upload file

-
- {% endif %} -
- MIT License © Copyright 2020 Fantastic Falcons -
- + + - + {% else %} +
+

Could not upload file

+
+ {% endif %} +
+ MIT License © Copyright 2020 Fantastic Falcons +
+ + + \ No newline at end of file diff --git a/templates/result.html b/templates/result.html new file mode 100644 index 0000000..95561fe --- /dev/null +++ b/templates/result.html @@ -0,0 +1,14 @@ + + + + + + + Document + + + +

You got {{ correct }}/{{ total }} right !

+ + + \ No newline at end of file