示例#1
0
 def add(self, m: NotetypeDict) -> OpChangesWithId:
     "Replaced with add_dict()"
     self.ensureNameUnique(m)
     out = self.col._backend.add_notetype_legacy(to_json_bytes(m))
     m["id"] = out.id
     self._mutate_after_write(m)
     return out
示例#2
0
 def add(self, notetype: NotetypeDict) -> OpChangesWithId:
     "Replaced with add_dict()"
     self.ensure_name_unique(notetype)
     out = self.col._backend.add_notetype_legacy(to_json_bytes(notetype))
     notetype["id"] = out.id
     self._mutate_after_write(notetype)
     return out
示例#3
0
 def set(self, key: str, val: Any) -> None:
     self.col._backend.set_config_json_no_undo(
         key=key,
         value_json=to_json_bytes(val),
         # this argument is ignored
         undoable=True,
     )
示例#4
0
文件: decks.py 项目: humbatoa/anki
 def update(self, g: Deck, preserve_usn: bool = True) -> None:
     "Add or update an existing deck. Used for syncing and merging."
     try:
         g["id"] = self.col._backend.add_or_update_deck_legacy(
             deck=to_json_bytes(g), preserve_usn_and_mtime=preserve_usn)
     except DeckIsFilteredError as exc:
         raise DeckRenameError("deck was filtered") from exc
示例#5
0
 def update(self, m: NotetypeDict, preserve_usn: bool = True) -> None:
     "Add or update an existing model. Use .update_dict() instead."
     self._remove_from_cache(m["id"])
     self.ensureNameUnique(m)
     m["id"] = self.col._backend.add_or_update_notetype(
         json=to_json_bytes(m), preserve_usn_and_mtime=preserve_usn)
     self.setCurrent(m)
     self._mutate_after_write(m)
示例#6
0
 def _db_command(self, input: Dict[str, Any]) -> Any:
     try:
         return from_json_bytes(self._backend.db_command(to_json_bytes(input)))
     except Exception as e:
         err_bytes = bytes(e.args[0])
     err = pb.BackendError()
     err.ParseFromString(err_bytes)
     raise backend_exception_to_pylib(err)
示例#7
0
 def _db_command(self, input: dict[str, Any]) -> Any:
     bytes_input = to_json_bytes(input)
     try:
         return from_json_bytes(self._backend.db_command(bytes_input))
     except Exception as error:
         err_bytes = bytes(error.args[0])
     err = backend_pb2.BackendError()
     err.ParseFromString(err_bytes)
     raise backend_exception_to_pylib(err)
示例#8
0
文件: template.py 项目: humbatoa/anki
 def _partially_render(self) -> PartiallyRenderedCard:
     if self._template:
         # card layout screen
         out = self._col._backend.render_uncommitted_card(
             note=self._note.to_backend_note(),
             card_ord=self._card.ord,
             template=to_json_bytes(self._template),
             fill_empty=self._fill_empty,
         )
     else:
         # existing card (eg study mode)
         out = self._col._backend.render_existing_card(
             card_id=self._card.id, browser=self._browser)
     return PartiallyRenderedCard.from_proto(out)
示例#9
0
 def update(
     self,
     notetype: NotetypeDict,
     preserve_usn: bool = True,
     skip_checks: bool = False,
 ) -> None:
     "Add or update an existing model. Use .update_dict() instead."
     self._remove_from_cache(notetype["id"])
     self.ensure_name_unique(notetype)
     notetype["id"] = self.col._backend.add_or_update_notetype(
         json=to_json_bytes(notetype),
         preserve_usn_and_mtime=preserve_usn,
         skip_checks=skip_checks,
     )
     self.set_current(notetype)
     self._mutate_after_write(notetype)
示例#10
0
文件: template.py 项目: rye761/anki
 def _partially_render(self) -> PartiallyRenderedCard:
     if self._template:
         # card layout screen
         out = self._col._backend.render_uncommitted_card_legacy(
             note=self._note._to_backend_note(),
             card_ord=self._card.ord,
             template=to_json_bytes(self._template),
             fill_empty=self._fill_empty,
         )
         # when rendering card layout, the css changes have not been
         # committed; we need the current notetype instance instead
         out.css = self._note_type["css"]
     else:
         # existing card (eg study mode)
         out = self._col._backend.render_existing_card(
             card_id=self._card.id, browser=self._browser)
     return PartiallyRenderedCard.from_proto(out)
示例#11
0
 def update_dict(self, notetype: NotetypeDict) -> OpChanges:
     "Update a NotetypeDict. Caller will need to re-load notetype if new fields/cards added."
     self._remove_from_cache(notetype["id"])
     self.ensure_name_unique(notetype)
     return self.col._backend.update_notetype_legacy(
         to_json_bytes(notetype))
示例#12
0
 def add_dict(self, notetype: NotetypeDict) -> OpChangesWithId:
     "Notetype needs to be fetched from DB after adding."
     self.ensure_name_unique(notetype)
     return self.col._backend.add_notetype_legacy(to_json_bytes(notetype))
示例#13
0
 def add_deck_legacy(self, deck: DeckDict) -> OpChangesWithId:
     "Add a deck created with new_deck_legacy(). Must have id of 0."
     if not deck["id"] == 0:
         raise Exception("id should be 0")
     return self.col._backend.add_deck_legacy(to_json_bytes(deck))
示例#14
0
 def update_config(self,
                   conf: DeckConfig,
                   preserve_usn: bool = False) -> None:
     conf["id"] = self.col._backend.add_or_update_deck_config_legacy(
         config=to_json_bytes(conf), preserve_usn_and_mtime=preserve_usn)
示例#15
0
 def update(self, g: Deck, preserve_usn: bool = True) -> None:
     "Add or update an existing deck. Used for syncing and merging."
     g["id"] = self.col._backend.add_or_update_deck_legacy(
         deck=to_json_bytes(g), preserve_usn_and_mtime=preserve_usn)
示例#16
0
文件: decks.py 项目: njhsi/anki
 def add_deck_legacy(self, deck: DeckDict) -> OpChangesWithID:
     "Add a deck created with new_deck_legacy(). Must have id of 0."
     assert deck["id"] == 0
     return self.col._backend.add_deck_legacy(to_json_bytes(deck))
示例#17
0
 def update_config(self,
                   conf: DeckConfigDict,
                   preserve_usn: bool = False) -> None:
     "preserve_usn is ignored"
     conf["id"] = self.col._backend.add_or_update_deck_config_legacy(
         json=to_json_bytes(conf))
示例#18
0
 def update_dict(self, deck: DeckDict) -> OpChanges:
     return self.col._backend.update_deck_legacy(json=to_json_bytes(deck))
示例#19
0
文件: config.py 项目: vi3itor/anki
 def set(self, key: str, val: Any) -> None:
     self.col._backend.set_config_json(key=key,
                                       value_json=to_json_bytes(val))