diff --git a/BUGS.md b/BUGS.md index 767dfd7..a8e0d26 100644 --- a/BUGS.md +++ b/BUGS.md @@ -2,13 +2,10 @@ BUGS: - se refs de um topic estao invalidos, nao carrega esse topico. devia haver um error nos logs a indicar qual o ref invalido. -- templates not working: quesntion-information, question-warning (remove all informative panels??) -- link directo para topico nao valida se topico esta unlocked. -- reportar comentarios após submeter. - forçar reload das perguntas sem ter de deitar abaixo o servidor. - topicos virtuais nao deveriam aparecer. na construção da árvore os sucessores seriam ligados directamente aos predecessores. - Criar outra estrutura organizada em capítulos (conjuntos de tópicos). Permitir capítulos de capítulos, etc. talvez usar grafos de grafos... -- pertuntas tipo tristate: (sim, não, não sei) +- pertuntas tipo tristate: (sim, não, não sei - detect questions in questions.yaml without ref -> error ou generate default. - error if demo.yaml has no topics - session management. close after inactive time. @@ -19,6 +16,8 @@ BUGS: TODO: +- reportar comentarios após submeter. +- each topic only loads a sample of K questions (max) in random order. - servir imagens/ficheiros. - update de fontawesome para versão 5. - reload das perguntas enquanto online. @@ -35,6 +34,8 @@ TODO: FIXED: +- link directo para topico nao valida se topico esta unlocked. +- templates not working: quesntion-information, question-warning (remove all informative panels??) - enderecos errados dao internal error. - barra de progresso nao está visível. - tabs em textarea nao funcionam correctamente (insere 1 espaco em vez de 4) diff --git a/knowledge.py b/knowledge.py index c662210..04b92cc 100644 --- a/knowledge.py +++ b/knowledge.py @@ -70,6 +70,10 @@ class StudentKnowledge(object): if not topic: topic = self.get_recommended_topic() + # check if it's unlocked + if self.is_locked(topic): + return False + self.current_topic = topic # logger.info(f'Topic set to "{topic}"') @@ -82,6 +86,7 @@ class StudentKnowledge(object): self.current_question = self.questions.pop(0) # FIXME crash if empty self.current_question['start_time'] = datetime.now() + return True # ------------------------------------------------------------------------ # The topic has finished and there are no more questions. @@ -148,6 +153,10 @@ class StudentKnowledge(object): return self.current_topic # ------------------------------------------------------------------------ + def is_locked(self, topic): + return topic not in self.state + + # ------------------------------------------------------------------------ # Return list of {ref: 'xpto', name: 'long name', leve: 0.5} # Levels are in the interval [0, 1] if unlocked or None if locked. # Topics unlocked but not yet done have level 0.0. @@ -176,3 +185,4 @@ class StudentKnowledge(object): # ------------------------------------------------------------------------ def get_recommended_topic(self): # FIXME untested return min(self.state.items(), key=lambda x: x[1]['level'])[0] + diff --git a/learnapp.py b/learnapp.py index 52c444a..f8e9b45 100644 --- a/learnapp.py +++ b/learnapp.py @@ -147,12 +147,16 @@ class LearnApp(object): # ------------------------------------------------------------------------ def start_topic(self, uid, topic): try: - self.online[uid]['state'].init_topic(topic) + ok = self.online[uid]['state'].init_topic(topic) except KeyError as e: - logger.warning(f'User "{uid}" trying to start nonexistent "{topic}"') + logger.warning(f'User "{uid}" denied nonexistent "{topic}"') raise e else: - logger.info(f'User "{uid}" started "{topic}"') + if ok: + logger.info(f'User "{uid}" started "{topic}"') + else: + logger.warning(f'User "{uid}" denied locked "{topic}"') + return ok # ------------------------------------------------------------------------ # Fill db table 'Topic' with topics from the graph if not already there. diff --git a/serve.py b/serve.py index bb89d79..d768db2 100755 --- a/serve.py +++ b/serve.py @@ -129,16 +129,17 @@ class TopicHandler(BaseHandler): uid = self.current_user try: - self.learn.start_topic(uid, topic) + ok = self.learn.start_topic(uid, topic) except KeyError: - self.redirect('/') - # raise tornado.web.HTTPError(404) + self.redirect('/') else: - self.render('topic.html', - uid=uid, - name=self.learn.get_student_name(uid), - ) - + if ok: + self.render('topic.html', + uid=uid, + name=self.learn.get_student_name(uid), + ) + else: + self.redirect('/') # ---------------------------------------------------------------------------- class FileHandler(BaseHandler): -- libgit2 0.21.2