diff --git a/app.py b/app.py index da99666..733c975 100644 --- a/app.py +++ b/app.py @@ -144,7 +144,9 @@ class App(object): starttime=str(t['start_time']), finishtime=str(t['finish_time']), filename=fpath, - student_id=t['student']['number'])) + student_id=t['student']['number'], + state=t['state'], + comment='')) s.add_all([Question( ref=q['ref'], grade=q['grade'], @@ -159,13 +161,29 @@ class App(object): # ----------------------------------------------------------------------- def giveup_test(self, uid): - logger.info('Student {0}: gave up.'.format(uid)) t = self.online[uid]['test'] grade = t.giveup() - if t['save_answers']: - fname = ' -- '.join((t['student']['number'], t['ref'], str(t['finish_time']))) + '.json' - fpath = path.abspath(path.join(t['answers_dir'], fname)) - t.save_json(fpath) + + # save JSON with the test + fname = ' -- '.join((t['student']['number'], t['ref'], str(t['finish_time']))) + '.json' + fpath = path.abspath(path.join(t['answers_dir'], fname)) + t.save_json(fpath) + + # insert test into database + with self.db_session() as s: + s.add(Test( + ref=t['ref'], + title=t['title'], + grade=t['grade'], + starttime=str(t['start_time']), + finishtime=str(t['finish_time']), + filename=fpath, + student_id=t['student']['number'], + state=t['state'], + comment='')) + s.commit() + + logger.info('Student {0}: gave up.'.format(uid)) return t # ----------------------------------------------------------------------- diff --git a/models.py b/models.py index a8cb15d..6449dea 100644 --- a/models.py +++ b/models.py @@ -29,8 +29,10 @@ class Test(Base): __tablename__ = 'tests' id = Column(Integer, primary_key=True) # auto_increment ref = Column(String) - title = Column(String) + title = Column(String) # FIXME depends on ref and should come from another table... grade = Column(Float) + state = Column(String) # ONGOING, FINISHED, QUIT, NULL + comment = Column(String) starttime = Column(String) finishtime = Column(String) filename = Column(String) diff --git a/templates/grade.html b/templates/grade.html index 92e74bd..c2c442f 100644 --- a/templates/grade.html +++ b/templates/grade.html @@ -50,8 +50,16 @@
Teve ${t['grade']} valores na escala de 0 a 20.
-A prova está terminada, pode fechar o browser e desligar o computador.
+ + % if t['state'] == 'FINISHED': +Teve ${t['grade']} valores na escala de 0 a 20.
+ + % elif t['state'] == 'QUIT': +Foi registada a sua desistência da prova.
+ + % endif + +Pode fechar o browser e desligar o computador.