Commit e6915ba05f9c4729557ff39bb12f8c476312ccc8
1 parent
51627bcc
Exists in
master
and in
1 other branch
- code cleanup.
- fixed info questions to continue with a single button click.
Showing
3 changed files
with
36 additions
and
26 deletions
Show diff stats
BUGS.md
| 1 | 1 | ||
| 2 | # BUGS | 2 | # BUGS |
| 3 | 3 | ||
| 4 | -- falha no file handler de vez em quando, nao sei porquê... | 4 | +- falha intermitent no file handler quando o browser envia 2 GET requests ao mesmo tempo (porquê?) |
| 5 | - nos topicos learn.yaml, qd falha acrescenta no fim. nao faz sentido. | 5 | - nos topicos learn.yaml, qd falha acrescenta no fim. nao faz sentido. |
| 6 | - 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... | 6 | - 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... |
| 7 | 7 |
serve.py
| @@ -16,6 +16,7 @@ import functools | @@ -16,6 +16,7 @@ import functools | ||
| 16 | import tornado.ioloop | 16 | import tornado.ioloop |
| 17 | import tornado.web | 17 | import tornado.web |
| 18 | import tornado.httpserver | 18 | import tornado.httpserver |
| 19 | +from tornado.escape import to_unicode | ||
| 19 | 20 | ||
| 20 | # this project | 21 | # this project |
| 21 | from learnapp import LearnApp | 22 | from learnapp import LearnApp |
| @@ -122,9 +123,9 @@ class ChangePasswordHandler(BaseHandler): | @@ -122,9 +123,9 @@ class ChangePasswordHandler(BaseHandler): | ||
| 122 | 123 | ||
| 123 | changed_ok = await self.learn.change_password(uid, pw) | 124 | changed_ok = await self.learn.change_password(uid, pw) |
| 124 | if changed_ok: | 125 | if changed_ok: |
| 125 | - notification = tornado.escape.to_unicode(self.render_string('notification.html', type='success', msg='A password foi alterada!')) | 126 | + notification = to_unicode(self.render_string('notification.html', type='success', msg='A password foi alterada!')) |
| 126 | else: | 127 | else: |
| 127 | - notification = tornado.escape.to_unicode(self.render_string('notification.html', type='danger', msg='A password não foi alterada!')) | 128 | + notification = to_unicode(self.render_string('notification.html', type='danger', msg='A password não foi alterada!')) |
| 128 | self.write({'msg': notification}) | 129 | self.write({'msg': notification}) |
| 129 | 130 | ||
| 130 | 131 | ||
| @@ -141,7 +142,6 @@ class RootHandler(BaseHandler): | @@ -141,7 +142,6 @@ class RootHandler(BaseHandler): | ||
| 141 | name=self.learn.get_student_name(uid), | 142 | name=self.learn.get_student_name(uid), |
| 142 | state=self.learn.get_student_state(uid), | 143 | state=self.learn.get_student_state(uid), |
| 143 | title=self.learn.get_title(), | 144 | title=self.learn.get_title(), |
| 144 | - # get_topic_type=self.learn.get_topic_type, # function | ||
| 145 | ) | 145 | ) |
| 146 | 146 | ||
| 147 | 147 | ||
| @@ -172,12 +172,13 @@ class TopicHandler(BaseHandler): | @@ -172,12 +172,13 @@ class TopicHandler(BaseHandler): | ||
| 172 | # ---------------------------------------------------------------------------- | 172 | # ---------------------------------------------------------------------------- |
| 173 | 173 | ||
| 174 | # FIXME error in many situations... images are not shown... | 174 | # FIXME error in many situations... images are not shown... |
| 175 | - | 175 | +# seems to happen when the browser sends two GET requests at the same time |
| 176 | class FileHandler(BaseHandler): | 176 | class FileHandler(BaseHandler): |
| 177 | SUPPORTED_METHODS = ['GET'] | 177 | SUPPORTED_METHODS = ['GET'] |
| 178 | 178 | ||
| 179 | @tornado.web.authenticated | 179 | @tornado.web.authenticated |
| 180 | - async def get(self, filename): | 180 | + # async |
| 181 | + def get(self, filename): | ||
| 181 | uid = self.current_user | 182 | uid = self.current_user |
| 182 | public_dir = self.learn.get_current_public_dir(uid) | 183 | public_dir = self.learn.get_current_public_dir(uid) |
| 183 | filepath = path.expanduser(path.join(public_dir, filename)) | 184 | filepath = path.expanduser(path.join(public_dir, filename)) |
| @@ -191,12 +192,13 @@ class FileHandler(BaseHandler): | @@ -191,12 +192,13 @@ class FileHandler(BaseHandler): | ||
| 191 | else: | 192 | else: |
| 192 | content_type = mimetypes.guess_type(filename) | 193 | content_type = mimetypes.guess_type(filename) |
| 193 | self.set_header("Content-Type", content_type[0]) | 194 | self.set_header("Content-Type", content_type[0]) |
| 194 | - | ||
| 195 | # divide the file into chunks and write one chunk at a time, so | 195 | # divide the file into chunks and write one chunk at a time, so |
| 196 | # that the write does not block the ioloop for very long. | 196 | # that the write does not block the ioloop for very long. |
| 197 | with f: | 197 | with f: |
| 198 | - self.write(f.read()) | ||
| 199 | - await self.flush() | 198 | + data = f.read() |
| 199 | + self.write(data) | ||
| 200 | + # await self.flush() | ||
| 201 | + self.flush() | ||
| 200 | 202 | ||
| 201 | 203 | ||
| 202 | # ---------------------------------------------------------------------------- | 204 | # ---------------------------------------------------------------------------- |
| @@ -226,24 +228,24 @@ class QuestionHandler(BaseHandler): | @@ -226,24 +228,24 @@ class QuestionHandler(BaseHandler): | ||
| 226 | q = self.learn.get_current_question(user) | 228 | q = self.learn.get_current_question(user) |
| 227 | 229 | ||
| 228 | if q is not None: | 230 | if q is not None: |
| 229 | - question_html = self.render_string(self.templates[q['type']], | ||
| 230 | - question=q, md=md_to_html) | 231 | + question_html = to_unicode(self.render_string(self.templates[q['type']], |
| 232 | + question=q, md=md_to_html)) | ||
| 231 | response = { | 233 | response = { |
| 232 | 'method': 'new_question', | 234 | 'method': 'new_question', |
| 233 | 'params': { | 235 | 'params': { |
| 234 | 'type': q['type'], | 236 | 'type': q['type'], |
| 235 | - 'question': tornado.escape.to_unicode(question_html), | 237 | + 'question': question_html, |
| 236 | 'progress': self.learn.get_student_progress(user), | 238 | 'progress': self.learn.get_student_progress(user), |
| 237 | 'tries': q['tries'], | 239 | 'tries': q['tries'], |
| 238 | - }, | 240 | + } |
| 239 | } | 241 | } |
| 240 | 242 | ||
| 241 | else: | 243 | else: |
| 242 | - finished_topic_html = self.render_string('finished_topic.html') | 244 | + finished_topic_html = to_unicode(self.render_string('finished_topic.html')) |
| 243 | response = { | 245 | response = { |
| 244 | 'method': 'finished_topic', | 246 | 'method': 'finished_topic', |
| 245 | 'params': { | 247 | 'params': { |
| 246 | - 'question': tornado.escape.to_unicode(finished_topic_html) | 248 | + 'question': finished_topic_html |
| 247 | } | 249 | } |
| 248 | } | 250 | } |
| 249 | 251 | ||
| @@ -275,8 +277,9 @@ class QuestionHandler(BaseHandler): | @@ -275,8 +277,9 @@ class QuestionHandler(BaseHandler): | ||
| 275 | comments=q['comments'], md=md_to_html) | 277 | comments=q['comments'], md=md_to_html) |
| 276 | 278 | ||
| 277 | response['params'] = { | 279 | response['params'] = { |
| 280 | + 'type': q['type'], | ||
| 278 | 'progress': self.learn.get_student_progress(user), | 281 | 'progress': self.learn.get_student_progress(user), |
| 279 | - 'comments': tornado.escape.to_unicode(comments_html), | 282 | + 'comments': to_unicode(comments_html), |
| 280 | 'tries': q['tries'], | 283 | 'tries': q['tries'], |
| 281 | } | 284 | } |
| 282 | 285 | ||
| @@ -285,21 +288,23 @@ class QuestionHandler(BaseHandler): | @@ -285,21 +288,23 @@ class QuestionHandler(BaseHandler): | ||
| 285 | comments=q['comments'], md=md_to_html) | 288 | comments=q['comments'], md=md_to_html) |
| 286 | 289 | ||
| 287 | response['params'] = { | 290 | response['params'] = { |
| 291 | + 'type': q['type'], | ||
| 288 | 'progress': self.learn.get_student_progress(user), | 292 | 'progress': self.learn.get_student_progress(user), |
| 289 | - 'comments': tornado.escape.to_unicode(comments_html), # FIXME | 293 | + 'comments': to_unicode(comments_html), |
| 290 | 'tries': q['tries'], | 294 | 'tries': q['tries'], |
| 291 | } | 295 | } |
| 292 | 296 | ||
| 293 | elif action == 'wrong': # no more tries | 297 | elif action == 'wrong': # no more tries |
| 294 | - comments_html = self.render_string('comments.html', | ||
| 295 | - comments=q['comments'], md=md_to_html) | ||
| 296 | - solution_html = self.render_string('solution.html', | ||
| 297 | - solution=q['solution'], md=md_to_html) | 298 | + comments_html = to_unicode(self.render_string('comments.html', |
| 299 | + comments=q['comments'], md=md_to_html)) | ||
| 300 | + solution_html = to_unicode(self.render_string('solution.html', | ||
| 301 | + solution=q['solution'], md=md_to_html)) | ||
| 298 | 302 | ||
| 299 | response['params'] = { | 303 | response['params'] = { |
| 304 | + 'type': q['type'], | ||
| 300 | 'progress': self.learn.get_student_progress(user), | 305 | 'progress': self.learn.get_student_progress(user), |
| 301 | - 'comments': tornado.escape.to_unicode(comments_html), | ||
| 302 | - 'solution': tornado.escape.to_unicode(solution_html), | 306 | + 'comments': comments_html, |
| 307 | + 'solution': solution_html, | ||
| 303 | 'tries': q['tries'], | 308 | 'tries': q['tries'], |
| 304 | } | 309 | } |
| 305 | 310 |
static/js/topic.js
| @@ -26,7 +26,6 @@ function updateQuestion(response) { | @@ -26,7 +26,6 @@ function updateQuestion(response) { | ||
| 26 | 26 | ||
| 27 | switch (method) { | 27 | switch (method) { |
| 28 | case "new_question": | 28 | case "new_question": |
| 29 | - console.log(params["type"]); | ||
| 30 | new_question(params["type"], params["question"], params["tries"], params["progress"]); | 29 | new_question(params["type"], params["question"], params["tries"], params["progress"]); |
| 31 | break; | 30 | break; |
| 32 | case "finished_topic": | 31 | case "finished_topic": |
| @@ -52,8 +51,8 @@ function new_question(type, question, tries, progress) { | @@ -52,8 +51,8 @@ function new_question(type, question, tries, progress) { | ||
| 52 | } | 51 | } |
| 53 | $("#submit").off(); | 52 | $("#submit").off(); |
| 54 | $("#submit").click(postAnswer); | 53 | $("#submit").click(postAnswer); |
| 55 | - | ||
| 56 | $("#tries").html(tries); | 54 | $("#tries").html(tries); |
| 55 | + | ||
| 57 | $('#topic_progress').css('width', (100*progress)+'%').attr('aria-valuenow', 100*progress); | 56 | $('#topic_progress').css('width', (100*progress)+'%').attr('aria-valuenow', 100*progress); |
| 58 | MathJax.Hub.Queue(["Typeset",MathJax.Hub,"question_div"]); | 57 | MathJax.Hub.Queue(["Typeset",MathJax.Hub,"question_div"]); |
| 59 | 58 | ||
| @@ -90,11 +89,17 @@ function getFeedback(response) { | @@ -90,11 +89,17 @@ function getFeedback(response) { | ||
| 90 | var method = response["method"]; | 89 | var method = response["method"]; |
| 91 | var params = response["params"]; | 90 | var params = response["params"]; |
| 92 | 91 | ||
| 92 | + if (params['type'] == "info") { | ||
| 93 | + getQuestion(); | ||
| 94 | + return; | ||
| 95 | + } | ||
| 96 | + | ||
| 93 | switch (method) { | 97 | switch (method) { |
| 94 | case "right": | 98 | case "right": |
| 95 | $('#comments').html(params['comments']); | 99 | $('#comments').html(params['comments']); |
| 96 | MathJax.Hub.Queue(["Typeset", MathJax.Hub, "#comments"]); | 100 | MathJax.Hub.Queue(["Typeset", MathJax.Hub, "#comments"]); |
| 97 | $("#submit").html("Continuar"); | 101 | $("#submit").html("Continuar"); |
| 102 | + // $("#submit").toggleClass("btn-info btn-primary"); | ||
| 98 | $("#submit").off(); | 103 | $("#submit").off(); |
| 99 | $("#submit").click(getQuestion); | 104 | $("#submit").click(getQuestion); |
| 100 | break; | 105 | break; |
| @@ -123,7 +128,7 @@ function getFeedback(response) { | @@ -123,7 +128,7 @@ function getFeedback(response) { | ||
| 123 | } | 128 | } |
| 124 | } | 129 | } |
| 125 | 130 | ||
| 126 | - | 131 | +// =========================================================================== |
| 127 | $(document).ready(function() { | 132 | $(document).ready(function() { |
| 128 | getQuestion(); | 133 | getQuestion(); |
| 129 | $("#submit").click(postAnswer); | 134 | $("#submit").click(postAnswer); |