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