Commit 834ee855dfefda15dd43718d1abebc5db99f327d

Authored by Miguel Barão
1 parent eda5bbbc
Exists in master and in 1 other branch dev

- csv file with the grades is named after the test "ref".

perguntations/app.py
... ... @@ -294,7 +294,7 @@ class App():
294 294 writer = csv.writer(csvstr, delimiter=';', quoting=csv.QUOTE_ALL)
295 295 writer.writerow(('Número', 'Nota', 'Início', 'Fim'))
296 296 writer.writerows(grades)
297   - return csvstr.getvalue()
  297 + return self.testfactory['ref'], csvstr.getvalue()
298 298  
299 299 def get_student_test(self, uid, default=None):
300 300 '''get test from online student'''
... ...
perguntations/serve.py
... ... @@ -184,10 +184,11 @@ class AdminWebservice(BaseHandler):
184 184 '''admin webservices that do not change state'''
185 185 cmd = self.get_query_argument('cmd')
186 186 if cmd == 'testcsv':
  187 + test_ref, data = self.testapp.get_test_csv()
187 188 self.set_header('Content-Type', 'text/csv')
188 189 self.set_header('content-Disposition',
189   - 'attachment; filename=notas.csv')
190   - self.write(self.testapp.get_test_csv())
  190 + f'attachment; filename={test_ref}.csv')
  191 + self.write(data)
191 192 await self.flush()
192 193  
193 194 # ----------------------------------------------------------------------------
... ...
perguntations/test.py
... ... @@ -9,6 +9,7 @@ from os import path
9 9 import random
10 10 from datetime import datetime
11 11 import logging
  12 +import re
12 13  
13 14 # this project
14 15 from perguntations.questions import QFactory, QuestionException
... ... @@ -123,10 +124,13 @@ class TestFactory(dict):
123 124  
124 125  
125 126 # ------------------------------------------------------------------------
126   - def check_missing_ref(self):
  127 + def check_test_ref(self):
127 128 '''Test must have a `ref`'''
128 129 if 'ref' not in self:
129 130 raise TestFactoryException('Missing "ref" in configuration!')
  131 + if not re.match(r'^[a-zA-Z0-9_-]+$', self['ref']):
  132 + raise TestFactoryException('Test "ref" can only contain the '
  133 + 'characters a-zA-Z0-9_-')
130 134  
131 135 def check_missing_database(self):
132 136 '''Test must have a database'''
... ... @@ -208,7 +212,7 @@ class TestFactory(dict):
208 212 Checks for valid keys and sets default values.
209 213 Also checks if some files and directories exist
210 214 '''
211   - self.check_missing_ref()
  215 + self.check_test_ref()
212 216 self.check_missing_database()
213 217 self.check_missing_answers_directory()
214 218 self.check_answers_directory_writable()
... ...