Commit 717aa0b3f71d3f96171025357c66009177640ef6
1 parent
aa7b797e
Exists in
master
and in
1 other branch
- cleanup if/elif/else in serve.py
- removed uid from navbar, name is enough - fixed navbar menu alignment
Showing
4 changed files
with
38 additions
and
42 deletions
Show diff stats
learnapp.py
| ... | ... | @@ -184,7 +184,7 @@ class LearnApp(object): |
| 184 | 184 | n = s.query(Student).count() |
| 185 | 185 | m = s.query(Topic).count() |
| 186 | 186 | q = s.query(Answer).count() |
| 187 | - except Exception as e: | |
| 187 | + except Exception: | |
| 188 | 188 | logger.critical(f'Database "{db}" not usable!') |
| 189 | 189 | sys.exit(1) |
| 190 | 190 | else: | ... | ... |
serve.py
| ... | ... | @@ -15,7 +15,6 @@ import tornado.ioloop |
| 15 | 15 | import tornado.web |
| 16 | 16 | import tornado.httpserver |
| 17 | 17 | from tornado import template, iostream, gen |
| 18 | - | |
| 19 | 18 | from tornado.concurrent import run_on_executor |
| 20 | 19 | from tornado.platform.asyncio import to_tornado_future |
| 21 | 20 | |
| ... | ... | @@ -267,26 +266,24 @@ class QuestionHandler(BaseHandler): |
| 267 | 266 | 'comments': tornado.escape.to_unicode(comments_html), # FIXME |
| 268 | 267 | } |
| 269 | 268 | }) |
| 270 | - else: # answer is correct | |
| 271 | - if question is None: # finished topic | |
| 272 | - finished_topic_html = self.render_string('finished_topic.html') | |
| 273 | - self.write({ | |
| 274 | - 'method': 'finished_topic', | |
| 275 | - 'params': { | |
| 276 | - 'question': tornado.escape.to_unicode(finished_topic_html) | |
| 277 | - } | |
| 278 | - }) | |
| 279 | - | |
| 280 | - else: # continue with a new question | |
| 281 | - template = self.templates[question['type']] | |
| 282 | - question_html = self.render_string(template, question=question, md=md_to_html) | |
| 283 | - self.write({ | |
| 284 | - 'method': 'new_question', | |
| 285 | - 'params': { | |
| 286 | - 'question': tornado.escape.to_unicode(question_html), | |
| 287 | - 'progress': self.learn.get_student_progress(user), | |
| 288 | - } | |
| 289 | - }) | |
| 269 | + elif question is None: # right answer, finished topic | |
| 270 | + finished_topic_html = self.render_string('finished_topic.html') | |
| 271 | + self.write({ | |
| 272 | + 'method': 'finished_topic', | |
| 273 | + 'params': { | |
| 274 | + 'question': tornado.escape.to_unicode(finished_topic_html) | |
| 275 | + } | |
| 276 | + }) | |
| 277 | + else: # right answer, get next question in the topic | |
| 278 | + template = self.templates[question['type']] | |
| 279 | + question_html = self.render_string(template, question=question, md=md_to_html) | |
| 280 | + self.write({ | |
| 281 | + 'method': 'new_question', | |
| 282 | + 'params': { | |
| 283 | + 'question': tornado.escape.to_unicode(question_html), | |
| 284 | + 'progress': self.learn.get_student_progress(user), | |
| 285 | + } | |
| 286 | + }) | |
| 290 | 287 | |
| 291 | 288 | # ------------------------------------------------------------------------- |
| 292 | 289 | # Tornado web server |
| ... | ... | @@ -343,7 +340,6 @@ def main(): |
| 343 | 340 | |
| 344 | 341 | # --- run webserver |
| 345 | 342 | logging.info('Webserver running...') |
| 346 | - | |
| 347 | 343 | try: |
| 348 | 344 | tornado.ioloop.IOLoop.current().start() # running... |
| 349 | 345 | except KeyboardInterrupt: | ... | ... |
templates/maintopics.html
| ... | ... | @@ -43,10 +43,9 @@ |
| 43 | 43 | <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> |
| 44 | 44 | <i class="fas fa-user" aria-hidden="true"></i> |
| 45 | 45 | <span id="name">{{ escape(name) }}</span> |
| 46 | - (<span id="number">{{ escape(uid) }}</span>) | |
| 47 | 46 | <span class="caret"></span> |
| 48 | 47 | </a> |
| 49 | - <div class="dropdown-menu" aria-labelledby="navbarDropdown"> | |
| 48 | + <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown"> | |
| 50 | 49 | <button class="dropdown-item" data-toggle="modal" data-target="#password_modal">Mudar Password</button> |
| 51 | 50 | <div class="dropdown-divider"></div> |
| 52 | 51 | <a class="dropdown-item" href="/logout">Sair</a> |
| ... | ... | @@ -68,7 +67,7 @@ |
| 68 | 67 | <a class="list-group-item list-group-item-action bg-light disabled"> |
| 69 | 68 | <div class="d-flex justify-content-start"> |
| 70 | 69 | <div class="p-2 font-italic text-muted"> |
| 71 | - {{ t['name'] }} | |
| 70 | + ({{ t['name'] }}) | |
| 72 | 71 | </div> |
| 73 | 72 | <div class="ml-auto p-2"> |
| 74 | 73 | <i class="fas fa-lock text-danger"></i> |
| ... | ... | @@ -78,22 +77,24 @@ |
| 78 | 77 | {% else %} |
| 79 | 78 | <a class="list-group-item list-group-item-action" href="/topic/{{t['ref']}}"> |
| 80 | 79 | <div class="d-flex justify-content-start"> |
| 81 | - <div class="p-2"> | |
| 82 | - {{ t['name'] }} | |
| 83 | - </div> | |
| 84 | - <div class="ml-auto p-2"> | |
| 85 | - {% if t['level'] < 0.01 %} | |
| 80 | + {% if t['level'] < 0.01 %} | |
| 81 | + <div class="p-2">{{ t['name'] }}</div> | |
| 82 | + <div class="ml-auto p-2"> | |
| 86 | 83 | <i class="fas fa-lock-open text-success"></i> |
| 87 | - {% else %} | |
| 88 | - {% if t['type']=='chapter' %} | |
| 89 | - <i class="fas fa-trophy fa-lg text-warning"></i> | |
| 90 | - {% else %} | |
| 91 | - <span class="text-nowrap"> | |
| 84 | + </div> | |
| 85 | + {% elif t['type']=='chapter' %} | |
| 86 | + <div class="p-2 font-weight-light">{{ t['name'] }}</div> | |
| 87 | + <div class="ml-auto p-2"> | |
| 88 | + <i class="fas fa-trophy fa-lg text-warning"></i> | |
| 89 | + </div> | |
| 90 | + {% else %} | |
| 91 | + <div class="p-2">{{ t['name'] }}</div> | |
| 92 | + <div class="ml-auto p-2"> | |
| 93 | + <span class="text-nowrap"> | |
| 92 | 94 | {{ round(t['level']*5)*'<i class="fas fa-star text-warning"></i>' + (5-round(t['level']*5))*'<i class="far fa-star text-warning"></i>' }} |
| 93 | - </span> | |
| 94 | - {% end %} | |
| 95 | - {% end %} | |
| 96 | - </div> | |
| 95 | + </span> | |
| 96 | + </div> | |
| 97 | + {% end %} | |
| 97 | 98 | </div> |
| 98 | 99 | </a> |
| 99 | 100 | {% end %} | ... | ... |
templates/topic.html
| ... | ... | @@ -55,10 +55,9 @@ |
| 55 | 55 | <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> |
| 56 | 56 | <i class="fas fa-user" aria-hidden="true"></i> |
| 57 | 57 | <span id="name">{{ escape(name) }}</span> |
| 58 | - (<span id="number">{{ escape(uid) }}</span>) | |
| 59 | 58 | <span class="caret"></span> |
| 60 | 59 | </a> |
| 61 | - <div class="dropdown-menu" aria-labelledby="navbarDropdown"> | |
| 60 | + <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown"> | |
| 62 | 61 | <!-- <div class="dropdown-divider"></div> --> |
| 63 | 62 | <a class="dropdown-item" href="/">Voltar aos tópicos</a> |
| 64 | 63 | </div> | ... | ... |