diff --git a/BUGS.md b/BUGS.md index 5ad9115..ce818f8 100644 --- a/BUGS.md +++ b/BUGS.md @@ -1,7 +1,7 @@ # BUGS -- falha no file handler de vez em quando, nao sei porquê... +- falha intermitent no file handler quando o browser envia 2 GET requests ao mesmo tempo (porquê?) - 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/serve.py b/serve.py index 22fb1fd..6c29311 100755 --- a/serve.py +++ b/serve.py @@ -16,6 +16,7 @@ import functools import tornado.ioloop import tornado.web import tornado.httpserver +from tornado.escape import to_unicode # this project from learnapp import LearnApp @@ -122,9 +123,9 @@ class ChangePasswordHandler(BaseHandler): changed_ok = await self.learn.change_password(uid, pw) if changed_ok: - notification = tornado.escape.to_unicode(self.render_string('notification.html', type='success', msg='A password foi alterada!')) + notification = to_unicode(self.render_string('notification.html', type='success', msg='A password foi alterada!')) else: - notification = tornado.escape.to_unicode(self.render_string('notification.html', type='danger', msg='A password não foi alterada!')) + notification = to_unicode(self.render_string('notification.html', type='danger', msg='A password não foi alterada!')) self.write({'msg': notification}) @@ -141,7 +142,6 @@ class RootHandler(BaseHandler): name=self.learn.get_student_name(uid), state=self.learn.get_student_state(uid), title=self.learn.get_title(), - # get_topic_type=self.learn.get_topic_type, # function ) @@ -172,12 +172,13 @@ class TopicHandler(BaseHandler): # ---------------------------------------------------------------------------- # FIXME error in many situations... images are not shown... - +# seems to happen when the browser sends two GET requests at the same time class FileHandler(BaseHandler): SUPPORTED_METHODS = ['GET'] @tornado.web.authenticated - async def get(self, filename): + # async + def get(self, filename): uid = self.current_user public_dir = self.learn.get_current_public_dir(uid) filepath = path.expanduser(path.join(public_dir, filename)) @@ -191,12 +192,13 @@ class FileHandler(BaseHandler): else: content_type = mimetypes.guess_type(filename) self.set_header("Content-Type", content_type[0]) - # divide the file into chunks and write one chunk at a time, so # that the write does not block the ioloop for very long. with f: - self.write(f.read()) - await self.flush() + data = f.read() + self.write(data) + # await self.flush() + self.flush() # ---------------------------------------------------------------------------- @@ -226,24 +228,24 @@ class QuestionHandler(BaseHandler): q = self.learn.get_current_question(user) if q is not None: - question_html = self.render_string(self.templates[q['type']], - question=q, md=md_to_html) + question_html = to_unicode(self.render_string(self.templates[q['type']], + question=q, md=md_to_html)) response = { 'method': 'new_question', 'params': { 'type': q['type'], - 'question': tornado.escape.to_unicode(question_html), + 'question': question_html, 'progress': self.learn.get_student_progress(user), 'tries': q['tries'], - }, + } } else: - finished_topic_html = self.render_string('finished_topic.html') + finished_topic_html = to_unicode(self.render_string('finished_topic.html')) response = { 'method': 'finished_topic', 'params': { - 'question': tornado.escape.to_unicode(finished_topic_html) + 'question': finished_topic_html } } @@ -275,8 +277,9 @@ class QuestionHandler(BaseHandler): comments=q['comments'], md=md_to_html) response['params'] = { + 'type': q['type'], 'progress': self.learn.get_student_progress(user), - 'comments': tornado.escape.to_unicode(comments_html), + 'comments': to_unicode(comments_html), 'tries': q['tries'], } @@ -285,21 +288,23 @@ class QuestionHandler(BaseHandler): comments=q['comments'], md=md_to_html) response['params'] = { + 'type': q['type'], 'progress': self.learn.get_student_progress(user), - 'comments': tornado.escape.to_unicode(comments_html), # FIXME + 'comments': to_unicode(comments_html), 'tries': q['tries'], } 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) + comments_html = to_unicode(self.render_string('comments.html', + comments=q['comments'], md=md_to_html)) + solution_html = to_unicode(self.render_string('solution.html', + solution=q['solution'], md=md_to_html)) response['params'] = { + 'type': q['type'], 'progress': self.learn.get_student_progress(user), - 'comments': tornado.escape.to_unicode(comments_html), - 'solution': tornado.escape.to_unicode(solution_html), + 'comments': comments_html, + 'solution': solution_html, 'tries': q['tries'], } diff --git a/static/js/topic.js b/static/js/topic.js index 4a5a51e..810471c 100644 --- a/static/js/topic.js +++ b/static/js/topic.js @@ -26,7 +26,6 @@ function updateQuestion(response) { switch (method) { case "new_question": - console.log(params["type"]); new_question(params["type"], params["question"], params["tries"], params["progress"]); break; case "finished_topic": @@ -52,8 +51,8 @@ function new_question(type, question, tries, progress) { } $("#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"]); @@ -90,11 +89,17 @@ function getFeedback(response) { var method = response["method"]; var params = response["params"]; + if (params['type'] == "info") { + getQuestion(); + return; + } + switch (method) { case "right": $('#comments').html(params['comments']); MathJax.Hub.Queue(["Typeset", MathJax.Hub, "#comments"]); $("#submit").html("Continuar"); + // $("#submit").toggleClass("btn-info btn-primary"); $("#submit").off(); $("#submit").click(getQuestion); break; @@ -123,7 +128,7 @@ function getFeedback(response) { } } - +// =========================================================================== $(document).ready(function() { getQuestion(); $("#submit").click(postAnswer); -- libgit2 0.21.2