diff --git a/database.py b/database.py index 3164050..a851884 100644 --- a/database.py +++ b/database.py @@ -15,9 +15,18 @@ class Database(object): # return list of students and their results for a given test def test_grades(self, test_id): with sqlite3.connect(self.db) as c: - cmd = 'SELECT student_id,name,grade FROM students INNER JOIN tests ON students.number=tests.student_id WHERE test_id==? ORDER BY grade DESC;' - results = c.execute(cmd, [test_id]) - return results.fetchall() + # with all tests done by each student: + # cmd = 'SELECT student_id,name,grade FROM students INNER JOIN tests ON students.number=tests.student_id WHERE test_id==? ORDER BY grade DESC;' + + # only the best result for each student + cmd = ''' + SELECT student_id, name, MAX(grade) + FROM students INNER JOIN tests + ON students.number=tests.student_id + WHERE test_id==? + GROUP BY student_id + ORDER BY grade DESC;''' + return c.execute(cmd, [test_id]).fetchall() # get list of students in the database def get_students(self): diff --git a/serve.py b/serve.py index c6c9dc4..4171b57 100755 --- a/serve.py +++ b/serve.py @@ -23,8 +23,7 @@ class Root(object): self.database = database.Database(testconf['database']) self.auth = AuthController(database=testconf['database']) self.templates = TemplateLookup(directories=['templates'], input_encoding='utf-8') - self.tags = {'online': set(), 'finished': set()} - # self.loggedin = set() # students currently logged in + self.tags = {'online': set(), 'finished': set()} # should be in application, not server # --- DEFAULT ------------------------------------------------------------ # any path, e.g. /xpto/aargh is redirected to the test diff --git a/templates/students.html b/templates/students.html index e782fdc..7a66a8f 100644 --- a/templates/students.html +++ b/templates/students.html @@ -63,9 +63,7 @@