_basename used where possible

This commit is contained in:
Arthur Milchior 2020-04-06 22:20:51 +02:00
parent 69a9425cd0
commit 5315b717c0
3 changed files with 6 additions and 5 deletions

View File

@ -126,7 +126,7 @@ class DeckManager:
# child of an existing deck then it needs to be renamed # child of an existing deck then it needs to be renamed
deck = self.get(did) deck = self.get(did)
if "::" in deck["name"]: if "::" in deck["name"]:
base = self.path(deck["name"])[-1] base = self._basename(deck["name"])
suffix = "" suffix = ""
while True: while True:
# find an unused name # find an unused name
@ -296,8 +296,9 @@ class DeckManager:
_path = path _path = path
def _basename(self, name: str) -> Any: @classmethod
return self.path(name)[-1] def _basename(cls, name: str) -> Any:
return cls.path(name)[-1]
@classmethod @classmethod
def key(cls, deck: Dict[str, Any]) -> List[str]: def key(cls, deck: Dict[str, Any]) -> List[str]:

View File

@ -154,7 +154,7 @@ def fields_for_rendering(
fields["Tags"] = note.stringTags().strip() fields["Tags"] = note.stringTags().strip()
fields["Type"] = card.note_type()["name"] fields["Type"] = card.note_type()["name"]
fields["Deck"] = col.decks.name(card.odid or card.did) fields["Deck"] = col.decks.name(card.odid or card.did)
fields["Subdeck"] = DeckManager.path(fields["Deck"])[-1] fields["Subdeck"] = DeckManager._basename(fields["Deck"])
fields["Card"] = card.template()["name"] fields["Card"] = card.template()["name"]
flag = card.userFlag() flag = card.userFlag()
fields["CardFlag"] = flag and f"flag{flag}" or "" fields["CardFlag"] = flag and f"flag{flag}" or ""

View File

@ -1303,7 +1303,7 @@ QTableView {{ gridline-color: {grid} }}
def addDecks(parent, decks): def addDecks(parent, decks):
for head, did, rev, lrn, new, children in decks: for head, did, rev, lrn, new, children in decks:
name = self.mw.col.decks.get(did)["name"] name = self.mw.col.decks.get(did)["name"]
shortname = DeckManager.path(name)[-1] shortname = DeckManager._basename(name)
if children: if children:
subm = parent.addMenu(shortname) subm = parent.addMenu(shortname)
subm.addItem(_("Filter"), self._filterFunc("deck", name)) subm.addItem(_("Filter"), self._filterFunc("deck", name))