Commit bbdca9b8ded8a684c6cca7056233e512478ea90a
1 parent
ed4d8414
Exists in
master
and in
1 other branch
- fixed error when topic/wrong_name was given in the addressbar
Showing
3 changed files
with
35 additions
and
23 deletions
Show diff stats
BUGS.md
1 | 1 | |
2 | 2 | BUGS: |
3 | 3 | |
4 | -- barra de progresso nao está visível. | |
4 | +- templates not working: quesntion-information, question-warning (remove all informative panels??) | |
5 | +- link directo para topico nao valida se topico esta unlocked. | |
5 | 6 | - reportar comentarios após submeter. |
6 | 7 | - forçar reload das perguntas sem ter de deitar abaixo o servidor. |
7 | 8 | - topicos virtuais nao deveriam aparecer. na construção da árvore os sucessores seriam ligados directamente aos predecessores. |
... | ... | @@ -33,6 +34,8 @@ TODO: |
33 | 34 | |
34 | 35 | FIXED: |
35 | 36 | |
37 | +- enderecos errados dao internal error. | |
38 | +- barra de progresso nao está visível. | |
36 | 39 | - tabs em textarea nao funcionam correctamente (insere 1 espaco em vez de 4) |
37 | 40 | - guardar state cada vez que topico termina |
38 | 41 | - textarea deve mostrar no html os valores iniciais de ans, se existirem | ... | ... |
learnapp.py
... | ... | @@ -51,12 +51,12 @@ class LearnApp(object): |
51 | 51 | with self.db_session() as s: |
52 | 52 | student = s.query(Student).filter(Student.id == uid).one_or_none() |
53 | 53 | if student is None: |
54 | - logger.info(f'User "{uid}" does not exist.') | |
54 | + logger.info(f'User "{uid}" does not exist!') | |
55 | 55 | return False # student does not exist |
56 | 56 | |
57 | 57 | hashedtry = bcrypt.hashpw(try_pw.encode('utf-8'), student.password) |
58 | 58 | if hashedtry != student.password: |
59 | - logger.info(f'User "{uid}" wrong password.') | |
59 | + logger.info(f'User "{uid}" wrong password!') | |
60 | 60 | return False # wrong password |
61 | 61 | |
62 | 62 | # success |
... | ... | @@ -146,8 +146,13 @@ class LearnApp(object): |
146 | 146 | # Start new topic |
147 | 147 | # ------------------------------------------------------------------------ |
148 | 148 | def start_topic(self, uid, topic): |
149 | - self.online[uid]['state'].init_topic(topic) | |
150 | - logger.info(f'User "{uid}" started "{topic}"') | |
149 | + try: | |
150 | + self.online[uid]['state'].init_topic(topic) | |
151 | + except KeyError as e: | |
152 | + logger.warning(f'User "{uid}" trying to start nonexistent "{topic}"') | |
153 | + raise e | |
154 | + else: | |
155 | + logger.info(f'User "{uid}" started "{topic}"') | |
151 | 156 | |
152 | 157 | # ------------------------------------------------------------------------ |
153 | 158 | # Fill db table 'Topic' with topics from the graph if not already there. |
... | ... | @@ -158,7 +163,7 @@ class LearnApp(object): |
158 | 163 | missing_topics = [Topic(id=n) for n in nn if n not in tt] |
159 | 164 | if missing_topics: |
160 | 165 | s.add_all(missing_topics) |
161 | - logger.info(f'Added {len(missing_topics)} new topics to the database.') | |
166 | + logger.info(f'Added {len(missing_topics)} new topics to the database') | |
162 | 167 | |
163 | 168 | # ------------------------------------------------------------------------ |
164 | 169 | # setup and check database |
... | ... | @@ -173,12 +178,12 @@ class LearnApp(object): |
173 | 178 | m = s.query(Topic).count() |
174 | 179 | q = s.query(Answer).count() |
175 | 180 | except Exception as e: |
176 | - logger.critical(f'Database "{db}" not usable.') | |
181 | + logger.critical(f'Database "{db}" not usable!') | |
177 | 182 | sys.exit(1) |
178 | 183 | else: |
179 | - logger.info(f'{n:6} students.') | |
180 | - logger.info(f'{m:6} topics.') | |
181 | - logger.info(f'{q:6} answers.') | |
184 | + logger.info(f'{n:6} students') | |
185 | + logger.info(f'{m:6} topics') | |
186 | + logger.info(f'{q:6} answers') | |
182 | 187 | |
183 | 188 | # ------------------------------------------------------------------------ |
184 | 189 | # helper to manage db sessions using the `with` statement, for example | ... | ... |
serve.py
... | ... | @@ -30,8 +30,8 @@ class WebApplication(tornado.web.Application): |
30 | 30 | (r'/change_password', ChangePasswordHandler), |
31 | 31 | (r'/question', QuestionHandler), # each question |
32 | 32 | (r'/topic/(.+)', TopicHandler), # page for doing a topic |
33 | - (r'/', RootHandler), # show list of topics | |
34 | - # (r'/file/(.+)', FileHandler), # FIXME | |
33 | + # (r'/file/(.+)', FileHandler), # FIXME | |
34 | + (r'/.*', RootHandler), # show list of topics | |
35 | 35 | ] |
36 | 36 | settings = { |
37 | 37 | 'template_path': path.join(path.dirname(__file__), 'templates'), |
... | ... | @@ -121,19 +121,23 @@ class RootHandler(BaseHandler): |
121 | 121 | ) |
122 | 122 | |
123 | 123 | # ---------------------------------------------------------------------------- |
124 | -# Start a given topic: /topic | |
124 | +# Start a given topic: /topic/... | |
125 | 125 | # ---------------------------------------------------------------------------- |
126 | 126 | class TopicHandler(BaseHandler): |
127 | 127 | @tornado.web.authenticated |
128 | 128 | def get(self, topic): |
129 | 129 | uid = self.current_user |
130 | 130 | |
131 | - self.learn.start_topic(uid, topic) | |
132 | - | |
133 | - self.render('topic.html', | |
134 | - uid=uid, | |
135 | - name=self.learn.get_student_name(uid), | |
136 | - ) | |
131 | + try: | |
132 | + self.learn.start_topic(uid, topic) | |
133 | + except KeyError: | |
134 | + self.redirect('/') | |
135 | + # raise tornado.web.HTTPError(404) | |
136 | + else: | |
137 | + self.render('topic.html', | |
138 | + uid=uid, | |
139 | + name=self.learn.get_student_name(uid), | |
140 | + ) | |
137 | 141 | |
138 | 142 | |
139 | 143 | # ---------------------------------------------------------------------------- |
... | ... | @@ -163,9 +167,9 @@ class QuestionHandler(BaseHandler): |
163 | 167 | 'numeric-interval': 'question-text.html', |
164 | 168 | 'textarea': 'question-textarea.html', |
165 | 169 | # -- information panels -- |
166 | - 'information': 'question-information.html', | |
167 | - 'info': 'question-information.html', | |
168 | - 'success': 'question-success.html', | |
170 | + 'information': 'question-information.html', | |
171 | + 'info': 'question-information.html', | |
172 | + 'success': 'question-success.html', | |
169 | 173 | # 'warning': '', FIXME |
170 | 174 | # 'warn': '', FIXME |
171 | 175 | # 'alert': '', FIXME |
... | ... | @@ -276,7 +280,7 @@ def main(): |
276 | 280 | learnapp = LearnApp(arg.conffile[0]) |
277 | 281 | |
278 | 282 | # --- create web application |
279 | - logging.info('Starting Web App (tornado).') | |
283 | + logging.info('Starting Web App (tornado)') | |
280 | 284 | try: |
281 | 285 | webapp = WebApplication(learnapp, debug=arg.debug) |
282 | 286 | except Exception as e: | ... | ... |