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
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
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, )
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
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)
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)
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)
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)
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)
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)
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))
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))
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))
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)
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)
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))
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))
def update_dict(self, deck: DeckDict) -> OpChanges: return self.col._backend.update_deck_legacy(json=to_json_bytes(deck))
def set(self, key: str, val: Any) -> None: self.col._backend.set_config_json(key=key, value_json=to_json_bytes(val))