From 06833f7301f969184e152e1ca7f7aadfba04027f Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 17 Jan 2020 09:33:33 +1000 Subject: [PATCH] remove unused legacy requirements code --- pylib/anki/models.py | 55 -------------------------------------------- 1 file changed, 55 deletions(-) diff --git a/pylib/anki/models.py b/pylib/anki/models.py index 741d6d922..79a198fa3 100644 --- a/pylib/anki/models.py +++ b/pylib/anki/models.py @@ -559,20 +559,6 @@ select id from notes where mid = ?)""" ########################################################################## def _updateRequired(self, m: NoteType) -> None: - self._updateRequiredNew(m) - - def _updateRequiredLegacy(self, m: NoteType) -> None: - if m["type"] == MODEL_CLOZE: - # nothing to do - return - req = [] - flds = [f["name"] for f in m["flds"]] - for t in m["tmpls"]: - ret = self._reqForTemplate(m, flds, t) - req.append([t["ord"], ret[0], ret[1]]) - m["req"] = req - - def _updateRequiredNew(self, m: NoteType) -> None: fronts = [t["qfmt"] for t in m["tmpls"]] field_map = {} for (idx, fld) in enumerate(m["flds"]): @@ -580,47 +566,6 @@ select id from notes where mid = ?)""" reqs = self.col.backend.template_requirements(fronts, field_map) m["req"] = [list(l) for l in reqs] - def _reqForTemplate( - self, m: NoteType, flds: List[str], t: Template - ) -> Tuple[Union[str, List[int]], ...]: - a = [] - b = [] - for f in flds: - a.append("ankiflag") - b.append("") - - def renderWithFields(fields): - return self.col._renderQA( - (1, 1, m["id"], 1, t["ord"], "", joinFields(fields), 0) # type: ignore - )["q"] - - full = renderWithFields(a) - empty = renderWithFields(b) - # if full and empty are the same, the template is invalid and there is - # no way to satisfy it - if full == empty: - return "none", [], [] - type = "all" - req = [] - for i in range(len(flds)): - tmp = a[:] - tmp[i] = "" - # if no field content appeared, field is required - if "ankiflag" not in renderWithFields(tmp): - req.append(i) - if req: - return type, req - # if there are no required fields, switch to any mode - type = "any" - req = [] - for i in range(len(flds)): - tmp = b[:] - tmp[i] = "1" - # if not the same as empty, this field can make the card non-blank - if renderWithFields(tmp) != empty: - req.append(i) - return type, req - def availOrds(self, m: NoteType, flds: str) -> List: "Given a joined field string, return available template ordinals." if m["type"] == MODEL_CLOZE: