def getCard(self) -> Optional[Card]: """Fetch the next card from the queue. None if finished.""" response = self.get_queued_cards() if isinstance(response, QueuedCards): backend_card = response.cards[0].card card = Card(self.col) card._load_from_backend_card(backend_card) card.startTimer() return card else: return None
def getCard(self) -> Optional[Card]: """Fetch the next card from the queue. None if finished.""" try: queued_card = self.get_queued_cards().cards[0] except IndexError: return None card = Card(self.col) card._load_from_backend_card(queued_card.card) card.start_timer() return card
def prepare(html, card, context: str): if settings.enabled is False: return html if card.note_type()['name'] != settings.note_type: return html if mw is None: return html sched = copy.copy(mw.col.sched) for attr, value in vars(sched).items(): try: setattr(sched, attr, copy.deepcopy(value)) except Exception: pass next_card = None if sched.version == 3: sched_v3 = sched # type: Any cards = sched_v3.get_queued_cards(fetch_limit=2) if len(cards.cards) > 1: queued_card = cards.cards[1] if queued_card is not None: next_card = Card(sched.col) next_card._load_from_backend_card(queued_card.card) next_card.load() else: next_card = sched.getCard() if next_card is not None and settings.question_field is not None: try: next_term = next_card.note()[ settings.question_field] # type: Optional[str] except KeyError: next_term = next_card.note().values()[0] else: next_term = None next_id = None if next_card: next_id = next_card.note().id if context.startswith("clayout"): # in card layout preview we don't have current note, but we can use next_term current_term = "malli" if next_term is None else next_term current_id = next_id if next_id is not None else -1 else: current_id = card.note().id try: current_term = card.note()[settings.question_field] except KeyError: current_term = card.note().values()[0] card_types = { 0: "Forwards", 1: "Reversed", } app_dict = { 'context': context, 'isAnki': True, 'currentTerm': current_term, 'cardType': card_types.get(card.ord, "Unknown"), 'tags': card.note().tags, 'id': current_id, 'nextTerm': next_term, 'nextId': next_id, } return f""" <script> window.myAnkiSetup = {dumps(app_dict)}; if (window.myAnkiUpdate) window.myAnkiUpdate(window.myAnkiSetup); </script>""" + html