diff --git a/pylib/anki/decks.py b/pylib/anki/decks.py index a62fb83cd..f76f1cb56 100644 --- a/pylib/anki/decks.py +++ b/pylib/anki/decks.py @@ -126,7 +126,7 @@ class DeckManager: # child of an existing deck then it needs to be renamed deck = self.get(did) if "::" in deck["name"]: - base = self._basename(deck["name"]) + base = self.basename(deck["name"]) suffix = "" while True: # find an unused name @@ -261,14 +261,14 @@ class DeckManager: if ontoDeckDid is None or ontoDeckDid == "": if len(self.path(draggedDeckName)) > 1: - self.rename(draggedDeck, self._basename(draggedDeckName)) + self.rename(draggedDeck, self.basename(draggedDeckName)) elif self._canDragAndDrop(draggedDeckName, ontoDeckName): draggedDeck = self.get(draggedDeckDid) draggedDeckName = draggedDeck["name"] ontoDeckName = self.get(ontoDeckDid)["name"] assert ontoDeckName.strip() self.rename( - draggedDeck, ontoDeckName + "::" + self._basename(draggedDeckName) + draggedDeck, ontoDeckName + "::" + self.basename(draggedDeckName) ) def _canDragAndDrop(self, draggedDeckName: str, ontoDeckName: str) -> bool: @@ -283,7 +283,7 @@ class DeckManager: def _isParent(self, parentDeckName: str, childDeckName: str) -> Any: return self.path(childDeckName) == self.path(parentDeckName) + [ - self._basename(childDeckName) + self.basename(childDeckName) ] def _isAncestor(self, ancestorDeckName: str, descendantDeckName: str) -> Any: @@ -297,9 +297,11 @@ class DeckManager: _path = path @classmethod - def _basename(cls, name: str) -> Any: + def basename(cls, name: str) -> Any: return cls.path(name)[-1] + _basename = basename + @classmethod def key(cls, deck: Dict[str, Any]) -> List[str]: return cls.path(deck["name"]) diff --git a/pylib/anki/template.py b/pylib/anki/template.py index d98a1c2f8..5b14d33f0 100644 --- a/pylib/anki/template.py +++ b/pylib/anki/template.py @@ -154,7 +154,7 @@ def fields_for_rendering( fields["Tags"] = note.stringTags().strip() fields["Type"] = card.note_type()["name"] fields["Deck"] = col.decks.name(card.odid or card.did) - fields["Subdeck"] = DeckManager._basename(fields["Deck"]) + fields["Subdeck"] = DeckManager.basename(fields["Deck"]) fields["Card"] = card.template()["name"] flag = card.userFlag() fields["CardFlag"] = flag and f"flag{flag}" or "" diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index 80b414c25..b107e2a08 100644 --- a/qt/aqt/browser.py +++ b/qt/aqt/browser.py @@ -1303,7 +1303,7 @@ QTableView {{ gridline-color: {grid} }} def addDecks(parent, decks): for head, did, rev, lrn, new, children in decks: name = self.mw.col.decks.get(did)["name"] - shortname = DeckManager._basename(name) + shortname = DeckManager.basename(name) if children: subm = parent.addMenu(shortname) subm.addItem(_("Filter"), self._filterFunc("deck", name))