From: W. Trevor King Date: Wed, 6 Feb 2013 14:56:47 +0000 (-0500) Subject: Add --tag option and Question.tags sets for filtering large quizzes X-Git-Tag: v0.1~30 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=e9e9c36c89ec56eb0581a156ddb2fc900f30d3c5;p=quizzer.git Add --tag option and Question.tags sets for filtering large quizzes --- diff --git a/quizzer/cli.py b/quizzer/cli.py index cadc950..4df0b15 100644 --- a/quizzer/cli.py +++ b/quizzer/cli.py @@ -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() diff --git a/quizzer/question.py b/quizzer/question.py index 43e72b6..13dc335 100644 --- a/quizzer/question.py +++ b/quizzer/question.py @@ -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