Commit 678b6b011d1d357c8b34b355cdd3a83611bf97e5

Authored by Miguel Barao
1 parent 2ed48b70
Exists in master and in 1 other branch dev

- minor corrections.

@@ -57,6 +57,20 @@ A test is just a yaml file with the configuration for that test. Look at `demo/t @@ -57,6 +57,20 @@ A test is just a yaml file with the configuration for that test. Look at `demo/t
57 Questions are defined in yaml files. Each yaml file contains a list of questions 57 Questions are defined in yaml files. Each yaml file contains a list of questions
58 58
59 59
  60 +
  61 +
  62 +
  63 +
  64 +
  65 +
  66 +
  67 +
  68 +
  69 +
  70 +
  71 +
  72 +
  73 +
60 Before using the program you need to 74 Before using the program you need to
61 75
62 1. Edit `config/server.conf` in the server directory and define 76 1. Edit `config/server.conf` in the server directory and define
@@ -35,7 +35,6 @@ class App(object): @@ -35,7 +35,6 @@ class App(object):
35 35
36 # database 36 # database
37 engine = create_engine('sqlite:///{}'.format(self.testfactory['database']), echo=False) 37 engine = create_engine('sqlite:///{}'.format(self.testfactory['database']), echo=False)
38 - Base.metadata.create_all(engine) # Criate schema if needed FIXME no student '0'  
39 self.Session = scoped_session(sessionmaker(bind=engine)) 38 self.Session = scoped_session(sessionmaker(bind=engine))
40 39
41 try: 40 try:
@@ -44,11 +44,13 @@ try: @@ -44,11 +44,13 @@ try:
44 try: 44 try:
45 csvreader = csv.DictReader(open(args.csvfile, encoding='iso-8859-1'), delimiter=';', quotechar='"') 45 csvreader = csv.DictReader(open(args.csvfile, encoding='iso-8859-1'), delimiter=';', quotechar='"')
46 except EnvironmentError: 46 except EnvironmentError:
47 - print('CSV file "{0}" not found!'.format(args.csvfile)) 47 + print('Error: CSV file "{0}" not found.'.format(args.csvfile))
  48 + session.rollback()
  49 + sys.exit(1)
