From 9b8887c5a7ee01796e9d49a7d8658d784e5cfbb6 Mon Sep 17 00:00:00 2001 From: Miguel Barão Date: Sat, 27 Jun 2015 16:25:27 +0100 Subject: [PATCH] - added optional title to the questions - check if questions have a "ref" key in the test configuration --- questions.py | 6 +++++- templates/test.html | 4 ++-- test.py | 9 +++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/questions.py b/questions.py index 5b4f8e6..d3addfe 100644 --- a/questions.py +++ b/questions.py @@ -44,7 +44,8 @@ class QuestionsPool(dict): continue if q['ref'] in self: - print(' * question "{0}" in file "{1}" already exists in file "{2}". Ignoring...'.format(q['ref'], filename, self[q['ref']]['filename'])) + print(' * question "{0}" in file "{1}" already exists in file "{2}".'.format(q['ref'], filename, self[q['ref']]['filename'])) + sys.exit(1) # filename and index (number in the file, 0 based) q['filename'] = filename @@ -57,6 +58,9 @@ class QuestionsPool(dict): # type (default type is 'information') q['type'] = str(q.get('type', 'information')) + # optional title (default empty string) + q['title'] = str(q.get('title', '')) + # add question to the pool self[q['ref']] = q diff --git a/templates/test.html b/templates/test.html index aae8038..b2460a9 100644 --- a/templates/test.html +++ b/templates/test.html @@ -143,7 +143,7 @@
-

${i+1}.

+

${i+1}. ${q['title']}

${pretty(q['text'])}
@@ -160,7 +160,7 @@  Classificar
-

${i+1}.

+

${i+1}. ${q['title']}

${pretty(q['text'])} diff --git a/test.py b/test.py index 15d69c7..81955ef 100644 --- a/test.py +++ b/test.py @@ -14,14 +14,14 @@ import database def read_configuration(filename, debug=False, show_points=False, show_hints=False, practice=False, save_answers=False, show_ref=False): # FIXME validar se ficheiros e directorios existem??? if not os.path.isfile(filename): - print('Cannot find file "%s"' % filename) + print(' * Cannot find file "%s"' % filename) sys.exit(1) try: with open(filename, 'r') as f: test = yaml.load(f) except: - print('Error reading yaml file "{0}".'.format(filename)) + print(' * Error reading yaml file "{0}".'.format(filename)) raise # defaults: @@ -78,6 +78,11 @@ def read_configuration(filename, debug=False, show_points=False, show_hints=Fals # instantiated. elif isinstance(q, dict): + if 'ref' not in q: + print(' * Found a question without a "ref" key in the test "{}"'.format(filename)) + print(' Dictionary contents:', q) + sys.exit(1) + if isinstance(q['ref'], str): q['ref'] = [q['ref']] # ref is always a list p = float(q.get('points', 1.0)) # default points is 1.0 -- libgit2 0.21.2