From 678b6b011d1d357c8b34b355cdd3a83611bf97e5 Mon Sep 17 00:00:00 2001 From: Miguel Barao Date: Tue, 19 Jul 2016 11:55:58 +0100 Subject: [PATCH] - minor corrections. --- MANUAL.md | 14 ++++++++++++++ app.py | 1 - initdb.py | 8 +++++--- serve.py | 15 ++++++++------- templates/grade.html | 6 +++--- 5 files changed, 30 insertions(+), 14 deletions(-) diff --git a/MANUAL.md b/MANUAL.md index f867ebf..3844c2b 100644 --- a/MANUAL.md +++ b/MANUAL.md @@ -57,6 +57,20 @@ A test is just a yaml file with the configuration for that test. Look at `demo/t Questions are defined in yaml files. Each yaml file contains a list of questions + + + + + + + + + + + + + + Before using the program you need to 1. Edit `config/server.conf` in the server directory and define diff --git a/app.py b/app.py index 733c975..0cebb6a 100644 --- a/app.py +++ b/app.py @@ -35,7 +35,6 @@ class App(object): # database engine = create_engine('sqlite:///{}'.format(self.testfactory['database']), echo=False) - Base.metadata.create_all(engine) # Criate schema if needed FIXME no student '0' self.Session = scoped_session(sessionmaker(bind=engine)) try: diff --git a/initdb.py b/initdb.py index 85bde8f..cf7c27e 100755 --- a/initdb.py +++ b/initdb.py @@ -44,11 +44,13 @@ try: try: csvreader = csv.DictReader(open(args.csvfile, encoding='iso-8859-1'), delimiter=';', quotechar='"') except EnvironmentError: - print('CSV file "{0}" not found!'.format(args.csvfile)) + print('Error: CSV file "{0}" not found.'.format(args.csvfile)) + session.rollback() + sys.exit(1) else: session.add_all([Student(id=r['N.ยบ'], name=fix(r['Nome']), password='') for r in csvreader]) else: - # otherwise add 5 fake students + # otherwise add a few fake students fakes = [ ['1888', 'Fernando Pessoa'], ['1799', 'Almeida Garrett'], @@ -65,8 +67,8 @@ try: session.commit() except Exception: - session.rollback() print('Error: Database already exists.') + session.rollback() sys.exit(1) else: diff --git a/serve.py b/serve.py index 869fe88..effb31e 100755 --- a/serve.py +++ b/serve.py @@ -20,6 +20,7 @@ from tools import load_yaml # ============================================================================ # Authentication +# http://tools.cherrypy.org/wiki/AuthenticationAndAccessRestrictions # ============================================================================ def check_auth(*args, **kwargs): """A tool that looks in config for 'auth.require'. If found and it @@ -91,7 +92,6 @@ class AdminWebService(object): @cherrypy.tools.accept(media='application/json') # FIXME def POST(self, **args): - # print('POST', args) # FIXME if args['cmd'] == 'allow': if args['value'] == 'true': return self.app.allow_student(args['name']) @@ -105,7 +105,7 @@ class AdminWebService(object): return self.app.insert_new_student(uid=args['number'], name=args['name']) else: - print(args) + print(args) # FIXME # ============================================================================ # Student webservice @@ -134,10 +134,10 @@ class Root(object): self.app = app t = TemplateLookup(directories=[TEMPLATES_DIR], input_encoding='utf-8') self.template = { - 'login': t.get_template('/login.html'), - 'test': t.get_template('/test.html'), - 'grade': t.get_template('/grade.html'), - 'admin': t.get_template('/admin.html'), + 'login': t.get_template('/login.html'), + 'test': t.get_template('/test.html'), + 'grade': t.get_template('/grade.html'), + 'admin': t.get_template('/admin.html'), 'review': t.get_template('/review.html'), } @@ -260,7 +260,8 @@ class Root(object): # --- ADMIN -------------------------------------------------------------- @cherrypy.expose @require(name_is('0')) - def admin(self, **reset_pw): + # def admin(self, **reset_pw): + def admin(self): return self.template['admin'].render() # --- REVIEW ------------------------------------------------------------- diff --git a/templates/grade.html b/templates/grade.html index c2c442f..22d9300 100644 --- a/templates/grade.html +++ b/templates/grade.html @@ -4,12 +4,13 @@ - Teste + Teste + @@ -36,10 +37,9 @@ -- libgit2 0.21.2