diff --git a/BUGS.md b/BUGS.md index ff46be1..dfe6096 100644 --- a/BUGS.md +++ b/BUGS.md @@ -6,6 +6,7 @@ - hints nao funciona - uniformizar question.py com a de aprendizations... - permitir eliminar teste a decorrer +- eventos unfocus? - servidor nao esta a lidar com eventos scroll/resize. ignorar? # TODO @@ -18,7 +19,7 @@ node_modules/mathjax-node-cli/bin/tex2svg '\sqrt{x}' usar isto para gerar svg que passa a fazer parte do texto da pergunta (markdown suporta tags svg?) fazer funçao tex() que recebe formula e converte para svg. exemplo: - fr'''A formula é {tex(\sqrt{x]})}''' + fr'''A formula é {tex("\sqrt{x]}")}''' - Gerar pdf's com todos os testes no final (pdfkit). - manter registo dos unfocus durante o teste e de qual a pergunta visivel nesse momento diff --git a/app.py b/app.py index 170b4d3..d9ec112 100644 --- a/app.py +++ b/app.py @@ -12,6 +12,7 @@ from sqlalchemy.orm import sessionmaker, scoped_session # this project from models import Student, Test, Question import test +from tools import load_yaml logger = logging.getLogger(__name__) @@ -23,7 +24,7 @@ class AppException(Exception): # Application # ============================================================================ class App(object): - def __init__(self, filename, conf): + def __init__(self, conf={}): # online = { # uid1: { # 'student': {'number': 123, 'name': john, ...}, @@ -35,8 +36,17 @@ class App(object): self.online = dict() # {uid: {'student':{}}} self.allowed = set([]) # '0' is hardcoded to allowed elsewhere + # build test configuration dictionary + testconf = {} + if conf['filename']: + logger.info(f'Loading test configuration "{conf["filename"]}".') + testconf.update(load_yaml(conf['filename'])) + + testconf.update(conf) # configuration overrides + + # start test factory try: - self.testfactory = test.TestFactory(filename, conf=conf) + self.testfactory = test.TestFactory(testconf) except test.TestFactoryException: logger.critical('Can\'t create test factory.') raise AppException() diff --git a/serve.py b/serve.py index bff5983..79d5ee3 100755 --- a/serve.py +++ b/serve.py @@ -8,6 +8,8 @@ import logging.config import json import base64 import uuid +# from mimetypes import guess_type + # packages import tornado.ioloop @@ -28,7 +30,7 @@ class WebApplication(tornado.web.Application): (r'/test', TestHandler), (r'/review', ReviewHandler), (r'/admin', AdminHandler), - (r'/static/(.+)', FileHandler), # FIXME + (r'/file/(.+)', FileHandler), # FIXME (r'/', RootHandler), # TODO multiple tests ] @@ -93,17 +95,33 @@ class LogoutHandler(BaseHandler): # FIXME checkit class FileHandler(BaseHandler): @tornado.web.authenticated - def get(self, filename): + def get(self): uid = self.current_user - public_dir = self.learn.get_current_public_dir(uid) # FIXME!!! - filepath = path.expanduser(path.join(public_dir, filename)) - try: - f = open(filepath, 'rb') - except FileNotFoundError: - raise tornado.web.HTTPError(404) - else: - self.write(f.read()) - f.close() + qref = self.get_query_argument('ref') + qfile = self.get_query_argument('filename') + self.write(self.testapp.get_file(ref, filename)) + + + # if not os.path.isfile(file_location): + # raise tornado.web.HTTPError(status_code=404) + + # content_type, _ = guess_type(file_location) + # self.add_header('Content-Type', content_type) + # with open(file_location) as source_file: + # self.write(source_file.read()) + + + + + # public_dir = self.learn.get_current_public_dir(uid) # FIXME!!! + # filepath = path.expanduser(path.join(public_dir, filename)) + # try: + # f = open(filepath, 'rb') + # except FileNotFoundError: + # raise tornado.web.HTTPError(404) + # else: + # self.write(f.read()) + # f.close() # ------------------------------------------------------------------------- @@ -309,7 +327,7 @@ def main(): logger_file = 'logger-debug.yaml' if arg.debug else 'logger.yaml' SERVER_PATH = path.dirname(path.realpath(__file__)) LOGGER_CONF = path.join(SERVER_PATH, f'config/{logger_file}') - + try: logging.config.dictConfig(load_yaml(LOGGER_CONF)) except: @@ -318,10 +336,14 @@ def main(): logging.info('===============================================') # --- start application - filename = path.abspath(path.expanduser(arg.testfile[0])) + config = { + 'filename': arg.testfile[0] or '', + 'debug': arg.debug, + 'allow_all': arg.allow_all, + } try: - app = App(filename, vars(arg)) + app = App(config) except AppException: logging.critical('Failed to start application.') sys.exit(1) diff --git a/templates/admin.html b/templates/admin.html index 3a7798b..1b0d4e5 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -66,10 +66,10 @@ - - - - + + + +
NúmeroNomeEstadoNotaNúmeroNomeEstadoNota
diff --git a/test.py b/test.py index 8452ea6..b6ee5e0 100644 --- a/test.py +++ b/test.py @@ -9,7 +9,7 @@ import logging # project import questions -from tools import load_yaml +# from tools import load_yaml # Logger configuration logger = logging.getLogger(__name__) @@ -29,17 +29,11 @@ class TestFactory(dict): # some configurations using the conf argument. # base questions are loaded from files into a pool. # ----------------------------------------------------------------------- - def __init__(self, filename=None, conf={}): - super().__init__({}) + def __init__(self, conf): + super().__init__(conf) - if filename is not None: - self.update(load_yaml(filename)) - self['filename'] = filename - else: - self['filename'] = '' - - self.update(conf) # overrides configuration - self.sanity_checks() # defaults and sanity checks + # set defaults and sanity checks + self.sanity_checks() # loads question_factory self.question_factory = questions.QuestionFactory() @@ -66,7 +60,7 @@ class TestFactory(dict): # --- database if 'database' not in self: - logger.critical('Missing "database" key in configuration.') + logger.critical('Missing "database" in configuration.') raise TestFactoryException() elif not path.isfile(path.expanduser(self['database'])): logger.critical(f'Can\'t find database {self["database"]}.') @@ -74,7 +68,7 @@ class TestFactory(dict): # --- answers_dir if 'answers_dir' not in self: - logger.warning('Missing "answers_dir".') + logger.critical('Missing "answers_dir".') raise TestFactoryException() try: # check if answers_dir is a writable directory f = open(path.join(path.expanduser(self['answers_dir']),'REMOVE-ME'), 'w') @@ -127,7 +121,7 @@ class TestFactory(dict): # --- defaults for optional keys self.setdefault('title', '') - self.setdefault('show_hints', False) + self.setdefault('show_hints', False) # FIXME not implemented yet self.setdefault('show_points', False) self.setdefault('scale_points', True) self.setdefault('scale_max', 20.0) @@ -178,7 +172,6 @@ class TestFactory(dict): 'student': student, # student id 'questions': test, # list of questions 'answers_dir': self['answers_dir'], - # 'total_points': total_points, # FIXME which ones are required? 'show_hints': self['show_hints'], @@ -191,8 +184,8 @@ class TestFactory(dict): }) # ----------------------------------------------------------------------- - def __repr__(self): - return '{\n' + '\n'.join(' {0:14s}: {1}'.format(k, v) for k,v in self.items()) + '\n}' + # def __repr__(self): + # return '{\n' + '\n'.join(' {0:14s}: {1}'.format(k, v) for k,v in self.items()) + '\n}' # =========================================================================== -- libgit2 0.21.2