diff --git a/BUGS.md b/BUGS.md index 8832eda..bbe467b 100644 --- a/BUGS.md +++ b/BUGS.md @@ -1,6 +1,7 @@ # BUGS +- errar no ultimo topico nao mostra solucao? - nos topicos learn.yaml, qd falha acrescenta no fim. nao faz sentido. - ocorreu uma vez o sqlalchemy dar mesg erro a indicar que as threads sao diferents quando se faz o get da primeira pergunta do topico. Muitas vezes nao mostar erro, mas a pagina da erro ou fica em branco... diff --git a/demo/solar_system/questions.yaml b/demo/solar_system/questions.yaml index ac57804..be37cf6 100644 --- a/demo/solar_system/questions.yaml +++ b/demo/solar_system/questions.yaml @@ -19,32 +19,32 @@ shuffle: False discount: True -# # --------------------------------------------------------------------------- -# - -# ref: home-planet -# type: text -# title: Sistema solar -# text: O nosso planeta chama-se planeta... -# correct: ['Terra', 'terra'] -# # opcional -# answer: Não é Marte... +# --------------------------------------------------------------------------- +- + ref: home-planet + type: text + title: Sistema solar + text: O nosso planeta chama-se planeta... + correct: ['Terra', 'terra'] + # opcional + answer: Não é Marte... -# # --------------------------------------------------------------------------- -# - -# ref: saturn -# type: text-regex -# title: Sistema solar -# text: O planeta do sistema solar conhecido por ter aneis é o planeta... -# correct: !regex '[Ss]aturno' +# --------------------------------------------------------------------------- +- + ref: saturn + type: text-regex + title: Sistema solar + text: O planeta do sistema solar conhecido por ter aneis é o planeta... + correct: !regex '[Ss]aturno' # --------------------------------------------------------------------------- -# - ref: first_3_planets -# type: textarea -# title: Sistema solar -# text: Escreva o nome dos três planetas mais próximos do Sol. (Exemplo `A, B e C`) -# correct: correct-first_3_planets.py -# # correct: correct-timeout.py -# # opcional -# answer: Vulcano, Krypton, Plutão -# lines: 3 -# timeout: 50 +- ref: first_3_planets + type: textarea + title: Sistema solar + text: Escreva o nome dos três planetas mais próximos do Sol. (Exemplo `A, B e C`) + correct: correct-first_3_planets.py + # correct: correct-timeout.py + # opcional + answer: Vulcano, Krypton, Plutão + lines: 3 + timeout: 50 diff --git a/http-redirect.py b/http-redirect.py index ae1fbeb..f91bbc0 100755 --- a/http-redirect.py +++ b/http-redirect.py @@ -16,7 +16,7 @@ from tornado import ioloop, web, httpserver class WebRedirectApplication(web.Application): def __init__(self, target='https://localhost'): handlers = [ - (r'/*', RootHandler), # redirect to https + (r'/', RootHandler), # redirect to https ] super().__init__(handlers) self.target = target @@ -28,7 +28,7 @@ class RootHandler(web.RequestHandler): SUPPORTED_METHODS = ['GET'] def get(self): - print('Redirecting...') + # print('Redirecting...') self.redirect(self.application.target) diff --git a/knowledge.py b/knowledge.py index f880059..df60e57 100644 --- a/knowledge.py +++ b/knowledge.py @@ -153,7 +153,7 @@ class StudentKnowledge(object): if self.next_question() is None: action = 'finished_topic' else: - action = 'new_question' # FIXME show comments + action = 'wrong' # FIXME show comments else: action = 'try_again' diff --git a/learnapp.py b/learnapp.py index c44c921..e5ec64a 100644 --- a/learnapp.py +++ b/learnapp.py @@ -191,7 +191,7 @@ class LearnApp(object): logger.warning(f'User "{uid}" tried to open nonexistent topic: "{topic}"') raise e else: - logger.info(f'User "{uid}" started "{topic}"') + logger.info(f'User "{uid}" started topic "{topic}"') # ------------------------------------------------------------------------ # Fill db table 'Topic' with topics from the graph if not already there. diff --git a/questions.py b/questions.py index 35db7a1..101eed8 100644 --- a/questions.py +++ b/questions.py @@ -363,11 +363,6 @@ class QuestionTextArea(Question): # =========================================================================== class QuestionInformation(Question): - '''An instance of QuestionInformation will always have the keys: - type (str) - text (str) - points (0.0) - ''' #------------------------------------------------------------------------ def __init__(self, q): super().__init__(q) diff --git a/serve.py b/serve.py index b1e32ac..a6280d7 100755 --- a/serve.py +++ b/serve.py @@ -44,7 +44,7 @@ class WebApplication(tornado.web.Application): (r'/logout', LogoutHandler), (r'/change_password', ChangePasswordHandler), (r'/question', QuestionHandler), # renders each question - (r'/topic/(.+)', TopicHandler), # page for exercising a topic + (r'/topic/(.+)', TopicHandler), # start a topic (r'/file/(.+)', FileHandler), # serve files, images, etc (r'/', RootHandler), # show list of topics ] @@ -200,6 +200,8 @@ class FileHandler(BaseHandler): # respond to AJAX to get a JSON question # ---------------------------------------------------------------------------- class QuestionHandler(BaseHandler): + SUPPORTED_METHODS = ['GET', 'POST'] + templates = { 'checkbox': 'question-checkbox.html', 'radio': 'question-radio.html', @@ -218,20 +220,20 @@ class QuestionHandler(BaseHandler): def get(self): logging.debug('QuestionHandler.get()') user = self.current_user + q = self.learn.get_current_question(user) + question_html = self.render_string(self.templates[q['type']], + question=q, md=md_to_html) - question = self.learn.get_current_question(user) - - question_html = self.render_string(self.templates[question['type']], - question=question, md=md_to_html) - - self.write({ + response = { 'method': 'new_question', 'params': { + 'type': q['type'], 'question': tornado.escape.to_unicode(question_html), 'progress': self.learn.get_student_progress(user), - 'tries': question['tries'], + 'tries': q['tries'], }, - }) + } + self.write(response) # --- post answer, returns what to do next: shake, new_question, finished @tornado.web.authenticated @@ -253,57 +255,72 @@ class QuestionHandler(BaseHandler): # and get corrected question q, action = await self.learn.check_answer(user, answer) - # get next question (same, new or None) - question = self.learn.get_current_question(user) + print(action) if action == 'try_again': comments_html = self.render_string('comments.html', - comments=question['comments'], md=md_to_html) - self.write({ - 'method': 'try_again', # FIXME js + comments=q['comments'], md=md_to_html) + + response = { + 'method': 'try_again', 'params': { 'progress': self.learn.get_student_progress(user), 'comments': tornado.escape.to_unicode(comments_html), # FIXME - 'tries': question['tries'], + 'tries': q['tries'], } - }) - - # if action == 'wrong': - # comments_html = self.render_string('comments.html', - # comments=question['comments'], md=md_to_html) - # template = self.templates[question['type']] - # question_html = self.render_string(template, question=question, md=md_to_html) - # self.write({ - # 'method': 'wrong', # FIXME js - # 'params': { - # 'question': tornado.escape.to_unicode(question_html), - # 'progress': self.learn.get_student_progress(user), - # 'comments': tornado.escape.to_unicode(comments_html), # FIXME - # 'tries': question['tries'], - # } - # }) + } + print(response) + self.write(response) - elif action == 'new_question': # get next question in the topic - template = self.templates[question['type']] - question_html = self.render_string(template, - question=question, md=md_to_html) - self.write({ - 'method': 'new_question', + elif action == 'wrong': # no more tries + comments_html = self.render_string('comments.html', + comments=q['comments'], md=md_to_html) + solution_html = self.render_string('solution.html', + solution=q['solution'], md=md_to_html) + + # template = self.templates[question['type']] + # question_html = self.render_string(template, question=question, md=md_to_html) + response = { + 'method': 'wrong', # FIXME js 'params': { - 'question': tornado.escape.to_unicode(question_html), + # 'question': tornado.escape.to_unicode(question_html), 'progress': self.learn.get_student_progress(user), - 'tries': question['tries'], + 'comments': tornado.escape.to_unicode(comments_html), # FIXME + 'solution': tornado.escape.to_unicode(solution_html), # FIXME + 'tries': q['tries'], } - }) + } + print(response) + self.write(response) + + elif action == 'new_question': # get next question in the topic + self.get() + # question = self.learn.get_current_question(user) + + # template = self.templates[question['type']] + # question_html = self.render_string(template, + # question=question, md=md_to_html) + # response = { + # 'method': 'new_question', + # 'params': { + # 'type': question['type'], + # 'question': tornado.escape.to_unicode(question_html), + # 'progress': self.learn.get_student_progress(user), + # 'tries': question['tries'], + # } + # } + # print(response) + # self.write(response) elif action == 'finished_topic': # right answer, finished topic finished_topic_html = self.render_string('finished_topic.html') - self.write({ + response = { 'method': 'finished_topic', 'params': { 'question': tornado.escape.to_unicode(finished_topic_html) } - }) + } + self.write(response) else: logger.error(f'Unknown action {action}') diff --git a/static/js/topic.js b/static/js/topic.js index b0aaad6..f50fe57 100644 --- a/static/js/topic.js +++ b/static/js/topic.js @@ -8,56 +8,76 @@ $.fn.extend({ }); -function new_question(question, tries, progress) { +function new_question(type, question, tries, progress) { + console.log("new_question " + type); + $("#question_div").html(question); $("#comments").html(""); + $("#solution").html(""); + if (type == "info") { + $("#submit").html("Continuar"); + } + else { + $("#submit").html("Responder"); + } + $("#submit").off(); + $("#submit").click(postAnswer); + $("#tries").html(tries); $('#topic_progress').css('width', (100*progress)+'%').attr('aria-valuenow', 100*progress); MathJax.Hub.Queue(["Typeset",MathJax.Hub,"question_div"]); + $('#question_div').animateCSS('bounceInDown'); - // enable shift+enter to submit and tab to spaces conversion - $("input:text, input:radio, input:checkbox").keydown(function (e) { - if (e.keyCode == 13) { - e.preventDefault(); - if (e.shiftKey) postQuestion(); - return false; - }}); + // enable shift+enter to submit + // $("input:text, input:radio, input:checkbox").keydown(function (e) { + // if (e.keyCode == 13) { + // e.preventDefault(); + // if (e.shiftKey) postQuestion(); + // return false; + // }}); } + + // updates question according to the response given by the server function updateQuestion(response){ + console.log('updateQuestion '+response["method"]); + + var method = response["method"]; + var params = response["params"]; + - switch (response["method"]) { + switch (method) { case "new_question": - params = response["params"]; - new_question(params["question"], params["tries"], params["progress"]); + console.log(params["type"]); + new_question(params["type"], params["question"], params["tries"], params["progress"]); break; case "try_again": - $('#topic_progress').css('width', (100*response["params"]["progress"])+'%').attr('aria-valuenow', 100*response["params"]["progress"]); $('#question_div').animateCSS('shake'); - $('#comments').html(response['params']['comments']); - $("#tries").html(response["params"]["tries"]); + $('#topic_progress').css('width', (100*params["progress"])+'%').attr('aria-valuenow', 100*params["progress"]); + $("#tries").html(params["tries"]); + $('#comments').html(params['comments']); MathJax.Hub.Queue(["Typeset",MathJax.Hub,"#comments"]); break; - // case "wrong": - // $('#topic_progress').css('width', (100*response["params"]["progress"])+'%').attr('aria-valuenow', 100*response["params"]["progress"]); - // $('#question_div').animateCSS('shake'); - // $('#comments').html(response['params']['comments']); - // $("#tries").html(response["params"]["tries"]); - // MathJax.Hub.Queue(["Typeset",MathJax.Hub,"#comments"]); - - // // setTimeout(function(){ - // new_question(response["params"]["question"], response["params"]["tries"], response["params"]["progress"]); - // // }, 5000); - // break; - - + case "wrong": + $('#question_div').animateCSS('shake'); + $('#topic_progress').css('width', (100*params["progress"])+'%').attr('aria-valuenow', 100*params["progress"]); + $("#tries").html(params["tries"]); + $('#comments').html(params['comments']); + MathJax.Hub.Queue(["Typeset", MathJax.Hub, "#comments"]); + $('#solution').html(params['solution']); + MathJax.Hub.Queue(["Typeset", MathJax.Hub, "#solution"]); + $("fieldset").attr("disabled", "disabled"); + $("#submit").html("Continuar"); + $("#submit").off(); + $("#submit").click(getQuestion); + break; case "finished_topic": - $('#submit').css("visibility", "hidden"); + $('#submit').hide(); //css("visibility", "hidden"); $("#content").html(response["params"]["question"]); $('#topic_progress').css('width', '100%').attr('aria-valuenow', 100); $("#content").animateCSS('tada'); @@ -68,6 +88,8 @@ function updateQuestion(response){ // Get current question function getQuestion() { + console.log("getQuestion"); + $.ajax({ type: "GET", url: "/question", @@ -80,7 +102,9 @@ function getQuestion() { // Send answer and receive a response. // The response can be a new_question or a shake if the answer is wrong, which // is then passed to updateQuestion() -function postQuestion() { +function postAnswer() { + console.log("postAnswer"); + if (typeof editor === 'object') editor.save(); @@ -94,7 +118,8 @@ function postQuestion() { }); } + $(document).ready(function() { getQuestion(); - $("#submit").click(postQuestion); + $("#submit").click(postAnswer); }); diff --git a/templates/comments.html b/templates/comments.html index 0108021..75c0984 100644 --- a/templates/comments.html +++ b/templates/comments.html @@ -1,9 +1,7 @@ {% autoescape %} {% if comments %} -
-
-

{{ md(comments) }}

-
+
+ {{ md(comments) }}
{% end %} diff --git a/templates/solution.html b/templates/solution.html new file mode 100644 index 0000000..f293ed0 --- /dev/null +++ b/templates/solution.html @@ -0,0 +1,8 @@ +{% autoescape %} + +{% if solution %} +
+

Solução

+ {{ md(solution) }} +
+{% end %} diff --git a/templates/topic.html b/templates/topic.html index 0f63297..7409621 100644 --- a/templates/topic.html +++ b/templates/topic.html @@ -79,13 +79,14 @@
+
-- libgit2 0.21.2