Commit 563f62ceafe1c756f6407cb511249dee5f2142db

Authored by Miguel Barão
1 parent 2285f4a5
Exists in master and in 1 other branch dev

- disabled submit during animations (fixes synchronization problems)

- changed FileHandler to close the file immediately after reading it
BUGS.md
1 1  
2 2 # BUGS
3 3  
4   -- botao para mostrar a solução quando se acerta.
5 4 - shift-enter não está a funcionar
6 5 - falha intermitent no file handler quando o browser envia 2 GET requests ao mesmo tempo (porquê?)
7 6 - nos topicos learn.yaml, qd falha acrescenta no fim. nao faz sentido.
... ... @@ -34,6 +33,8 @@
34 33  
35 34 # FIXED
36 35  
  36 +- quando se pressiona "responde" rapido (enquanto a animacao dura), a pergunta passa para a seguinte sem haver o correspondente redraw, ou seja a proxima resposta nao é a da pergunta mostrada.
  37 +- botao para mostrar a solução quando se acerta.
37 38 - não está a guardar o resultado no final do topico
38 39 - esta a permitir 2 logins em simultaneo do mesmo user. fica tudo baralhado se mxerem em simultaneo...
39 40 - errar no ultimo topico nao mostra solucao?
... ...
serve.py
... ... @@ -178,11 +178,11 @@ class FileHandler(BaseHandler):
178 178 SUPPORTED_METHODS = ['GET']
179 179  
180 180 @tornado.web.authenticated
181   - # async
182   - def get(self, filename):
  181 + async def get(self, filename):
183 182 uid = self.current_user
184 183 public_dir = self.learn.get_current_public_dir(uid)
185 184 filepath = path.expanduser(path.join(public_dir, filename))
  185 + content_type, encoding = mimetypes.guess_type(filename)
186 186  
187 187 try:
188 188 f = open(filepath, 'rb')
... ... @@ -190,16 +190,16 @@ class FileHandler(BaseHandler):
190 190 logging.error(f'File not found: {filepath}')
191 191 except PermissionError:
192 192 logging.error(f'No permission: {filepath}')
  193 + except Exception as e:
  194 + raise e
193 195 else:
194   - content_type = mimetypes.guess_type(filename)
195   - self.set_header("Content-Type", content_type[0])
196   - # divide the file into chunks and write one chunk at a time, so
197   - # that the write does not block the ioloop for very long.
198 196 with f:
199 197 data = f.read()
  198 + f.close()
  199 + self.set_header("Content-Type", content_type)
200 200 self.write(data)
201   - # await self.flush()
202   - self.flush()
  201 + await self.flush()
  202 + # self.flush()
203 203  
204 204  
205 205 # ----------------------------------------------------------------------------
... ...
static/js/topic.js
... ... @@ -3,6 +3,7 @@ $.fn.extend({
3 3 var animationEnd = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend';
4 4 this.addClass('animated ' + animation).one(animationEnd, function() {
5 5 $(this).removeClass('animated ' + animation);
  6 + $("#submit").removeClass("disabled");
6 7 });
7 8 }
8 9 });
... ... @@ -27,6 +28,8 @@ function showTriesLeft(tries) {
27 28  
28 29 // Get current question
29 30 function getQuestion() {
  31 + $("#submit").addClass("disabled");
  32 +
30 33 $.ajax({
31 34 type: "GET",
32 35 url: "/question",
... ... @@ -42,7 +45,7 @@ function updateQuestion(response) {
42 45 var method = response["method"];
43 46 var params = response["params"];
44 47  
45   - $('#right, #wrong').hide();
  48 + $("#right, #wrong").hide();
46 49  
47 50 switch (method) {
48 51 case "new_question":
... ... @@ -63,8 +66,8 @@ function new_question(type, question, tries, progress) {
63 66 $("#question_div").html(question).animateCSS('bounceInDown');
64 67 showTriesLeft(tries);
65 68 $("#comments, #solution").html("");
66   - var btn_text = (type == "info") ? "Continuar" : "Responder";
67   - $("#submit").html(btn_text).off().click(postAnswer);
  69 + var btntext = (type == "info") ? "Continuar" : "Responder";
  70 + $("#submit").html(btntext).off().click(postAnswer);
68 71 $('#topic_progress').css('width', (100*progress)+'%').attr('aria-valuenow', 100*progress);
69 72 MathJax.Hub.Queue(["Typeset",MathJax.Hub,"question_div"]);
70 73  
... ...
templates/topic.html
... ... @@ -111,6 +111,7 @@
111 111  
112 112 <div id="solution"></div>
113 113  
  114 + <!-- reponder / continuar -->
114 115 <a class="btn btn-primary btn-lg btn-block my-5" id="submit" data-toggle="tooltip" data-placement="right" href="#solution"></a>
115 116 <!-- title="Shift-Enter" -->
116 117 </div>
... ...