def choice_flashcard_template(headings, prompt, answer): deck = FlashcardDeck() # set up headings for heading in headings: new_heading = deck.headings.new_item() new_heading.text = heading deck.headings.array.append(new_heading) # set up a default interaction ci = ChoiceInteraction() ci.prompt = str(prompt) ci.answer = str(answer) deck.interactions.array.append(deck.interactions.new_item()) deck.interactions.array[0].store(ci, False) # create four empty rows (for now, at least) for i in xrange(4): card = Flashcard() for j in xrange(len(headings)): card.sides.array.append(card.sides.new_item()) new_card = deck.cards.new_item() new_card.store(card, False) deck.cards.array.append(new_card) return deck
def legacy_ductmodel_conversion(self): from ductus.modules.flashcards.ductmodels import FlashcardDeck, Flashcard, ChoiceInteraction, Phrase fcd = FlashcardDeck() # set up the choice interaction ci = ChoiceInteraction() ci.prompt = "0" ci.answer = "1" fcd.interactions.array.append(fcd.interactions.new_item()) fcd.interactions.array[0].store(ci, False) # set up each flashcard for group in self.groups: for element in group.get().group: prompt = Phrase() prompt.phrase.text = element.prompt.text answer = Phrase() answer.phrase.text = element.answer.text flashcard = Flashcard() flashcard.sides.array.append(flashcard.sides.new_item()) flashcard.sides.array[0].store(prompt, False) flashcard.sides.array.append(flashcard.sides.new_item()) flashcard.sides.array[1].store(answer, False) new_item = fcd.cards.new_item() new_item.store(flashcard, False) fcd.cards.array.append(new_item) # set up the headings for h in ("prompt", "answer"): new_item = fcd.headings.new_item() new_item.text = h fcd.headings.array.append(new_item) # always, always, always preserve the DuctusCommonElement fcd.common = self.common return fcd