From bbdca9b8ded8a684c6cca7056233e512478ea90a Mon Sep 17 00:00:00 2001 From: Miguel Barao Date: Fri, 12 Jan 2018 12:49:08 +0000 Subject: [PATCH] - fixed error when topic/wrong_name was given in the addressbar --- BUGS.md | 5 ++++- learnapp.py | 23 ++++++++++++++--------- serve.py | 30 +++++++++++++++++------------- 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/BUGS.md b/BUGS.md index e08bba9..209ed42 100644 --- a/BUGS.md +++ b/BUGS.md @@ -1,7 +1,8 @@ BUGS: -- barra de progresso nao está visível. +- templates not working: quesntion-information, question-warning (remove all informative panels??) +- link directo para topico nao valida se topico esta unlocked. - reportar comentarios após submeter. - forçar reload das perguntas sem ter de deitar abaixo o servidor. - topicos virtuais nao deveriam aparecer. na construção da árvore os sucessores seriam ligados directamente aos predecessores. @@ -33,6 +34,8 @@ TODO: FIXED: +- enderecos errados dao internal error. +- barra de progresso nao está visível. - tabs em textarea nao funcionam correctamente (insere 1 espaco em vez de 4) - guardar state cada vez que topico termina - textarea deve mostrar no html os valores iniciais de ans, se existirem diff --git a/learnapp.py b/learnapp.py index 6e0ae00..52c444a 100644 --- a/learnapp.py +++ b/learnapp.py @@ -51,12 +51,12 @@ class LearnApp(object): with self.db_session() as s: student = s.query(Student).filter(Student.id == uid).one_or_none() if student is None: - logger.info(f'User "{uid}" does not exist.') + logger.info(f'User "{uid}" does not exist!') return False # student does not exist hashedtry = bcrypt.hashpw(try_pw.encode('utf-8'), student.password) if hashedtry != student.password: - logger.info(f'User "{uid}" wrong password.') + logger.info(f'User "{uid}" wrong password!') return False # wrong password # success @@ -146,8 +146,13 @@ class LearnApp(object): # Start new topic # ------------------------------------------------------------------------ def start_topic(self, uid, topic): - self.online[uid]['state'].init_topic(topic) - logger.info(f'User "{uid}" started "{topic}"') + try: + self.online[uid]['state'].init_topic(topic) + except KeyError as e: + logger.warning(f'User "{uid}" trying to start nonexistent "{topic}"') + raise e + else: + logger.info(f'User "{uid}" started "{topic}"') # ------------------------------------------------------------------------ # Fill db table 'Topic' with topics from the graph if not already there. @@ -158,7 +163,7 @@ class LearnApp(object): missing_topics = [Topic(id=n) for n in nn if n not in tt] if missing_topics: s.add_all(missing_topics) - logger.info(f'Added {len(missing_topics)} new topics to the database.') + logger.info(f'Added {len(missing_topics)} new topics to the database') # ------------------------------------------------------------------------ # setup and check database @@ -173,12 +178,12 @@ class LearnApp(object): m = s.query(Topic).count() q = s.query(Answer).count() except Exception as e: - logger.critical(f'Database "{db}" not usable.') + logger.critical(f'Database "{db}" not usable!') sys.exit(1) else: - logger.info(f'{n:6} students.') - logger.info(f'{m:6} topics.') - logger.info(f'{q:6} answers.') + logger.info(f'{n:6} students') + logger.info(f'{m:6} topics') + logger.info(f'{q:6} answers') # ------------------------------------------------------------------------ # helper to manage db sessions using the `with` statement, for example diff --git a/serve.py b/serve.py index bcd7470..aec2ec8 100755 --- a/serve.py +++ b/serve.py @@ -30,8 +30,8 @@ class WebApplication(tornado.web.Application): (r'/change_password', ChangePasswordHandler), (r'/question', QuestionHandler), # each question (r'/topic/(.+)', TopicHandler), # page for doing a topic - (r'/', RootHandler), # show list of topics - # (r'/file/(.+)', FileHandler), # FIXME + # (r'/file/(.+)', FileHandler), # FIXME + (r'/.*', RootHandler), # show list of topics ] settings = { 'template_path': path.join(path.dirname(__file__), 'templates'), @@ -121,19 +121,23 @@ class RootHandler(BaseHandler): ) # ---------------------------------------------------------------------------- -# Start a given topic: /topic +# Start a given topic: /topic/... # ---------------------------------------------------------------------------- class TopicHandler(BaseHandler): @tornado.web.authenticated def get(self, topic): uid = self.current_user - self.learn.start_topic(uid, topic) - - self.render('topic.html', - uid=uid, - name=self.learn.get_student_name(uid), - ) + try: + self.learn.start_topic(uid, topic) + except KeyError: + self.redirect('/') + # raise tornado.web.HTTPError(404) + else: + self.render('topic.html', + uid=uid, + name=self.learn.get_student_name(uid), + ) # ---------------------------------------------------------------------------- @@ -163,9 +167,9 @@ class QuestionHandler(BaseHandler): 'numeric-interval': 'question-text.html', 'textarea': 'question-textarea.html', # -- information panels -- - 'information': 'question-information.html', - 'info': 'question-information.html', - 'success': 'question-success.html', + 'information': 'question-information.html', + 'info': 'question-information.html', + 'success': 'question-success.html', # 'warning': '', FIXME # 'warn': '', FIXME # 'alert': '', FIXME @@ -276,7 +280,7 @@ def main(): learnapp = LearnApp(arg.conffile[0]) # --- create web application - logging.info('Starting Web App (tornado).') + logging.info('Starting Web App (tornado)') try: webapp = WebApplication(learnapp, debug=arg.debug) except Exception as e: -- libgit2 0.21.2