From 717aa0b3f71d3f96171025357c66009177640ef6 Mon Sep 17 00:00:00 2001 From: Miguel Barão Date: Wed, 28 Feb 2018 17:06:36 +0000 Subject: [PATCH] - cleanup if/elif/else in serve.py - removed uid from navbar, name is enough - fixed navbar menu alignment --- learnapp.py | 2 +- serve.py | 40 ++++++++++++++++++---------------------- templates/maintopics.html | 35 ++++++++++++++++++----------------- templates/topic.html | 3 +-- 4 files changed, 38 insertions(+), 42 deletions(-) diff --git a/learnapp.py b/learnapp.py index ddc711d..695ccdf 100644 --- a/learnapp.py +++ b/learnapp.py @@ -184,7 +184,7 @@ class LearnApp(object): n = s.query(Student).count() m = s.query(Topic).count() q = s.query(Answer).count() - except Exception as e: + except Exception: logger.critical(f'Database "{db}" not usable!') sys.exit(1) else: diff --git a/serve.py b/serve.py index 97aa379..7bb3eba 100755 --- a/serve.py +++ b/serve.py @@ -15,7 +15,6 @@ import tornado.ioloop import tornado.web import tornado.httpserver from tornado import template, iostream, gen - from tornado.concurrent import run_on_executor from tornado.platform.asyncio import to_tornado_future @@ -267,26 +266,24 @@ class QuestionHandler(BaseHandler): 'comments': tornado.escape.to_unicode(comments_html), # FIXME } }) - else: # answer is correct - if question is None: # finished topic - finished_topic_html = self.render_string('finished_topic.html') - self.write({ - 'method': 'finished_topic', - 'params': { - 'question': tornado.escape.to_unicode(finished_topic_html) - } - }) - - else: # continue with a new question - template = self.templates[question['type']] - question_html = self.render_string(template, question=question, md=md_to_html) - self.write({ - 'method': 'new_question', - 'params': { - 'question': tornado.escape.to_unicode(question_html), - 'progress': self.learn.get_student_progress(user), - } - }) + elif question is None: # right answer, finished topic + finished_topic_html = self.render_string('finished_topic.html') + self.write({ + 'method': 'finished_topic', + 'params': { + 'question': tornado.escape.to_unicode(finished_topic_html) + } + }) + else: # right answer, get next question in the topic + template = self.templates[question['type']] + question_html = self.render_string(template, question=question, md=md_to_html) + self.write({ + 'method': 'new_question', + 'params': { + 'question': tornado.escape.to_unicode(question_html), + 'progress': self.learn.get_student_progress(user), + } + }) # ------------------------------------------------------------------------- # Tornado web server @@ -343,7 +340,6 @@ def main(): # --- run webserver logging.info('Webserver running...') - try: tornado.ioloop.IOLoop.current().start() # running... except KeyboardInterrupt: diff --git a/templates/maintopics.html b/templates/maintopics.html index 3bd93d8..ed17d6a 100644 --- a/templates/maintopics.html +++ b/templates/maintopics.html @@ -43,10 +43,9 @@ -