Commit 9b8887c5a7ee01796e9d49a7d8658d784e5cfbb6
1 parent
ec4fbd45
Exists in
master
and in
1 other branch
- added optional title to the questions
- check if questions have a "ref" key in the test configuration
Showing
3 changed files
with
14 additions
and
5 deletions
Show diff stats
questions.py
... | ... | @@ -44,7 +44,8 @@ class QuestionsPool(dict): |
44 | 44 | continue |
45 | 45 | |
46 | 46 | if q['ref'] in self: |
47 | - print(' * question "{0}" in file "{1}" already exists in file "{2}". Ignoring...'.format(q['ref'], filename, self[q['ref']]['filename'])) | |
47 | + print(' * question "{0}" in file "{1}" already exists in file "{2}".'.format(q['ref'], filename, self[q['ref']]['filename'])) | |
48 | + sys.exit(1) | |
48 | 49 | |
49 | 50 | # filename and index (number in the file, 0 based) |
50 | 51 | q['filename'] = filename |
... | ... | @@ -57,6 +58,9 @@ class QuestionsPool(dict): |
57 | 58 | # type (default type is 'information') |
58 | 59 | q['type'] = str(q.get('type', 'information')) |
59 | 60 | |
61 | + # optional title (default empty string) | |
62 | + q['title'] = str(q.get('title', '')) | |
63 | + | |
60 | 64 | # add question to the pool |
61 | 65 | self[q['ref']] = q |
62 | 66 | ... | ... |
templates/test.html
... | ... | @@ -143,7 +143,7 @@ |
143 | 143 | </div> |
144 | 144 | <div class="panel-body"> |
145 | 145 | <!-- <div class="well danger drop-shadow"> --> |
146 | - <h4> ${i+1}.</h4> | |
146 | + <h3><small>${i+1}.</small> ${q['title']}</h3> | |
147 | 147 | ${pretty(q['text'])} |
148 | 148 | </div> |
149 | 149 | </div> |
... | ... | @@ -160,7 +160,7 @@ |
160 | 160 | Classificar |
161 | 161 | </div> |
162 | 162 | <div class="panel-body" id="example${i}"> |
163 | - <h4> ${i+1}. </h4> | |
163 | + <h3> <small>${i+1}.</small> ${q['title']}</h3> | |
164 | 164 | |
165 | 165 | <p class="question"> |
166 | 166 | ${pretty(q['text'])} | ... | ... |
test.py
... | ... | @@ -14,14 +14,14 @@ import database |
14 | 14 | def read_configuration(filename, debug=False, show_points=False, show_hints=False, practice=False, save_answers=False, show_ref=False): |
15 | 15 | # FIXME validar se ficheiros e directorios existem??? |
16 | 16 | if not os.path.isfile(filename): |
17 | - print('Cannot find file "%s"' % filename) | |
17 | + print(' * Cannot find file "%s"' % filename) | |
18 | 18 | sys.exit(1) |
19 | 19 | |
20 | 20 | try: |
21 | 21 | with open(filename, 'r') as f: |
22 | 22 | test = yaml.load(f) |
23 | 23 | except: |
24 | - print('Error reading yaml file "{0}".'.format(filename)) | |
24 | + print(' * Error reading yaml file "{0}".'.format(filename)) | |
25 | 25 | raise |
26 | 26 | |
27 | 27 | # defaults: |
... | ... | @@ -78,6 +78,11 @@ def read_configuration(filename, debug=False, show_points=False, show_hints=Fals |
78 | 78 | # instantiated. |
79 | 79 | |
80 | 80 | elif isinstance(q, dict): |
81 | + if 'ref' not in q: | |
82 | + print(' * Found a question without a "ref" key in the test "{}"'.format(filename)) | |
83 | + print(' Dictionary contents:', q) | |
84 | + sys.exit(1) | |
85 | + | |
81 | 86 | if isinstance(q['ref'], str): |
82 | 87 | q['ref'] = [q['ref']] # ref is always a list |
83 | 88 | p = float(q.get('points', 1.0)) # default points is 1.0 | ... | ... |