diff --git a/BUGS.md b/BUGS.md index 910773a..e3478a8 100644 --- a/BUGS.md +++ b/BUGS.md @@ -1,8 +1,7 @@ # BUGS -- upgrade para tornado 5.0. -- servir imagens das perguntas +- servir imagens das perguntas não funciona. Necessario passar a ref da pergunta no link para poder ajustar o path no FileHandler - o eventloop está a bloquear. correção do teste é blocking. usar threadpoolexecutor? - se submissão falhar (aluno desconectado da rede) nao pode sair da página para nao perder o teste. possiveis solucoes: - botao submeter valida se esta online com um post willing_to_submit, se estiver online, mostra mensagem de confirmacao, caso contrario avisa que nao esta online. @@ -46,6 +45,7 @@ # FIXED +- upgrade para tornado 5.0. - ctrl-c should ask for confirmation before exiting. - md_to_html() nao usa o segundo argumento q. pode retirar-se dos templates? - config/logger.yaml ainda é do cherrypy... diff --git a/serve.py b/serve.py index 6298db1..28c6a60 100755 --- a/serve.py +++ b/serve.py @@ -88,7 +88,6 @@ class LoginHandler(BaseHandler): class LogoutHandler(BaseHandler): @tornado.web.authenticated def get(self): - # self.testapp.logout(self.current_user) self.clear_cookie('user') self.redirect('/') @@ -104,36 +103,45 @@ class FileHandler(BaseHandler): chunk_size = 4 * 1024 * 1024 # serve up to 4 MiB multiple times @tornado.web.authenticated - async def get(self, filename): + def get(self, filename): uid = self.current_user - # public_dir = self.learn.get_current_public_dir(uid) - filepath = path.expanduser(path.join(public_dir, filename)) + # ref = self.get_query_argument('ref') + # print(ref) + # questions_path = self.testapp.get_questions_path() + # p = path.join(questions_path, ref, 'public', filename) + # print(p) + logging.error(f'{uid} requested file but FileHandler is not working!!!') + self.write('image') - try: - f = open(filepath, 'rb') - except FileNotFoundError: - logging.error(f'File not found: {filepath}') - except PermissionError: - logging.error(f'No permission: {filepath}') - else: - content_type = mimetypes.guess_type(filename) - self.set_header("Content-Type", content_type[0]) - # divide the file into chunks and write one chunk at a time, so - # that the write does not block the ioloop for very long. - with f: - chunk = f.read(self.chunk_size) - while chunk: - try: - self.write(chunk) # write the cunk to response - await self.flush() # flush the current chunk to socket - except iostream.StreamClosedError: - break # client closed the connection - finally: - del chunk - await gen.sleep(0.000000001) # 1 nanosecond (hack) - # FIXME in the upcomming tornado 5.0 use `await asyncio.sleep(0)` instead - chunk = f.read(self.chunk_size) + # # public_dir = self.learn.get_current_public_dir(uid) + # filepath = path.expanduser(path.join(public_dir, filename)) + + # try: + # f = open(filepath, 'rb') + # except FileNotFoundError: + # logging.error(f'File not found: {filepath}') + # except PermissionError: + # logging.error(f'No permission: {filepath}') + # else: + # content_type = mimetypes.guess_type(filename) + # self.set_header("Content-Type", content_type[0]) + + # # divide the file into chunks and write one chunk at a time, so + # # that the write does not block the ioloop for very long. + # with f: + # chunk = f.read(self.chunk_size) + # while chunk: + # try: + # self.write(chunk) # write the cunk to response + # await self.flush() # flush the current chunk to socket + # except iostream.StreamClosedError: + # break # client closed the connection + # finally: + # del chunk + # await gen.sleep(0.000000001) # 1 nanosecond (hack) + # # FIXME in the upcomming tornado 5.0 use `await asyncio.sleep(0)` instead + # chunk = f.read(self.chunk_size) # ------------------------------------------------------------------------- # FIXME checkit # class FileHandler(BaseHandler): diff --git a/templates/question.html b/templates/question.html index 2e34215..4b13056 100644 --- a/templates/question.html +++ b/templates/question.html @@ -22,7 +22,7 @@
- + {% if show_ref %}