From c68f0cedc922fc11d6de840395effe32442aa7e2 Mon Sep 17 00:00:00 2001 From: Miguel Barão Date: Sat, 4 Feb 2017 19:55:03 +0000 Subject: [PATCH] - added question animations --- serve.py | 28 ++++++++++++++++++++-------- templates/learn.html | 43 ++++++++++++++++++++++++++++++++----------- templates/question-checkbox.html | 38 +++++++++++++++++++++----------------- templates/question-radio.html | 38 ++++++++++++++++++++++---------------- templates/question-text.html | 24 +++++++++++++++--------- templates/question-textarea.html | 24 ++++++++++++++---------- 6 files changed, 124 insertions(+), 71 deletions(-) diff --git a/serve.py b/serve.py index 6d42e73..7e61bef 100755 --- a/serve.py +++ b/serve.py @@ -32,12 +32,12 @@ class LearnApp(object): # returns dictionary def next_question(self): - print('next question') + # print('next question') # q = self.factory.generate('math-expressions') questions = list(self.factory) - print(questions) + # print(questions) q = self.factory.generate(random.choice(questions)) - print(q) + # print(q) self.q = q return q @@ -80,7 +80,7 @@ class BaseHandler(tornado.web.RequestHandler): def get_current_user(self): user_cookie = self.get_secure_cookie("user") - print('base.get_current_user -> ', user_cookie) + # print('base.get_current_user -> ', user_cookie) if user_cookie: return user_cookie # json.loads(user_cookie) @@ -152,16 +152,24 @@ class QuestionHandler(BaseHandler): print('Reference' + str(ref)) question = self.application.learn.q # get current question + print('=====================================') + print(' ' + str(question)) + print('-------------------------------------') + + if question is not None: ans = self.get_body_arguments('answer') - print(ans) + print(' answer = ' + str(ans)) question['answer'] = ans # insert answer grade = question.correct() # correct answer - print('grade = ' + str(grade)) + print(' grade = ' + str(grade)) - if grade > 0.99999: + correct = grade > 0.99999 + if correct: question = self.application.learn.next_question() + else: + correct = True # to animate correctly question = self.application.learn.next_question() templates = { @@ -172,10 +180,14 @@ class QuestionHandler(BaseHandler): 'text_numeric': 'question-text.html', 'textarea': 'question-textarea.html', } - self.render(templates[question['type']], + html_out = self.render_string(templates[question['type']], question=question, # the dictionary with the question?? md=md, # passes function that renders markdown to html ) + self.write({ + 'html': tornado.escape.to_unicode(html_out), + 'correct': correct, + }) # if question['type'] == 'checkbox': # self.render('question-checkbox.html', diff --git a/templates/learn.html b/templates/learn.html index cf33ab8..04b1c92 100644 --- a/templates/learn.html +++ b/templates/learn.html @@ -36,7 +36,7 @@ -