48 else: 50 else:
49 session.add_all([Student(id=r['N.º'], name=fix(r['Nome']), password='') for r in csvreader]) 51 session.add_all([Student(id=r['N.º'], name=fix(r['Nome']), password='') for r in csvreader])
50 else: 52 else:
51 - # otherwise add 5 fake students 53 + # otherwise add a few fake students
52 fakes = [ 54 fakes = [
53 ['1888', 'Fernando Pessoa'], 55 ['1888', 'Fernando Pessoa'],
54 ['1799', 'Almeida Garrett'], 56 ['1799', 'Almeida Garrett'],
@@ -65,8 +67,8 @@ try: @@ -65,8 +67,8 @@ try:
65 session.commit() 67 session.commit()
66 68
67 except Exception: 69 except Exception:
68 - session.rollback()  
69 print('Error: Database already exists.') 70 print('Error: Database already exists.')
  71 + session.rollback()
70 sys.exit(1) 72 sys.exit(1)
71 73
72 else: 74 else:
@@ -20,6 +20,7 @@ from tools import load_yaml @@ -20,6 +20,7 @@ from tools import load_yaml
20 20
21 # ============================================================================ 21 # ============================================================================
22 # Authentication 22 # Authentication
  23 +# http://tools.cherrypy.org/wiki/AuthenticationAndAccessRestrictions
23 # ============================================================================ 24 # ============================================================================
24 def check_auth(*args, **kwargs): 25 def check_auth(*args, **kwargs):
25 """A tool that looks in config for 'auth.require'. If found and it 26 """A tool that looks in config for 'auth.require'. If found and it
@@ -91,7 +92,6 @@ class AdminWebService(object): @@ -91,7 +92,6 @@ class AdminWebService(object):
91 92
92 @cherrypy.tools.accept(media='application/json') # FIXME 93 @cherrypy.tools.accept(media='application/json') # FIXME
93 def POST(self, **args): 94 def POST(self, **args):
94 - # print('POST', args) # FIXME  
95 if args['cmd'] == 'allow': 95 if args['cmd'] == 'allow':
96 if args['value'] == 'true': 96 if args['value'] == 'true':
97 return self.app.allow_student(args['name']) 97 return self.app.allow_student(args['name'])
@@ -105,7 +105,7 @@ class AdminWebService(object): @@ -105,7 +105,7 @@ class AdminWebService(object):
105 return self.app.insert_new_student(uid=args['number'], name=args['name']) 105 return self.app.insert_new_student(uid=args['number'], name=args['name'])
106 106
107 else: 107 else:
108 - print(args) 108 + print(args) # FIXME
109 109
110 # ============================================================================ 110 # ============================================================================
111 # Student webservice 111 # Student webservice
@@ -134,10 +134,10 @@ class Root(object): @@ -134,10 +134,10 @@ class Root(object):
134 self.app = app 134 self.app = app
135 t = TemplateLookup(directories=[TEMPLATES_DIR], input_encoding='utf-8') 135 t = TemplateLookup(directories=[TEMPLATES_DIR], input_encoding='utf-8')
136 self.template = { 136 self.template = {
137 - 'login': t.get_template('/login.html'),  
138 - 'test': t.get_template('/test.html'),  
139 - 'grade': t.get_template('/grade.html'),  
140 - 'admin': t.get_template('/admin.html'), 137 + 'login': t.get_template('/login.html'),
  138 + 'test': t.get_template('/test.html'),
  139 + 'grade': t.get_template('/grade.html'),
  140 + 'admin': t.get_template('/admin.html'),
141 'review': t.get_template('/review.html'), 141 'review': t.get_template('/review.html'),
142 } 142 }
143 143
@@ -260,7 +260,8 @@ class Root(object): @@ -260,7 +260,8 @@ class Root(object):
260 # --- ADMIN -------------------------------------------------------------- 260 # --- ADMIN --------------------------------------------------------------
261 @cherrypy.expose 261 @cherrypy.expose
262 @require(name_is('0')) 262 @require(name_is('0'))
263 - def admin(self, **reset_pw): 263 + # def admin(self, **reset_pw):
  264 + def admin(self):
264 return self.template['admin'].render() 265 return self.template['admin'].render()
265 266
266 # --- REVIEW ------------------------------------------------------------- 267 # --- REVIEW -------------------------------------------------------------
templates/grade.html
@@ -4,12 +4,13 @@ @@ -4,12 +4,13 @@
4 <meta charset="UTF-8"> 4 <meta charset="UTF-8">
5 <meta http-equiv="X-UA-Compatible" content="IE=edge"> 5 <meta http-equiv="X-UA-Compatible" content="IE=edge">
6 <meta name="viewport" content="width=device-width, initial-scale=1"> 6 <meta name="viewport" content="width=device-width, initial-scale=1">
7 - <title> Teste </title> 7 + <title>Teste</title>
8 <link rel="icon" href="/static/favicon.ico"> 8 <link rel="icon" href="/static/favicon.ico">
9 9
10 <!-- Bootstrap --> 10 <!-- Bootstrap -->
11 <link rel="stylesheet" href="/static/css/bootstrap.min.css"> 11 <link rel="stylesheet" href="/static/css/bootstrap.min.css">
12 <link rel="stylesheet" href="/static/css/bootstrap-theme.min.css"> <!-- optional --> 12 <link rel="stylesheet" href="/static/css/bootstrap-theme.min.css"> <!-- optional -->
  13 + <link rel="stylesheet" href="/static/font-awesome/css/font-awesome.min.css">
13 <link rel="stylesheet" href="/static/css/test.css"> 14 <link rel="stylesheet" href="/static/css/test.css">
14 15
15 <script src="/static/js/jquery.min.js"></script> 16 <script src="/static/js/jquery.min.js"></script>
@@ -36,10 +37,9 @@ @@ -36,10 +37,9 @@
36 <ul class="nav navbar-nav navbar-right"> 37 <ul class="nav navbar-nav navbar-right">
37 <li class="dropdown"> 38 <li class="dropdown">
38 <a class="dropdown-toggle" data-toggle="dropdown" href="#"> 39 <a class="dropdown-toggle" data-toggle="dropdown" href="#">
39 - <span class="glyphicon glyphicon-user" aria-hidden="true"></span> 40 + <i class="fa fa-user" aria-hidden="true"></i>
40 <span id="name">${t['student']['name']}</span> 41 <span id="name">${t['student']['name']}</span>
41 (<span id="number">${t['student']['number']}</span>) 42 (<span id="number">${t['student']['number']}</span>)
42 - <!-- <span class="caret"></span> -->  
43 </a> 43 </a>
44 </li> 44 </li>
45 </ul> 45 </ul>