replace _path by path (because it's not private here)
This commit is contained in:
parent
266c2022b5
commit
69a9425cd0
@ -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._path(deck["name"])[-1]
|
||||
base = self.path(deck["name"])[-1]
|
||||
suffix = ""
|
||||
while True:
|
||||
# find an unused name
|
||||
@ -260,7 +260,7 @@ class DeckManager:
|
||||
ontoDeckName = self.get(ontoDeckDid)["name"]
|
||||
|
||||
if ontoDeckDid is None or ontoDeckDid == "":
|
||||
if len(self._path(draggedDeckName)) > 1:
|
||||
if len(self.path(draggedDeckName)) > 1:
|
||||
self.rename(draggedDeck, self._basename(draggedDeckName))
|
||||
elif self._canDragAndDrop(draggedDeckName, ontoDeckName):
|
||||
draggedDeck = self.get(draggedDeckDid)
|
||||
@ -282,29 +282,31 @@ class DeckManager:
|
||||
return True
|
||||
|
||||
def _isParent(self, parentDeckName: str, childDeckName: str) -> Any:
|
||||
return self._path(childDeckName) == self._path(parentDeckName) + [
|
||||
return self.path(childDeckName) == self.path(parentDeckName) + [
|
||||
self._basename(childDeckName)
|
||||
]
|
||||
|
||||
def _isAncestor(self, ancestorDeckName: str, descendantDeckName: str) -> Any:
|
||||
ancestorPath = self._path(ancestorDeckName)
|
||||
return ancestorPath == self._path(descendantDeckName)[0 : len(ancestorPath)]
|
||||
ancestorPath = self.path(ancestorDeckName)
|
||||
return ancestorPath == self.path(descendantDeckName)[0 : len(ancestorPath)]
|
||||
|
||||
@staticmethod
|
||||
def _path(name: str) -> Any:
|
||||
def path(name: str) -> Any:
|
||||
return name.split("::")
|
||||
|
||||
_path = path
|
||||
|
||||
def _basename(self, name: str) -> Any:
|
||||
return self._path(name)[-1]
|
||||
return self.path(name)[-1]
|
||||
|
||||
@classmethod
|
||||
def key(cls, deck: Dict[str, Any]) -> List[str]:
|
||||
return cls._path(deck["name"])
|
||||
return cls.path(deck["name"])
|
||||
|
||||
def _ensureParents(self, name: str) -> Any:
|
||||
"Ensure parents exist, and return name with case matching parents."
|
||||
s = ""
|
||||
path = self._path(name)
|
||||
path = self.path(name)
|
||||
if len(path) < 2:
|
||||
return name
|
||||
for p in path[:-1]:
|
||||
@ -469,14 +471,14 @@ class DeckManager:
|
||||
self.save(deck)
|
||||
|
||||
# ensure no sections are blank
|
||||
if not all(self._path(deck["name"])):
|
||||
if not all(self.path(deck["name"])):
|
||||
self.col.log("fix deck with missing sections", deck["name"])
|
||||
deck["name"] = "recovered%d" % intTime(1000)
|
||||
self.save(deck)
|
||||
|
||||
# immediate parent must exist
|
||||
if "::" in deck["name"]:
|
||||
immediateParent = "::".join(self._path(deck["name"])[:-1])
|
||||
immediateParent = "::".join(self.path(deck["name"])[:-1])
|
||||
if immediateParent not in names:
|
||||
self.col.log("fix deck with missing parent", deck["name"])
|
||||
self._ensureParents(deck["name"])
|
||||
@ -579,7 +581,7 @@ class DeckManager:
|
||||
childMap[deck["id"]] = node
|
||||
|
||||
# add note to immediate parent
|
||||
parts = self._path(deck["name"])
|
||||
parts = self.path(deck["name"])
|
||||
if len(parts) > 1:
|
||||
immediateParent = "::".join(parts[:-1])
|
||||
pid = nameMap[immediateParent]["id"]
|
||||
@ -591,7 +593,7 @@ class DeckManager:
|
||||
"All parents of did."
|
||||
# get parent and grandparent names
|
||||
parents: List[str] = []
|
||||
for part in self._path(self.get(did)["name"])[:-1]:
|
||||
for part in self.path(self.get(did)["name"])[:-1]:
|
||||
if not parents:
|
||||
parents.append(part)
|
||||
else:
|
||||
@ -609,7 +611,7 @@ class DeckManager:
|
||||
"All existing parents of name"
|
||||
if "::" not in name:
|
||||
return []
|
||||
names = self._path(name)[:-1]
|
||||
names = self.path(name)[:-1]
|
||||
head = []
|
||||
parents = []
|
||||
|
||||
|
@ -258,13 +258,13 @@ class Anki2Importer(Importer):
|
||||
name = g["name"]
|
||||
# if there's a prefix, replace the top level deck
|
||||
if self.deckPrefix:
|
||||
tmpname = "::".join(DeckManager._path(name)[1:])
|
||||
tmpname = "::".join(DeckManager.path(name)[1:])
|
||||
name = self.deckPrefix
|
||||
if tmpname:
|
||||
name += "::" + tmpname
|
||||
# manually create any parents so we can pull in descriptions
|
||||
head = ""
|
||||
for parent in DeckManager._path(name)[:-1]:
|
||||
for parent in DeckManager.path(name)[:-1]:
|
||||
if head:
|
||||
head += "::"
|
||||
head += parent
|
||||
|
@ -154,7 +154,7 @@ class Scheduler(V2):
|
||||
data = []
|
||||
|
||||
def parent(name):
|
||||
parts = DeckManager._path(name)
|
||||
parts = DeckManager.path(name)
|
||||
if len(parts) < 2:
|
||||
return None
|
||||
parts = parts[:-1]
|
||||
|
@ -241,7 +241,7 @@ order by due"""
|
||||
data = []
|
||||
|
||||
def parent(name):
|
||||
parts = DeckManager._path(name)
|
||||
parts = DeckManager.path(name)
|
||||
if len(parts) < 2:
|
||||
return None
|
||||
parts = parts[:-1]
|
||||
@ -280,7 +280,7 @@ order by due"""
|
||||
def _groupChildren(self, grps: List[List[Any]]) -> Any:
|
||||
# first, split the group names into components
|
||||
for g in grps:
|
||||
g[0] = DeckManager._path(g[0])
|
||||
g[0] = DeckManager.path(g[0])
|
||||
# and sort based on those components
|
||||
grps.sort(key=itemgetter(0))
|
||||
# then run main function
|
||||
|
@ -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._path(fields["Deck"])[-1]
|
||||
fields["Subdeck"] = DeckManager.path(fields["Deck"])[-1]
|
||||
fields["Card"] = card.template()["name"]
|
||||
flag = card.userFlag()
|
||||
fields["CardFlag"] = flag and f"flag{flag}" or ""
|
||||
|
@ -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._path(name)[-1]
|
||||
shortname = DeckManager.path(name)[-1]
|
||||
if children:
|
||||
subm = parent.addMenu(shortname)
|
||||
subm.addItem(_("Filter"), self._filterFunc("deck", name))
|
||||
|
Loading…
Reference in New Issue
Block a user