From 8005184eaa8150e2041879dc445ff8eae82d75ec Mon Sep 17 00:00:00 2001 From: Miguel Barão Date: Tue, 1 Nov 2016 12:30:16 +0000 Subject: [PATCH] - minor changes --- BUGS.md | 2 +- app.py | 24 +++++++++--------------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/BUGS.md b/BUGS.md index 9ecad8b..5d17782 100644 --- a/BUGS.md +++ b/BUGS.md @@ -1,12 +1,12 @@ # BUGS -- servidor nao esta a lidar com eventos scroll/resize - se um teste tiver a mesma pergunta (ref igual) varias vezes, rebenta na correcçao. As respostas são agregadas numa lista para cada ref. Ex: {'ref1': 'resposta1', 'ref2': ['resposta2a', 'resposta2b']} possivelmente as referencias das perguntas deveriam ser o "testeRef:numPergunta"... é preciso ver como depois estao associadas às correcções. - se directorio logs não existir no directorio actual (não perguntations) rebenta. - usar thread.Lock para aceder a variaveis de estado? +- servidor nao esta a lidar com eventos scroll/resize # TODO diff --git a/app.py b/app.py index 32d0f72..d73479b 100644 --- a/app.py +++ b/app.py @@ -33,7 +33,7 @@ class App(object): self.testfactory = test.TestFactory(filename, conf=conf) - # database + # connect to database and check registered students engine = create_engine('sqlite:///{}'.format(self.testfactory['database']), echo=False) self.Session = scoped_session(sessionmaker(bind=engine)) @@ -46,11 +46,17 @@ class App(object): else: logger.info('Database has {} students registered.'.format(n)) + # command line option --allow-all if conf['allow_all']: logger.info('Allowing all students') for student in self.get_all_students(): self.allow_student(student[0]) + # ----------------------------------------------------------------------- + def exit(self): + if len(self.online) > 1: + logger.warning('Students still online: {}'.format(', '.join(self.online))) + logger.critical('----------- !!! Server terminated !!! -----------') # ----------------------------------------------------------------------- # helper to manage db sessions using the `with` statement, for example @@ -63,12 +69,6 @@ class App(object): self.Session.remove() # ----------------------------------------------------------------------- - def exit(self): - if len(self.online) > 1: - logger.warning('Students still online: {}'.format(', '.join(self.online))) - logger.critical('----------- !!! Server terminated !!! -----------') - - # ----------------------------------------------------------------------- def login(self, uid, try_pw): if uid not in self.allowed and uid != '0': # not allowed @@ -107,14 +107,8 @@ class App(object): # ----------------------------------------------------------------------- def logout(self, uid): - if uid not in self.online: - # this should never happen - logger.error('Student {}: tried to logout, but is not logged in.'.format(uid)) - return False - else: - logger.info('Student {}: logged out.'.format(uid)) - del self.online[uid] - return True + del self.online[uid] + logger.info('Student {}: logged out.'.format(uid)) # ----------------------------------------------------------------------- def generate_test(self, uid): -- libgit2 0.21.2