Commit 7e354edb6ca9151fc75b7ca9a75241edce5bdf5b
1 parent
bbfe1f31
Exists in
master
and in
1 other branch
- added a new question type "success" that contains a message in alert style.
- changed some logger messages.
Showing
6 changed files
with
23 additions
and
14 deletions
Show diff stats
BUGS.md
app.py
| ... | ... | @@ -201,6 +201,7 @@ class LearnApp(object): |
| 201 | 201 | g.node[ref]['name'] = attr |
| 202 | 202 | |
| 203 | 203 | # iterate over topics and create question factories |
| 204 | + logger.info('Loading:') | |
| 204 | 205 | for ref in g.nodes_iter(): |
| 205 | 206 | g.node[ref].setdefault('name', ref) |
| 206 | 207 | fullpath = path.expanduser(path.join(prefix, ref)) |
| ... | ... | @@ -210,8 +211,8 @@ class LearnApp(object): |
| 210 | 211 | logger.error(f'build_dependency_graph: "{fullpath}" is not a directory') |
| 211 | 212 | |
| 212 | 213 | if path.isfile(filename): |
| 213 | - logger.info(f'Loading questions from "{filename}"') | |
| 214 | 214 | questions = load_yaml(filename, default=[]) |
| 215 | + logger.info(f' {len(questions)} questions from "{ref}"') | |
| 215 | 216 | for q in questions: |
| 216 | 217 | q['path'] = fullpath |
| 217 | 218 | g.node[ref]['factory'] = [QFactory(q) for q in questions] | ... | ... |
knowledge.py
| ... | ... | @@ -28,7 +28,7 @@ class Knowledge(object): |
| 28 | 28 | |
| 29 | 29 | # ------------------------------------------------------------------------ |
| 30 | 30 | def new_topic(self, topic=None): |
| 31 | - logger.debug(f'new_topic {topic}') | |
| 31 | + logger.debug(f'-> Knowledge.new_topic({topic})') | |
| 32 | 32 | if topic is None: |
| 33 | 33 | # select the first topic that has level < 0.9 |
| 34 | 34 | for topic in self.topic_sequence: |
| ... | ... | @@ -44,6 +44,7 @@ class Knowledge(object): |
| 44 | 44 | |
| 45 | 45 | # ------------------------------------------------------------------------ |
| 46 | 46 | def generate_questions_for_topic(self, topic): |
| 47 | + logger.debug(f'-> Knowledge.generate_questions_for_topic({topic})') | |
| 47 | 48 | factory_list = self.depgraph.node[topic]['factory'] |
| 48 | 49 | return [q.generate() for q in factory_list] |
| 49 | 50 | |
| ... | ... | @@ -57,6 +58,7 @@ class Knowledge(object): |
| 57 | 58 | |
| 58 | 59 | # ------------------------------------------------------------------------ |
| 59 | 60 | def get_knowledge_state(self): |
| 61 | + logger.debug('-> Knowledge.get_knowledge_state()') | |
| 60 | 62 | ts = [] |
| 61 | 63 | for t in self.topic_sequence: |
| 62 | 64 | if t in self.state: |
| ... | ... | @@ -64,7 +66,6 @@ class Knowledge(object): |
| 64 | 66 | else: |
| 65 | 67 | ts.append((t, 0.0)) |
| 66 | 68 | return ts |
| 67 | - # return [(t, self.state.get(t, 0.0)) for t in self.topic_sequence] | |
| 68 | 69 | |
| 69 | 70 | # ------------------------------------------------------------------------ |
| 70 | 71 | def get_topic_progress(self): |
| ... | ... | @@ -95,7 +96,6 @@ class Knowledge(object): |
| 95 | 96 | |
| 96 | 97 | return self.current_question |
| 97 | 98 | |
| 98 | - | |
| 99 | 99 | # --- checks answer ------------------------------------------------------ |
| 100 | 100 | # returns current question with correction, time and comments updated |
| 101 | 101 | def check_answer(self, answer): | ... | ... |
questions.py
| ... | ... | @@ -392,10 +392,12 @@ class QFactory(object): |
| 392 | 392 | 'text_regex': QuestionTextRegex, |
| 393 | 393 | 'text_numeric': QuestionTextNumeric, |
| 394 | 394 | 'textarea' : QuestionTextArea, |
| 395 | - # informative panels | |
| 395 | + # -- informative panels -- | |
| 396 | 396 | 'information': QuestionInformation, |
| 397 | + 'info' : QuestionInformation, # same as 'information' | |
| 397 | 398 | 'warning' : QuestionInformation, |
| 398 | 399 | 'alert' : QuestionInformation, |
| 400 | + 'success' : QuestionInformation, | |
| 399 | 401 | } |
| 400 | 402 | |
| 401 | 403 | def __init__(self, question_dict): |
| ... | ... | @@ -413,7 +415,7 @@ class QFactory(object): |
| 413 | 415 | |
| 414 | 416 | # If question is of generator type, an external program will be run |
| 415 | 417 | # which will print a valid question in yaml format to stdout. This |
| 416 | - # output is then converted to a dictionary and `q` becomes that dict. | |
| 418 | + # output is then yaml parsed into a dictionary `q`. | |
| 417 | 419 | if q['type'] == 'generator': |
| 418 | 420 | logger.debug(f'Running script "{q["script"]}"...') |
| 419 | 421 | q.setdefault('arg', '') # optional arguments will be sent to stdin | ... | ... |
serve.py
| ... | ... | @@ -108,13 +108,7 @@ class ChangePasswordHandler(BaseHandler): |
| 108 | 108 | pw = self.get_body_arguments('new_password')[0]; |
| 109 | 109 | |
| 110 | 110 | if self.learn.change_password(uid, pw): |
| 111 | - notification = tornado.escape.to_unicode( | |
| 112 | - self.render_string( | |
| 113 | - 'notification.html', | |
| 114 | - type='success', | |
| 115 | - msg='A password foi alterada!' | |
| 116 | - ) | |
| 117 | - ) | |
| 111 | + notification = tornado.escape.to_unicode(self.render_string('notification.html', type='success', msg='A password foi alterada!')) | |
| 118 | 112 | else: |
| 119 | 113 | notification = tornado.escape.to_unicode(self.render_string('notification.html', type='danger', msg='A password não foi alterada!')) |
| 120 | 114 | self.write({'msg': notification}) |
| ... | ... | @@ -148,13 +142,15 @@ class FileHandler(BaseHandler): |
| 148 | 142 | # respond to AJAX to get a JSON question |
| 149 | 143 | class QuestionHandler(BaseHandler): |
| 150 | 144 | templates = { |
| 151 | - 'information': 'question-information.html', | |
| 152 | 145 | 'checkbox': 'question-checkbox.html', |
| 153 | 146 | 'radio': 'question-radio.html', |
| 154 | 147 | 'text': 'question-text.html', |
| 155 | 148 | 'text_regex': 'question-text.html', |
| 156 | 149 | 'text_numeric': 'question-text.html', |
| 157 | 150 | 'textarea': 'question-textarea.html', |
| 151 | + # -- information panels -- | |
| 152 | + 'information': 'question-information.html', | |
| 153 | + 'success': 'question-success.html', | |
| 158 | 154 | } |
| 159 | 155 | |
| 160 | 156 | # @tornado.web.authenticated | ... | ... |