From 0e95aad2c4dd6637d4955f76b4bdbecf25864236 Mon Sep 17 00:00:00 2001 From: Miguel Barão Date: Mon, 2 May 2016 19:26:36 +0100 Subject: [PATCH] - /students shows active/inactive/finished in separate panels --- database.py | 15 +++++++++++++++ serve.py | 5 +++-- templates/students.html | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------- 3 files changed, 109 insertions(+), 37 deletions(-) diff --git a/database.py b/database.py index 1d59c52..666c936 100644 --- a/database.py +++ b/database.py @@ -29,6 +29,21 @@ class Database(object): ORDER BY grade DESC, finish_time DESC;''' return c.execute(cmd, [test_id]).fetchall() + # return list of students and their results for a given test + def test_grades2(self, test_id): + with sqlite3.connect(self.db) as c: + # 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, grade, start_time, finish_time + FROM students INNER JOIN tests + ON students.number=tests.student_id + WHERE test_id==? + ORDER BY finish_time ASC;''' + return c.execute(cmd, [test_id]).fetchall() + # get list of students in the database def get_students(self): with sqlite3.connect(self.db) as c: diff --git a/serve.py b/serve.py index cbad33d..070273f 100755 --- a/serve.py +++ b/serve.py @@ -17,7 +17,6 @@ except ImportError: try: from mako.lookup import TemplateLookup - import djks except ImportError: print('The package "mako" is missing. See README.md for instructions.') sys.exit(1) @@ -78,9 +77,11 @@ class Root(object): for num in reset_pw: cherrypy.log.error('Password updated for student %s.' % str(num), 'APPLICATION') + grades = self.database.test_grades2(self.testconf['ref']) students = self.database.get_students() + template = self.templates.get_template('/students.html') - return template.render(students=students, tags=self.tags) + return template.render(students=students, tags=self.tags, grades=grades) # --- RESULTS ------------------------------------------------------------ @cherrypy.expose diff --git a/templates/students.html b/templates/students.html index 7a66a8f..2a6debe 100644 --- a/templates/students.html +++ b/templates/students.html @@ -33,46 +33,102 @@
- ${len(tags['online'])} online ${len(tags['finished'])} finished + ${len(tags['finished'])} Terminado(s)
- - - - - - - - - - - - % for r in students: +
+
TagsNúmeroNomePassword
+ - + + + + + + + + % for r in grades: + % if r[0] in tags['finished']: - finished + + + + + + % endif - - - - + + % endfor + +
- % if r[0] in tags['online']: - online - % endif + NúmeroNomeLoginLogoutNota
${r[0]} ${r[1]} ${r[3][:19]}${r[4][:19]}${r[2]}${r[0]} ${r[1]} -
-
- - - - -
-
-
+
+
+ +
+
+ ${len(tags['online'])} Activo(s) +
+
+ + + + + + - % endfor - -
NúmeroNome
-
+ + + % for r in students: + + % if r[0] in tags['online']: + ${r[0]} + ${r[1]} + % endif + + % endfor + + +
+ + + +
+
+ ${len(students)-len(tags['online'])} Inactivo(s) +
+
+ + + + + + + + + + + % for r in students: + + % if r[0] not in tags['online']: + + + + % endif + + % endfor + +
NúmeroNomePassword
${r[0]} ${r[1]} +
+
+ + + + +
+
+
+
+
-- libgit2 0.21.2