mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
Handle note without cards in browser (#1929)
Change the IndexError to a NotFoundError which is picked up by the table model.
This commit is contained in:
parent
8478492190
commit
dd0e56afb3
1 changed files with 4 additions and 1 deletions
|
@ -8,6 +8,7 @@ from typing import Sequence, cast
|
||||||
from anki.browser import BrowserConfig
|
from anki.browser import BrowserConfig
|
||||||
from anki.cards import Card, CardId
|
from anki.cards import Card, CardId
|
||||||
from anki.collection import Collection
|
from anki.collection import Collection
|
||||||
|
from anki.errors import NotFoundError
|
||||||
from anki.notes import Note, NoteId
|
from anki.notes import Note, NoteId
|
||||||
from anki.utils import ids2str
|
from anki.utils import ids2str
|
||||||
from aqt.browser.table import Column, ItemId, ItemList
|
from aqt.browser.table import Column, ItemId, ItemList
|
||||||
|
@ -191,7 +192,9 @@ class NoteState(ItemState):
|
||||||
self.col.set_browser_note_columns(self._active_columns)
|
self.col.set_browser_note_columns(self._active_columns)
|
||||||
|
|
||||||
def get_card(self, item: ItemId) -> Card:
|
def get_card(self, item: ItemId) -> Card:
|
||||||
return self.get_note(item).cards()[0]
|
if cards := self.get_note(item).cards():
|
||||||
|
return cards[0]
|
||||||
|
raise NotFoundError
|
||||||
|
|
||||||
def get_note(self, item: ItemId) -> Note:
|
def get_note(self, item: ItemId) -> Note:
|
||||||
return self.col.get_note(NoteId(item))
|
return self.col.get_note(NoteId(item))
|
||||||
|
|
Loading…
Reference in a new issue