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