Commit bbdca9b8ded8a684c6cca7056233e512478ea90a

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

- fixed error when topic/wrong_name was given in the addressbar

Showing 3 changed files with 35 additions and 23 deletions   Show diff stats
1 1
2 BUGS: 2 BUGS:
3 3
4 -- barra de progresso nao está visível. 4 +- templates not working: quesntion-information, question-warning (remove all informative panels??)
  5 +- link directo para topico nao valida se topico esta unlocked.
5 - reportar comentarios após submeter. 6 - reportar comentarios após submeter.
6 - forçar reload das perguntas sem ter de deitar abaixo o servidor. 7 - forçar reload das perguntas sem ter de deitar abaixo o servidor.
7 - topicos virtuais nao deveriam aparecer. na construção da árvore os sucessores seriam ligados directamente aos predecessores. 8 - topicos virtuais nao deveriam aparecer. na construção da árvore os sucessores seriam ligados directamente aos predecessores.
@@ -33,6 +34,8 @@ TODO: @@ -33,6 +34,8 @@ TODO:
33 34
34 FIXED: 35 FIXED:
35 36
  37 +- enderecos errados dao internal error.
  38 +- barra de progresso nao está visível.
36 - tabs em textarea nao funcionam correctamente (insere 1 espaco em vez de 4) 39 - tabs em textarea nao funcionam correctamente (insere 1 espaco em vez de 4)
37 - guardar state cada vez que topico termina 40 - guardar state cada vez que topico termina
38 - textarea deve mostrar no html os valores iniciais de ans, se existirem 41 - textarea deve mostrar no html os valores iniciais de ans, se existirem
@@ -51,12 +51,12 @@ class LearnApp(object): @@ -51,12 +51,12 @@ class LearnApp(object):
51 with self.db_session() as s: 51 with self.db_session() as s:
52 student = s.query(Student).filter(Student.id == uid).one_or_none() 52 student = s.query(Student).filter(Student.id == uid).one_or_none()
53 if student is None: 53 if student is None:
54 - logger.info(f'User "{uid}" does not exist.') 54 + logger.info(f'User "{uid}" does not exist!')
55 return False # student does not exist 55 return False # student does not exist
56 56
57 hashedtry = bcrypt.hashpw(try_pw.encode('utf-8'), student.password) 57 hashedtry = bcrypt.hashpw(try_pw.encode('utf-8'), student.password)
58 if hashedtry != student.password: 58 if hashedtry != student.password:
59 - logger.info(f'User "{uid}" wrong password.') 59 + logger.info(f'User "{uid}" wrong password!')
60 return False # wrong password 60 return False # wrong password
61 61
62 # success 62 # success
@@ -146,8 +146,13 @@ class LearnApp(object): @@ -146,8 +146,13 @@ class LearnApp(object):
146 # Start new topic 146 # Start new topic
147 # ------------------------------------------------------------------------ 147 # ------------------------------------------------------------------------
148 def start_topic(self, uid, topic): 148 def start_topic(self, uid, topic):
149 - self.online[uid]['state'].init_topic(topic)  
150 - logger.info(f'User "{uid}" started "{topic}"') 149 + try:
  150 + self.online[uid]['state'].init_topic(topic)
  151 + except KeyError as e:
  152 + logger.warning(f'User "{uid}" trying to start nonexistent "{topic}"')
  153 + raise e
  154 + else:
  155 + logger.info(f'User "{uid}" started "{topic}"')
151 156
152 # ------------------------------------------------------------------------ 157 # ------------------------------------------------------------------------
153 # Fill db table 'Topic' with topics from the graph if not already there. 158 # Fill db table 'Topic' with topics from the graph if not already there.
@@ -158,7 +163,7 @@ class LearnApp(object): @@ -158,7 +163,7 @@ class LearnApp(object):
158 missing_topics = [Topic(id=n) for n in nn if n not in tt] 163 missing_topics = [Topic(id=n) for n in nn if n not in tt]
159 if missing_topics: 164 if missing_topics:
160 s.add_all(missing_topics) 165 s.add_all(missing_topics)
161 - logger.info(f'Added {len(missing_topics)} new topics to the database.') 166 + logger.info(f'Added {len(missing_topics)} new topics to the database')
162 167
163 # ------------------------------------------------------------------------ 168 # ------------------------------------------------------------------------
164 # setup and check database 169 # setup and check database
@@ -173,12 +178,12 @@ class LearnApp(object): @@ -173,12 +178,12 @@ class LearnApp(object):
173 m = s.query(Topic).count() 178 m = s.query(Topic).count()
174 q = s.query(Answer).count() 179 q = s.query(Answer).count()
175 except Exception as e: 180 except Exception as e:
176 - logger.critical(f'Database "{db}" not usable.') 181 + logger.critical(f'Database "{db}" not usable!')
177 sys.exit(1) 182 sys.exit(1)
178 else: 183 else:
179 - logger.info(f'{n:6} students.')  
180 - logger.info(f'{m:6} topics.')  
181 - logger.info(f'{q:6} answers.') 184 + logger.info(f'{n:6} students')
  185 + logger.info(f'{m:6} topics')
  186 + logger.info(f'{q:6} answers')
