diff --git a/questions.py b/questions.py index 6a65d0a..bd29b11 100644 --- a/questions.py +++ b/questions.py @@ -1,22 +1,25 @@ # Example: # +# # read everything from question files # pool = QuestionPool() # pool.add_from_files(['file1.yaml', 'file1.yaml']) # +# # generate a new test, creating instances for all questions # test = [] # for q in pool.values(): # test.append(create_question(q)) # +# # experiment answering one question and correct it # test[0]['answer'] = 42 # insert answer # grade = test[0].correct() # correct answer -# Functions: -# create_question(q) -# q - dictionary with question in yaml format -# returns - question instance with the correct class +# QuestionsPool - dictionary of questions not yet instantiated +# +# question_generator - runs external script to get a question dictionary +# create_question - returns question instance with the correct class # An instance of an actual question is a Question object: # @@ -28,12 +31,18 @@ # QuestionTextArea - corrected by an external program # QuestionInformation - not a question, just a box with content -import yaml import random import re import subprocess import os.path import logging +import sys + +try: + import yaml +except ImportError: + print('The package "yaml" is missing. See README.md for instructions.') + sys.exit(1) qlogger = logging.getLogger('Questions') diff --git a/serve.py b/serve.py index be598c4..cbad33d 100755 --- a/serve.py +++ b/serve.py @@ -4,10 +4,23 @@ # The program runs a web server where students login to answer a sequence of questions. # Their grades are automatically calculated and stored in a sqlite3 database. -import cherrypy -from mako.lookup import TemplateLookup -import argparse from os import path +import sys +import argparse +# from threading import Lock + +try: + import cherrypy +except ImportError: + print('The package "cherrypy" is missing. See README.md for instructions.') + sys.exit(1) + +try: + from mako.lookup import TemplateLookup + import djks +except ImportError: + print('The package "mako" is missing. See README.md for instructions.') + sys.exit(1) # path where this file is located SERVER_PATH = path.dirname(path.realpath(__file__)) @@ -30,7 +43,9 @@ class Root(object): self.database = database.Database(testconf['database']) self.auth = AuthController(database=testconf['database']) self.templates = TemplateLookup(directories=[TEMPLATES_DIR], input_encoding='utf-8') - self.tags = {'online': set(), 'finished': set()} # FIXME should be in application, not server + # FIXME should be in application, not server + # FIXME lock and threading + self.tags = {'allowed': set(['0']), 'online': set(), 'finished': set()} # --- DEFAULT ------------------------------------------------------------ # any path, e.g. /xpto/aargh is redirected to the test @@ -89,6 +104,12 @@ class Root(object): # If it's the first time, create instance of the test and register the # time. uid = cherrypy.session.get('userid') + # if uid not in self.tags['allowed']: + # print('not allowed') + # raise cherrypy.HTTPRedirect('/logout') + # return + # print(self.tags) + name = cherrypy.session.get('name') t = cherrypy.session.get('test', None) if t is None: diff --git a/test.py b/test.py index e067838..fd2eed5 100644 --- a/test.py +++ b/test.py @@ -1,10 +1,22 @@ import os, sys, fnmatch import random -import yaml, json import sqlite3 from datetime import datetime +try: + import yaml +except ImportError: + print('The package "yaml" is missing. See README.md for instructions.') + sys.exit(1) + +try: + import json +except ImportError: + print('The package "json" is missing. See README.md for instructions.') + sys.exit(1) + + # my code import questions import database -- libgit2 0.21.2