def id(self, name: str, create: bool = True, type: Optional[Dict[str, Any]] = None) -> Optional[int]: "Add a deck with NAME. Reuse deck if already exists. Return id as int." if type is None: type = defaultDeck name = name.replace('"', "") name = unicodedata.normalize("NFC", name) deck = self.byName(name) if deck: return int(deck["id"]) if not create: return None g = copy.deepcopy(type) if "::" in name: # not top level; ensure all parents exist name = self._ensureParents(name) g["name"] = name while 1: id = intTime(1000) if str(id) not in self.decks: break g["id"] = id self.decks[str(id)] = g self.save(g) self.maybeAddToActive() hooks.deck_added(g) return int(id)
def id(self, name: str, create: bool = True, type: int = 0,) -> Optional[int]: "Add a deck with NAME. Reuse deck if already exists. Return id as int." id = self.id_for_name(name) if id: return id elif not create: return None deck = self.new_deck_legacy(bool(type)) deck["name"] = name self.update(deck, preserve_usn=False) hooks.deck_added(deck) return deck["id"]