Catch DeckIsFilteredError directly on frontend

This commit is contained in:
RumovZ 2021-02-26 11:32:40 +01:00
parent ef925a88d6
commit 92cbf168f6
6 changed files with 23 additions and 35 deletions

View file

@ -12,7 +12,7 @@ from typing import Any, Dict, Iterable, List, Optional, Sequence, Tuple, Union
import anki # pylint: disable=unused-import
import anki._backend.backend_pb2 as _pb
from anki.consts import *
from anki.errors import DeckIsFilteredError, DeckRenameError, NotFoundError
from anki.errors import NotFoundError
from anki.utils import from_json_bytes, ids2str, intTime, to_json_bytes
# public exports
@ -246,12 +246,9 @@ class DeckManager:
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
g["id"] = self.col._backend.add_or_update_deck_legacy(
deck=to_json_bytes(g), preserve_usn_and_mtime=preserve_usn
)
def rename(self, g: Deck, newName: str) -> None:
"Rename deck prefix to NAME if not exists. Updates children."

View file

@ -9,7 +9,7 @@ from typing import Any
import aqt
from anki.decks import DeckTreeNode
from anki.errors import DeckRenameError
from anki.errors import DeckIsFilteredError
from anki.utils import intTime
from aqt import AnkiQt, gui_hooks
from aqt.qt import *
@ -21,8 +21,8 @@ from aqt.utils import (
getOnlyText,
openLink,
shortcut,
show_rename_deck_error,
showInfo,
showWarning,
tr,
)
@ -268,8 +268,8 @@ class DeckBrowser:
try:
self.mw.col.decks.rename(deck, newName)
gui_hooks.sidebar_should_refresh_decks()
except DeckRenameError as err:
show_rename_deck_error(err)
except DeckIsFilteredError as err:
showWarning(str(err))
return
self.show()
@ -353,8 +353,8 @@ class DeckBrowser:
if deck:
try:
self.mw.col.decks.id(deck)
except DeckRenameError as err:
show_rename_deck_error(err)
except DeckIsFilteredError as err:
showWarning(str(err))
return
gui_hooks.sidebar_should_refresh_decks()
self.refresh()

View file

@ -4,8 +4,8 @@ from typing import Callable, List, Optional
import aqt
from anki.collection import SearchNode
from anki.decks import Deck, DeckRenameError
from anki.errors import InvalidInput
from anki.decks import Deck
from anki.errors import DeckIsFilteredError, InvalidInput
from anki.lang import without_unicode_isolation
from aqt import AnkiQt, colors, gui_hooks
from aqt.qt import *
@ -19,7 +19,6 @@ from aqt.utils import (
restoreGeom,
saveGeom,
show_invalid_search_error,
show_rename_deck_error,
showWarning,
tr,
)
@ -244,8 +243,8 @@ class DeckConf(QDialog):
self.saveConf()
except InvalidInput as err:
show_invalid_search_error(err)
except DeckRenameError as err:
show_rename_deck_error(err)
except DeckIsFilteredError as err:
showWarning(str(err))
else:
if not self.mw.col.sched.rebuild_filtered_deck(self.deck["id"]):
if askUser(tr(TR.DECKS_THE_PROVIDED_SEARCH_DID_NOT_MATCH)):

View file

@ -10,7 +10,7 @@ from typing import Any, Dict, Iterable, List, Optional, Sequence, Tuple, cast
import aqt
from anki.collection import Config, SearchNode
from anki.decks import DeckTreeNode
from anki.errors import DeckRenameError, InvalidInput
from anki.errors import DeckIsFilteredError, InvalidInput
from anki.tags import TagTreeNode
from anki.types import assert_exhaustive
from aqt import colors, gui_hooks
@ -23,8 +23,8 @@ from aqt.utils import (
askUser,
getOnlyText,
show_invalid_search_error,
show_rename_deck_error,
showInfo,
showWarning,
tr,
)
@ -993,8 +993,8 @@ class SidebarTreeView(QTreeView):
self.mw.checkpoint(tr(TR.ACTIONS_RENAME_DECK))
try:
self.mw.col.decks.rename(deck, new_name)
except DeckRenameError as err:
show_rename_deck_error(err)
except DeckIsFilteredError as err:
showWarning(str(err))
return
self.refresh()
self.mw.deckBrowser.refresh()

View file

@ -4,7 +4,7 @@
from typing import List, Optional
import aqt
from anki.decks import DeckRenameError
from anki.errors import DeckIsFilteredError
from aqt import gui_hooks
from aqt.qt import *
from aqt.utils import (
@ -17,8 +17,8 @@ from aqt.utils import (
restoreGeom,
saveGeom,
shortcut,
show_rename_deck_error,
showInfo,
showWarning,
tr,
)
@ -168,8 +168,8 @@ class StudyDeck(QDialog):
if n:
try:
did = self.mw.col.decks.id(n)
except DeckRenameError as err:
show_rename_deck_error(err)
except DeckIsFilteredError as err:
showWarning(str(err))
return
# deck name may not be the same as user input. ex: ", ::
self.name = self.mw.col.decks.name(did)

View file

@ -36,7 +36,7 @@ from PyQt5.QtWidgets import (
import anki
import aqt
from anki import Collection
from anki.errors import DeckRenameError, InvalidInput
from anki.errors import InvalidInput
from anki.lang import TR # pylint: disable=unused-import
from anki.utils import invalidFilename, isMac, isWin, noBundledLibs, versionWithBuild
from aqt.qt import *
@ -146,14 +146,6 @@ def show_invalid_search_error(err: Exception) -> None:
showWarning(text)
def show_rename_deck_error(err: DeckRenameError) -> None:
if err.description == "deck was filtered":
reason = tr(TR.ERRORS_REASON_FILTERED_PARENT)
else:
reason = "unknown reason."
showWarning(tr(TR.ERRORS_INVALID_DECK_NAME, reason=reason))
def showInfo(
text: str,
parent: Union[Literal[False], QDialog] = False,