Add --tag option and Question.tags sets for filtering large quizzes
authorW. Trevor King <wking@tremily.us>
Wed, 6 Feb 2013 14:56:47 +0000 (09:56 -0500)
committerW. Trevor King <wking@tremily.us>
Wed, 6 Feb 2013 14:56:47 +0000 (09:56 -0500)
quizzer/cli.py
quizzer/question.py

index cadc950f40452ea2cc9519c7e0995a53d9b7a073..4df0b1565337f927bf62af5d7583d0a1fa4642b0 100644 (file)
@@ -38,6 +38,9 @@ def main():
         '--all', action='store_const', const=True, default=False,
         help=('ask all questions '
               '(not just never-correctly-answered leaf questions)'))
+    parser.add_argument(
+        '-t', '--tag', action='append',
+        help='limit original questions to those matching at least one tag')
     parser.add_argument(
         'quiz', metavar='QUIZ',
         help='path to a quiz file')
@@ -51,9 +54,12 @@ def main():
         answers.load()
     except IOError:
         pass
-    stack = None
+    stack = answers.get_never_correctly_answered(
+        questions=quiz.leaf_questions())
     if args.all:
         stack = [question for question in quiz]
+    if args.tag:
+        stack = [q for q in stack if q.tags.intersection(args.tag)]
     ui = _cli.CommandLineInterface(quiz=quiz, answers=answers, stack=stack)
     ui.run()
     ui.answers.save()
index 43e72b6dd79254365df4d2996410830afd2e2f9e..13dc335ab02c54a14fbef5d49f5821c32f9f3f22 100644 (file)
@@ -38,6 +38,7 @@ class Question (object):
         'multiline',
         'help',
         'dependencies',
+        'tags',
         ]
 
     def __init__(self, **kwargs):
@@ -61,6 +62,10 @@ class Question (object):
             state['multiline'] = False
         if 'dependencies' not in state:
             state['dependencies'] = []
+        if 'tags' not in state:
+            state['tags'] = set()
+        else:
+            state['tags'] = set(state['tags'])
         for attr in self._state_attributes:
             if attr not in state:
                 state[attr] = None