diff --git a/BUGS.md b/BUGS.md index 8f885b5..dd8456d 100644 --- a/BUGS.md +++ b/BUGS.md @@ -1,6 +1,6 @@ BUGS: -- servir ficheiros de public temporariamente +- load/save the knowledge state of the student - se students.db não existe, rebenta. - database hardcoded in LearnApp. - implementar xsrf. Ver [http://www.tornadoweb.org/en/stable/guide/security.html#cross-site-request-forgery-protection]() @@ -14,6 +14,7 @@ TODO: SOLVED: +- servir ficheiros de public temporariamente - path dos generators scripts mal construido - questions hardcoded in LearnApp. - Factory para cada pergunta individual em vez de pool diff --git a/app.py b/app.py index 6582b2b..7930ecb 100644 --- a/app.py +++ b/app.py @@ -74,6 +74,12 @@ class LearnApp(object): return self.online[uid].get('name', '') # ------------------------------------------------------------------------ + def get_current_public_dir(self, uid): + topic = self.online[uid]['state'].topic + p = self.depgraph.graph['path'] + return path.join(p, topic, 'public') + + # ------------------------------------------------------------------------ # check answer and if correct returns new question, otherise returns None def check_answer(self, uid, answer): logger.debug(f'check_answer("{uid}", "{answer}")') diff --git a/knowledge.py b/knowledge.py index c5b340b..d3ffa15 100644 --- a/knowledge.py +++ b/knowledge.py @@ -21,7 +21,8 @@ class Knowledge(object): self.state = state # {node: level, node: level, ...} self.current_question = None - # self.seq = nx.topological_sort(self.depgraph) + self.seq = nx.topological_sort(self.depgraph) + self.topic = None def get_current_question(self): return self.current_question @@ -36,10 +37,10 @@ class Knowledge(object): g = self.depgraph # choose topic, ie, node of the graph # print(g.nodes()) - topic = random.choice(g.nodes()) # FIXME + self.topic = random.choice(g.nodes()) # FIXME # print(topic) # choose question from that topic - question = random.choice(g.node[topic]['factory']) + question = random.choice(g.node[self.topic]['factory']) # print(question) self.current_question = question.generate() diff --git a/serve.py b/serve.py index fb4a429..e9f8a5a 100755 --- a/serve.py +++ b/serve.py @@ -34,10 +34,11 @@ from tools import load_yaml, md class WebApplication(tornado.web.Application): def __init__(self): handlers = [ - (r'/', LearnHandler), (r'/login', LoginHandler), (r'/logout', LogoutHandler), (r'/question', QuestionHandler), + (r'/', LearnHandler), + (r'/(.+)', FileHandler), ] settings = { 'template_path': os.path.join(os.path.dirname(__file__), 'templates'), @@ -112,6 +113,18 @@ class LearnHandler(BaseHandler): ) # ---------------------------------------------------------------------------- +class FileHandler(BaseHandler): + @tornado.web.authenticated + def get(self, filename): + uid = self.current_user + public_dir = self.learn.get_current_public_dir(uid) + try: + with open(os.path.join(public_dir, filename), 'rb') as f: + self.write(f.read()) + except FileNotFoundError: + raise tornado.web.HTTPError(404) + +# ---------------------------------------------------------------------------- # respond to AJAX to get a JSON question class QuestionHandler(BaseHandler): templates = { diff --git a/static/css/learn.css b/static/css/learn.css index bf90bc7..b54aac6 100644 --- a/static/css/learn.css +++ b/static/css/learn.css @@ -1,3 +1,9 @@ -body { - padding-top: 65px; +body { + padding-top: 65px; +} + +img { + display: block; + margin: auto; + width: 80%; } \ No newline at end of file -- libgit2 0.21.2