Commit 29c8b4cb9768214b7f0bb03a19bb72b9dc100bab

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

- fixed FileHandler

- fixed enter-submit issue
BUGS.md
1 1  
2 2 BUGS:
3 3  
4   -- enter faz GET /question, que responde com json no ecran
  4 +- aumentar espaço a seguir às tabelas no texto
  5 +- guardar state cada vez que topico termina
5 6 - tabs em textarea nao funcionam correctamente (insere 1 espaco em vez de 4)
6 7 - reportar comentarios após submeter.
7   -- os topicos locked devem estar inactivos no sidebar.
8 8 - textarea deve mostrar no html os valores iniciais de ans, se existir
9 9 - detect questions in questions.yaml without ref -> error ou generate default.
10 10 - error if demo.yaml has no topics
11   -- guardar state cada vez que topico termina
12 11 - session management. close after inactive time.
13 12 - implementar xsrf. Ver [http://www.tornadoweb.org/en/stable/guide/security.html#cross-site-request-forgery-protection]()
14 13 - titulos das perguntas não suportam markdown
  14 +- generators not working: bcrypt (ver blog)
15 15  
16 16 TODO:
17 17  
18 18 - pymips: activar/desactivar instruções
19 19 - implementar servidor http com redirect para https.
20 20 - usar codemirror no textarea
21   -- generators not working: bcrypt (ver blog)
22 21  
23 22 FIXED:
24 23  
  24 +- os topicos locked devem estar inactivos no sidebar.
  25 +- enter faz GET /question, que responde com json no ecran. (solution: disabled enter)
25 26 - topicos no sidebar devem ser links para iniciar um topico acessivel.
26 27 - logs inicio de topico
27 28 - indicar o topico actual no sidebar
... ...
knowledge.py
... ... @@ -88,12 +88,9 @@ class Knowledge(object):
88 88 # new question if answer is correct
89 89 if grade > 0.999:
90 90 self.finished_questions.append(q)
91   - print('questions: ', self.questions)
92   - print('finished: ', self.finished_questions)
93 91 try:
94 92 self.current_question = self.questions.pop(0) # FIXME empty?
95 93 except IndexError:
96   - print('no more questions!')
97 94 self.current_question = None
98 95 self.state[self.current_topic] = {
99 96 'level': 1.0,
... ... @@ -103,10 +100,8 @@ class Knowledge(object):
103 100 else:
104 101 self.current_question['start_time'] = datetime.now()
105 102 else:
106   - # FIXME debug this
107 103 factory = self.depgraph.node[self.current_topic]['factory']
108 104 self.questions.append(factory[q['ref']].generate())
109   - print([q['ref'] for q in self.questions])
110 105  
111 106 return q
112 107  
... ... @@ -135,11 +130,6 @@ class Knowledge(object):
135 130 if t in self.state:
136 131 ts.append((t, self.state[t]['level'])) # already done
137 132 else:
138   - # deps = self.depgraph.predecessors(t)
139   - # # print(t, deps)
140   - # if all(d in self.state for d in deps):
141   - # ts.append((t, 0.0)) # unlocked not yet done
142   - # else:
143 133 ts.append((t, None)) # locked
144 134 return ts
145 135  
... ...
serve.py
... ... @@ -134,11 +134,14 @@ class FileHandler(BaseHandler):
134 134 def get(self, filename):
135 135 uid = self.current_user
136 136 public_dir = self.learn.get_current_public_dir(uid)
  137 + filepath = os.path.expanduser(os.path.join(public_dir, filename))
137 138 try:
138   - with open(os.path.join(public_dir, filename), 'rb') as f:
139   - self.write(f.read())
  139 + f = open(filepath, 'rb')
140 140 except FileNotFoundError:
141 141 raise tornado.web.HTTPError(404)
  142 + else:
  143 + self.write(f.read())
  144 + f.close()
142 145  
143 146 # ----------------------------------------------------------------------------
144 147 # respond to AJAX to get a JSON question
... ...
templates/learn.html
... ... @@ -165,9 +165,9 @@ function updateQuestion(response){
165 165  
166 166 // enable shift+enter to submit and tab to spaces conversion
167 167 $("input:text, input:radio, input:checkbox").keydown(function (e) {
168   - if (e.keyCode == 13 && e.shiftKey) {
  168 + if (e.keyCode == 13) {
169 169 e.preventDefault();
170   - postQuestion();
  170 + if (e.shiftKey) postQuestion();
171 171 return false;
172 172 }
173 173 });
... ...