From ee3f963919ced283384b839fe954e7388ef4a88a Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 30 Dec 2019 18:50:00 +1000 Subject: [PATCH] remove ':' from field names --- anki/models.py | 2 ++ aqt/clayout.py | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/anki/models.py b/anki/models.py index 035e3ae7d..9674e1131 100644 --- a/anki/models.py +++ b/anki/models.py @@ -338,6 +338,8 @@ and notes.mid = ? and cards.ord = ?""", def renameField(self, m: NoteType, field: Field, newName: Optional[str]) -> None: self.col.modSchema(check=True) + if newName is not None: + newName = newName.replace(":", "") pat = r"{{([^{}]*)([:#^/]|[^:#/^}][^:}]*?:|)%s}}" def wrap(txt): diff --git a/aqt/clayout.py b/aqt/clayout.py index 04e32c820..44e1709c4 100644 --- a/aqt/clayout.py +++ b/aqt/clayout.py @@ -49,6 +49,7 @@ class CardLayout(QDialog): self.emptyFields.append(name) note[name] = "(%s)" % name note.flush() + self.removeColons() self.setupTopArea() self.setupMainArea() self.setupButtons() @@ -242,6 +243,12 @@ Please create a new card type first.""" ) self.redraw() + def removeColons(self): + # colons in field names conflict with the template language + for fld in self.model["flds"]: + if ":" in fld["name"]: + self.mm.renameField(self.model, fld, fld["name"]) + # Buttons ##########################################################################