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,7 +184,7 @@ class LearnApp(object): | ||
184 | n = s.query(Student).count() | 184 | n = s.query(Student).count() |
185 | m = s.query(Topic).count() | 185 | m = s.query(Topic).count() |
186 | q = s.query(Answer).count() | 186 | q = s.query(Answer).count() |
187 | - except Exception as e: | 187 | + except Exception: |
188 | logger.critical(f'Database "{db}" not usable!') | 188 | logger.critical(f'Database "{db}" not usable!') |
189 | sys.exit(1) | 189 | sys.exit(1) |
190 | else: | 190 | else: |
serve.py
@@ -15,7 +15,6 @@ import tornado.ioloop | @@ -15,7 +15,6 @@ import tornado.ioloop | ||
15 | import tornado.web | 15 | import tornado.web |
16 | import tornado.httpserver | 16 | import tornado.httpserver |
17 | from tornado import template, iostream, gen | 17 | from tornado import template, iostream, gen |
18 | - | ||
19 | from tornado.concurrent import run_on_executor | 18 | from tornado.concurrent import run_on_executor |
20 | from tornado.platform.asyncio import to_tornado_future | 19 | from tornado.platform.asyncio import to_tornado_future |
21 | 20 | ||
@@ -267,26 +266,24 @@ class QuestionHandler(BaseHandler): | @@ -267,26 +266,24 @@ class QuestionHandler(BaseHandler): | ||
267 | 'comments': tornado.escape.to_unicode(comments_html), # FIXME | 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 | # Tornado web server | 289 | # Tornado web server |
@@ -343,7 +340,6 @@ def main(): | @@ -343,7 +340,6 @@ def main(): | ||
343 | 340 | ||
344 | # --- run webserver | 341 | # --- run webserver |
345 | logging.info('Webserver running...') | 342 | logging.info('Webserver running...') |
346 | - | ||
347 | try: | 343 | try: |
348 | tornado.ioloop.IOLoop.current().start() # running... | 344 | tornado.ioloop.IOLoop.current().start() # running... |
349 | except KeyboardInterrupt: | 345 | except KeyboardInterrupt: |
templates/maintopics.html
@@ -43,10 +43,9 @@ | @@ -43,10 +43,9 @@ | ||
43 | <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | 43 | <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> |
44 | <i class="fas fa-user" aria-hidden="true"></i> | 44 | <i class="fas fa-user" aria-hidden="true"></i> |
45 | <span id="name">{{ escape(name) }}</span> | 45 | <span id="name">{{ escape(name) }}</span> |
46 | - (<span id="number">{{ escape(uid) }}</span>) | ||
47 | <span class="caret"></span> | 46 | <span class="caret"></span> |
48 | </a> | 47 | </a> |
49 | - <div class="dropdown-menu" aria-labelledby="navbarDropdown"> | 48 | + <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown"> |
50 | <button class="dropdown-item" data-toggle="modal" data-target="#password_modal">Mudar Password</button> | 49 | <button class="dropdown-item" data-toggle="modal" data-target="#password_modal">Mudar Password</button> |
51 | <div class="dropdown-divider"></div> | 50 | <div class="dropdown-divider"></div> |
52 | <a class="dropdown-item" href="/logout">Sair</a> | 51 | <a class="dropdown-item" href="/logout">Sair</a> |
@@ -68,7 +67,7 @@ | @@ -68,7 +67,7 @@ | ||
68 | <a class="list-group-item list-group-item-action bg-light disabled"> | 67 | <a class="list-group-item list-group-item-action bg-light disabled"> |
69 | <div class="d-flex justify-content-start"> | 68 | <div class="d-flex justify-content-start"> |
70 | <div class="p-2 font-italic text-muted"> | 69 | <div class="p-2 font-italic text-muted"> |
71 | - {{ t['name'] }} | 70 | + ({{ t['name'] }}) |
72 | </div> | 71 | </div> |
73 | <div class="ml-auto p-2"> | 72 | <div class="ml-auto p-2"> |
74 | <i class="fas fa-lock text-danger"></i> | 73 | <i class="fas fa-lock text-danger"></i> |
@@ -78,22 +77,24 @@ | @@ -78,22 +77,24 @@ | ||
78 | {% else %} | 77 | {% else %} |
79 | <a class="list-group-item list-group-item-action" href="/topic/{{t['ref']}}"> | 78 | <a class="list-group-item list-group-item-action" href="/topic/{{t['ref']}}"> |
80 | <div class="d-flex justify-content-start"> | 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 | <i class="fas fa-lock-open text-success"></i> | 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 | {{ 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>' }} | 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 | </div> | 98 | </div> |
98 | </a> | 99 | </a> |
99 | {% end %} | 100 | {% end %} |
templates/topic.html
@@ -55,10 +55,9 @@ | @@ -55,10 +55,9 @@ | ||
55 | <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | 55 | <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> |
56 | <i class="fas fa-user" aria-hidden="true"></i> | 56 | <i class="fas fa-user" aria-hidden="true"></i> |
57 | <span id="name">{{ escape(name) }}</span> | 57 | <span id="name">{{ escape(name) }}</span> |
58 | - (<span id="number">{{ escape(uid) }}</span>) | ||
59 | <span class="caret"></span> | 58 | <span class="caret"></span> |
60 | </a> | 59 | </a> |
61 | - <div class="dropdown-menu" aria-labelledby="navbarDropdown"> | 60 | + <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown"> |
62 | <!-- <div class="dropdown-divider"></div> --> | 61 | <!-- <div class="dropdown-divider"></div> --> |
63 | <a class="dropdown-item" href="/">Voltar aos tópicos</a> | 62 | <a class="dropdown-item" href="/">Voltar aos tópicos</a> |
64 | </div> | 63 | </div> |