From 834ee855dfefda15dd43718d1abebc5db99f327d Mon Sep 17 00:00:00 2001 From: Miguel Barão Date: Sat, 2 May 2020 15:08:04 +0100 Subject: [PATCH] - csv file with the grades is named after the test "ref". --- perguntations/app.py | 2 +- perguntations/serve.py | 5 +++-- perguntations/test.py | 8 ++++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/perguntations/app.py b/perguntations/app.py index c4dc8c3..c4c229e 100644 --- a/perguntations/app.py +++ b/perguntations/app.py @@ -294,7 +294,7 @@ class App(): writer = csv.writer(csvstr, delimiter=';', quoting=csv.QUOTE_ALL) writer.writerow(('Número', 'Nota', 'Início', 'Fim')) writer.writerows(grades) - return csvstr.getvalue() + return self.testfactory['ref'], csvstr.getvalue() def get_student_test(self, uid, default=None): '''get test from online student''' diff --git a/perguntations/serve.py b/perguntations/serve.py index 79c0b16..2f2e703 100644 --- a/perguntations/serve.py +++ b/perguntations/serve.py @@ -184,10 +184,11 @@ class AdminWebservice(BaseHandler): '''admin webservices that do not change state''' cmd = self.get_query_argument('cmd') if cmd == 'testcsv': + test_ref, data = self.testapp.get_test_csv() self.set_header('Content-Type', 'text/csv') self.set_header('content-Disposition', - 'attachment; filename=notas.csv') - self.write(self.testapp.get_test_csv()) + f'attachment; filename={test_ref}.csv') + self.write(data) await self.flush() # ---------------------------------------------------------------------------- diff --git a/perguntations/test.py b/perguntations/test.py index e2d7ed1..3f53e31 100644 --- a/perguntations/test.py +++ b/perguntations/test.py @@ -9,6 +9,7 @@ from os import path import random from datetime import datetime import logging +import re # this project from perguntations.questions import QFactory, QuestionException @@ -123,10 +124,13 @@ class TestFactory(dict): # ------------------------------------------------------------------------ - def check_missing_ref(self): + def check_test_ref(self): '''Test must have a `ref`''' if 'ref' not in self: raise TestFactoryException('Missing "ref" in configuration!') + if not re.match(r'^[a-zA-Z0-9_-]+$', self['ref']): + raise TestFactoryException('Test "ref" can only contain the ' + 'characters a-zA-Z0-9_-') def check_missing_database(self): '''Test must have a database''' @@ -208,7 +212,7 @@ class TestFactory(dict): Checks for valid keys and sets default values. Also checks if some files and directories exist ''' - self.check_missing_ref() + self.check_test_ref() self.check_missing_database() self.check_missing_answers_directory() self.check_answers_directory_writable() -- libgit2 0.21.2