182 187
183 # ------------------------------------------------------------------------ 188 # ------------------------------------------------------------------------
184 # helper to manage db sessions using the `with` statement, for example 189 # helper to manage db sessions using the `with` statement, for example
@@ -30,8 +30,8 @@ class WebApplication(tornado.web.Application): @@ -30,8 +30,8 @@ class WebApplication(tornado.web.Application):
30 (r'/change_password', ChangePasswordHandler), 30 (r'/change_password', ChangePasswordHandler),
31 (r'/question', QuestionHandler), # each question 31 (r'/question', QuestionHandler), # each question
32 (r'/topic/(.+)', TopicHandler), # page for doing a topic 32 (r'/topic/(.+)', TopicHandler), # page for doing a topic
33 - (r'/', RootHandler), # show list of topics  
34 - # (r'/file/(.+)', FileHandler), # FIXME 33 + # (r'/file/(.+)', FileHandler), # FIXME
  34 + (r'/.*', RootHandler), # show list of topics
35 ] 35 ]
36 settings = { 36 settings = {
37 'template_path': path.join(path.dirname(__file__), 'templates'), 37 'template_path': path.join(path.dirname(__file__), 'templates'),
@@ -121,19 +121,23 @@ class RootHandler(BaseHandler): @@ -121,19 +121,23 @@ class RootHandler(BaseHandler):
121 ) 121 )
122 122
123 # ---------------------------------------------------------------------------- 123 # ----------------------------------------------------------------------------
124 -# Start a given topic: /topic 124 +# Start a given topic: /topic/...
125 # ---------------------------------------------------------------------------- 125 # ----------------------------------------------------------------------------
126 class TopicHandler(BaseHandler): 126 class TopicHandler(BaseHandler):
127 @tornado.web.authenticated 127 @tornado.web.authenticated
128 def get(self, topic): 128 def get(self, topic):
129 uid = self.current_user 129 uid = self.current_user
130 130
131 - self.learn.start_topic(uid, topic)  
132 -  
133 - self.render('topic.html',  
134 - uid=uid,  
135 - name=self.learn.get_student_name(uid),  
136 - ) 131 + try:
  132 + self.learn.start_topic(uid, topic)
  133 + except KeyError:
  134 + self.redirect('/')
  135 + # raise tornado.web.HTTPError(404)
  136 + else:
  137 + self.render('topic.html',
  138 + uid=uid,
  139 + name=self.learn.get_student_name(uid),
  140 + )
137 141
138 142
139 # ---------------------------------------------------------------------------- 143 # ----------------------------------------------------------------------------
@@ -163,9 +167,9 @@ class QuestionHandler(BaseHandler): @@ -163,9 +167,9 @@ class QuestionHandler(BaseHandler):
163 'numeric-interval': 'question-text.html', 167 'numeric-interval': 'question-text.html',
164 'textarea': 'question-textarea.html', 168 'textarea': 'question-textarea.html',
165 # -- information panels -- 169 # -- information panels --
166 - 'information': 'question-information.html',  
167 - 'info': 'question-information.html',  
168 - 'success': 'question-success.html', 170 + 'information': 'question-information.html',
  171 + 'info': 'question-information.html',
  172 + 'success': 'question-success.html',
169 # 'warning': '', FIXME 173 # 'warning': '', FIXME
170 # 'warn': '', FIXME 174 # 'warn': '', FIXME
171 # 'alert': '', FIXME 175 # 'alert': '', FIXME
@@ -276,7 +280,7 @@ def main(): @@ -276,7 +280,7 @@ def main():
276 learnapp = LearnApp(arg.conffile[0]) 280 learnapp = LearnApp(arg.conffile[0])
277 281
278 # --- create web application 282 # --- create web application
279 - logging.info('Starting Web App (tornado).') 283 + logging.info('Starting Web App (tornado)')
280 try: 284 try:
281 webapp = WebApplication(learnapp, debug=arg.debug) 285 webapp = WebApplication(learnapp, debug=arg.debug)
282 except Exception as e: 286 except Exception as e: