29 lines
920 B
Python
29 lines
920 B
Python
@dataclass
|
|
class QuizTask(Generic[C, V]):
|
|
question: str
|
|
answer: str
|
|
tags: Option[Tags[C, V]]
|
|
generator_metadata: QuizTaskGeneratorMetadata[C, V] = QuizTaskGeneratorMetadata[
|
|
C, V
|
|
].from_values()
|
|
id: uuid.UUID = uuid.uuid4()
|
|
|
|
def __init__(
|
|
self,
|
|
question: str,
|
|
answer: str,
|
|
tags: Optional[Union[Tags[C, V], List[Tuple[C, V]]]] = None,
|
|
):
|
|
self.question = question
|
|
self.answer = answer
|
|
if isinstance(tags, List):
|
|
self.tags = Some(Tags[C, V].from_list(tags))
|
|
else:
|
|
self.tags = Option.maybe(tags)
|
|
|
|
def has_tag(self, category: C, value: V) -> bool:
|
|
return self.tags.map_or(lambda t: t.has_tag(category, value), False)
|
|
|
|
def __str__(self):
|
|
return f"Question:\n{indent(self.question)}\nAnswer:\n{indent(self.answer)}\nTags:\n{indent(self.tags.map_or(lambda t: str(t), "{}"))}"
|