Commit 0c844fbc authored by colmoneill's avatar colmoneill

working draft of a questionnaire written into a dict in ref to #2;

we can now refer to a dict of questions (currently located in the main app) through a meta tag in the markdown. If a quiz is assigned and is know by the global environment, the template renders a quiz after the content of the markdown document page. Link anchors will need to be added. possible issues: * needing more than one correct answer is currently out of the model * where to redirect after submitting the questionnaire form, do we send back to the quiz? * defining a ratio of number of questions vs number of needed correct answers still needs to be built in before we award a badge
parent afe1e0d5
from flask import Flask, render_template, redirect, flash
from flask import Flask, render_template, redirect, flash, request
from flask_flatpages import FlatPages
import markdown
import random, copy
import os
import glob
from flask_mongoengine import *
......@@ -20,6 +21,24 @@ app = Flask(__name__)
app.config.from_object(__name__)
pages = FlatPages(app)
##################
## QUIZZZZZ ###
##################
original_questions = {
#Format is 'question':[options]
'Taj Mahal':['Agra','New Delhi','Mumbai','Chennai'],
'Great Wall of China':['China','Beijing','Shanghai','Tianjin'],
'Petra':['Ma\'an Governorate','Amman','Zarqa','Jerash'],
'Machu Picchu':['Cuzco Region','Lima','Piura','Tacna'],
'Egypt Pyramids':['Giza','Suez','Luxor','Tanta'],
'Colosseum':['Rome','Milan','Bari','Bologna'],
'Christ the Redeemer':['Rio de Janeiro','Natal','Olinda','Betim']
}
questions = copy.deepcopy(original_questions)
robotArmQuiz = copy.deepcopy(original_questions)
@app.route("/")
@app.route("/index")
def index():
......@@ -37,8 +56,28 @@ def learn():
@app.route('/learn/<path:path>/')
def page(path):
page = pages.get_or_404(path)
print(page)
return render_template('flatpage.html', page=page)
if 'quiz' in page.meta.keys():
quizName = page.meta['quiz']
if quizName in globals():
global quiz
quiz = globals()[quizName]
print(quiz)
questions_shuffled = shuffle(quiz)
for i in list(quiz.keys()):
random.shuffle(quiz[i])
else:
quiz = None
questions = None
return render_template('flatpage.html', page=page, quiz=quiz, q=questions_shuffled, o=quiz)
@app.route('/learn/check', methods=['POST'])
def quiz_answers():
correct = 0
for i in quiz.keys():
answered = request.form[i]
if quiz[i][0] == answered:
correct = correct+1
return '<h1>Correct Answers: <u>'+str(correct)+'</u></h1>'
# @app.route("/login")
......@@ -61,6 +100,25 @@ def event():
#def not_found(error):
# return render_template('error.html'), 404
##################
## QUIZZZZZ ###
##################
def shuffle(q):
"""
This function is for shuffling
the dictionary elements.
"""
selected_keys = []
i = 0
while i < len(q):
current_selection = random.choice(list(q.keys()))
if current_selection not in selected_keys:
selected_keys.append(current_selection)
i = i+1
return selected_keys
# /
......
title: bras robotique
published: 2010-12-24
featured_image: page_images/test.jpg
quiz: robotArmQuiz
......
......@@ -2,6 +2,8 @@
{% block content %}
{{page.quiz}}
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
......@@ -23,4 +25,18 @@
{{page}}
</div>
</div>
{% if page.quiz %}
<h1>7 Wonders of the World</h1>
<form action='/learn/check' method='POST'>
<ol>
{% for i in q %}
<li>Where is <u>{{i}}</u> located?</li>
{% for j in o[i] %}
<input type='radio' value='{{j}}' name='{{i}}' />{{j}}
{% endfor %}
{% endfor %}
</ol>
<input type="submit" value="submit" />
</form>
{% endif %}
{% endblock %}
{% extends "base.html" %}
{% block content %}
<h1>7 Wonders of the World</h1>
<form action='/learn/check' method='POST'>
<ol>
{% for i in q %}
<li>Where is <u>{{i}}</u> located?</li>
{% for j in o[i] %}
<input type='radio' value='{{j}}' name='{{i}}' />{{j}}
{% endfor %}
{% endfor %}
</ol>
<input type="submit" value="submit" />
</form>
{% endblock %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment