Пример #1
0
 def __init__(
     self,
     col: anki.collection.Collection,
     id: CardId | None = None,
     backend_card: BackendCard | None = None,
 ) -> None:
     self.col = col.weakref()
     self.timer_started: float | None = None
     self._render_output: anki.template.TemplateRenderOutput | None = None
     if id:
         # existing card
         self.id = id
         self.load()
     elif backend_card:
         self._load_from_backend_card(backend_card)
     else:
         # new card with defaults
         self._load_from_backend_card(cards_pb2.Card())
Пример #2
0
 def _to_backend_card(self) -> cards_pb2.Card:
     # mtime & usn are set by backend
     return cards_pb2.Card(
         id=self.id,
         note_id=self.nid,
         deck_id=self.did,
         template_idx=self.ord,
         ctype=self.type,
         queue=self.queue,
         due=self.due,
         interval=self.ivl,
         ease_factor=self.factor,
         reps=self.reps,
         lapses=self.lapses,
         remaining_steps=self.left,
         original_due=self.odue,
         original_deck_id=self.odid,
         flags=self.flags,
         data=self.data,
     )
Пример #3
0
 def _to_backend_card(self) -> cards_pb2.Card:
     # mtime & usn are set by backend
     return cards_pb2.Card(
         id=self.id,
         note_id=self.nid,
         deck_id=self.did,
         template_idx=self.ord,
         ctype=self.type,
         queue=self.queue,
         due=self.due,
         interval=self.ivl,
         ease_factor=self.factor,
         reps=self.reps,
         lapses=self.lapses,
         remaining_steps=self.left,
         original_due=self.odue,
         original_deck_id=self.odid,
         flags=self.flags,
         original_position=generic_pb2.UInt32(val=self.original_position)
         if self.original_position is not None else None,
     )