Commit 0e95aad2c4dd6637d4955f76b4bdbecf25864236

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

- /students shows active/inactive/finished in separate panels

Showing 3 changed files with 109 additions and 37 deletions   Show diff stats
database.py
... ... @@ -29,6 +29,21 @@ class Database(object):
29 29 ORDER BY grade DESC, finish_time DESC;'''
30 30 return c.execute(cmd, [test_id]).fetchall()
31 31  
  32 + # return list of students and their results for a given test
  33 + def test_grades2(self, test_id):
  34 + with sqlite3.connect(self.db) as c:
  35 + # with all tests done by each student:
  36 + # cmd = 'SELECT student_id,name,grade FROM students INNER JOIN tests ON students.number=tests.student_id WHERE test_id==? ORDER BY grade DESC;'
  37 +
  38 + # only the best result for each student
  39 + cmd = '''
  40 + SELECT student_id, name, grade, start_time, finish_time
  41 + FROM students INNER JOIN tests
  42 + ON students.number=tests.student_id
  43 + WHERE test_id==?
  44 + ORDER BY finish_time ASC;'''
  45 + return c.execute(cmd, [test_id]).fetchall()
  46 +
32 47 # get list of students in the database
33 48 def get_students(self):
34 49 with sqlite3.connect(self.db) as c:
... ...
serve.py
... ... @@ -17,7 +17,6 @@ except ImportError:
17 17  
18 18 try:
19 19 from mako.lookup import TemplateLookup
20   - import djks
21 20 except ImportError:
22 21 print('The package "mako" is missing. See README.md for instructions.')
23 22 sys.exit(1)
... ... @@ -78,9 +77,11 @@ class Root(object):
78 77 for num in reset_pw:
79 78 cherrypy.log.error('Password updated for student %s.' % str(num), 'APPLICATION')
80 79  
  80 + grades = self.database.test_grades2(self.testconf['ref'])
81 81 students = self.database.get_students()
  82 +
82 83 template = self.templates.get_template('/students.html')
83   - return template.render(students=students, tags=self.tags)
  84 + return template.render(students=students, tags=self.tags, grades=grades)
84 85  
85 86 # --- RESULTS ------------------------------------------------------------
86 87 @cherrypy.expose
... ...
templates/students.html
... ... @@ -33,46 +33,102 @@
33 33 <div class="container">
34 34 <div class="panel panel-default drop-shadow">
35 35 <div class="panel-heading">
36   - <span class="badge">${len(tags['online'])} online</span> <span class="badge">${len(tags['finished'])} finished</span>
  36 + ${len(tags['finished'])} Terminado(s)</span>
37 37 </div>
38   - <!-- <div class="panel-body"> -->
39   - <table class="table">
40   - <thead>
41   - <tr>
42   - <th>Tags</th>
43   - <th>Número</th>
44   - <th>Nome</th>
45   - <th>Password</th>
46   - </tr>
47   - </thead>
48   - <tbody>
49   - % for r in students:
  38 + <div class="panel-body">
  39 + <table class="table">
  40 + <thead>
50 41 <tr>
51   - <td>
52   - % if r[0] in tags['online']:
53   - <span class="label label-primary">online</span>
54   - % endif
  42 + <th>Número</th>
  43 + <th>Nome</th>
  44 + <th>Login</th>
  45 + <th>Logout</th>
  46 + <th>Nota</th>
  47 + </tr>
  48 + </thead>
  49 + <tbody>
  50 + % for r in grades:
  51 + <tr>
55 52 % if r[0] in tags['finished']:
56   - <span class="label label-success">finished</span>
  53 + <td>${r[0]}</td> <!-- numero -->
  54 + <td>${r[1]}</td> <!-- nome -->
  55 + <td>${r[3][:19]}</td>
  56 + <td>${r[4][:19]}</td>
  57 + <td>${r[2]}</td>
  58 +
57 59 % endif
58   - </td>
59   - <td>${r[0]}</td> <!-- numero -->
60   - <td>${r[1]}</td> <!-- nome -->
61   - <td class="col-sm-3">
62   - <form action="/students/" method="post" id="${r[0]}">
63   - <div class="input-group">
64   - <input type="password" class="form-control" placeholder="${r[2][:8]}" name="${r[0]}">
65   - <span class="input-group-btn">
66   - <button form="${r[0]}" type="submit" value="submit" class="btn btn-danger">reset</button>
67   - </span>
68   - </div><!-- /input-group -->
69   - </form>
70   - </td> <!-- password -->
  60 + </tr>
  61 + % endfor
  62 + </tbody>
  63 + </table>
  64 + </div>
  65 + </div>
  66 +
  67 + <div class="panel panel-success drop-shadow">
  68 + <div class="panel-heading">
  69 + ${len(tags['online'])} Activo(s)</span>
  70 + </div>
  71 + <div class="panel-body">
  72 + <table class="table">
  73 + <thead>
  74 + <tr>
  75 + <th>Número</th>
  76 + <th>Nome</th>
  77 +<!-- <th>Login</th> -->
71 78 </tr>
72   - % endfor
73   - </tbody>
74   - </table>
75   - </div> <!-- panel -->
  79 + </thead>
  80 + <tbody>
  81 + % for r in students:
  82 + <tr>
  83 + % if r[0] in tags['online']:
  84 + <td>${r[0]}</td> <!-- numero -->
  85 + <td>${r[1]}</td> <!-- nome -->
  86 + % endif
  87 + </tr>
  88 + % endfor
  89 + </tbody>
  90 + </table>
  91 + </div>
  92 + </div>
  93 +
  94 +
  95 + <div class="panel panel-danger drop-shadow">
  96 + <div class="panel-heading">
  97 + ${len(students)-len(tags['online'])} Inactivo(s)</span>
  98 + </div>
  99 + <div class="panel-body">
  100 +
  101 + <table class="table">
  102 + <thead>
  103 + <tr>
  104 + <th>Número</th>
  105 + <th>Nome</th>
  106 + <th>Password</th>
  107 + </tr>
  108 + </thead>
  109 + <tbody>
  110 + % for r in students:
  111 + <tr>
  112 + % if r[0] not in tags['online']:
  113 + <td>${r[0]}</td> <!-- numero -->
  114 + <td>${r[1]}</td> <!-- nome -->
  115 + <td class="col-sm-3">
  116 + <form action="/students/" method="post" id="${r[0]}">
  117 + <div class="input-group">
  118 + <input type="password" class="form-control" placeholder="${r[2][:8]}" name="${r[0]}">
  119 + <span class="input-group-btn">
  120 + <button form="${r[0]}" type="submit" value="submit" class="btn btn-danger">reset</button>
  121 + </span>
  122 + </div><!-- /input-group -->
  123 + </form>
  124 + </td> <!-- password -->
  125 + % endif
  126 + </tr>
  127 + % endfor
  128 + </tbody>
  129 + </table>
  130 + </div>
  131 + </div>
76 132 </div> <!-- container -->
77 133 </body>
78 134 </html>
... ...