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,7 +44,8 @@ class QuestionsPool(dict): | ||
| 44 | continue | 44 | continue |
| 45 | 45 | ||
| 46 | if q['ref'] in self: | 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 | # filename and index (number in the file, 0 based) | 50 | # filename and index (number in the file, 0 based) |
| 50 | q['filename'] = filename | 51 | q['filename'] = filename |
| @@ -57,6 +58,9 @@ class QuestionsPool(dict): | @@ -57,6 +58,9 @@ class QuestionsPool(dict): | ||
| 57 | # type (default type is 'information') | 58 | # type (default type is 'information') |
| 58 | q['type'] = str(q.get('type', 'information')) | 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 | # add question to the pool | 64 | # add question to the pool |
| 61 | self[q['ref']] = q | 65 | self[q['ref']] = q |
| 62 | 66 |
templates/test.html
| @@ -143,7 +143,7 @@ | @@ -143,7 +143,7 @@ | ||
| 143 | </div> | 143 | </div> |
| 144 | <div class="panel-body"> | 144 | <div class="panel-body"> |
| 145 | <!-- <div class="well danger drop-shadow"> --> | 145 | <!-- <div class="well danger drop-shadow"> --> |
| 146 | - <h4> ${i+1}.</h4> | 146 | + <h3><small>${i+1}.</small> ${q['title']}</h3> |
| 147 | ${pretty(q['text'])} | 147 | ${pretty(q['text'])} |
| 148 | </div> | 148 | </div> |
| 149 | </div> | 149 | </div> |
| @@ -160,7 +160,7 @@ | @@ -160,7 +160,7 @@ | ||
| 160 | Classificar | 160 | Classificar |
| 161 | </div> | 161 | </div> |
| 162 | <div class="panel-body" id="example${i}"> | 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 | <p class="question"> | 165 | <p class="question"> |
| 166 | ${pretty(q['text'])} | 166 | ${pretty(q['text'])} |
test.py
| @@ -14,14 +14,14 @@ import database | @@ -14,14 +14,14 @@ import database | ||
| 14 | def read_configuration(filename, debug=False, show_points=False, show_hints=False, practice=False, save_answers=False, show_ref=False): | 14 | def read_configuration(filename, debug=False, show_points=False, show_hints=False, practice=False, save_answers=False, show_ref=False): |
| 15 | # FIXME validar se ficheiros e directorios existem??? | 15 | # FIXME validar se ficheiros e directorios existem??? |
| 16 | if not os.path.isfile(filename): | 16 | if not os.path.isfile(filename): |
| 17 | - print('Cannot find file "%s"' % filename) | 17 | + print(' * Cannot find file "%s"' % filename) |
| 18 | sys.exit(1) | 18 | sys.exit(1) |
| 19 | 19 | ||
| 20 | try: | 20 | try: |
| 21 | with open(filename, 'r') as f: | 21 | with open(filename, 'r') as f: |
| 22 | test = yaml.load(f) | 22 | test = yaml.load(f) |
| 23 | except: | 23 | except: |
| 24 | - print('Error reading yaml file "{0}".'.format(filename)) | 24 | + print(' * Error reading yaml file "{0}".'.format(filename)) |
| 25 | raise | 25 | raise |
| 26 | 26 | ||
| 27 | # defaults: | 27 | # defaults: |
| @@ -78,6 +78,11 @@ def read_configuration(filename, debug=False, show_points=False, show_hints=Fals | @@ -78,6 +78,11 @@ def read_configuration(filename, debug=False, show_points=False, show_hints=Fals | ||
| 78 | # instantiated. | 78 | # instantiated. |
| 79 | 79 | ||
| 80 | elif isinstance(q, dict): | 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 | if isinstance(q['ref'], str): | 86 | if isinstance(q['ref'], str): |
| 82 | q['ref'] = [q['ref']] # ref is always a list | 87 | q['ref'] = [q['ref']] # ref is always a list |
| 83 | p = float(q.get('points', 1.0)) # default points is 1.0 | 88 | p = float(q.get('points', 1.0)) # default points is 1.0 |