From 9d52196949681ab77c0580ece2a99d116c5c5cee Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 22 Mar 2011 14:24:57 +0900 Subject: [PATCH] add a bgclass helper func --- anki/cards.py | 4 ++++ anki/models.py | 2 +- tests/test_cards.py | 12 ++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/anki/cards.py b/anki/cards.py index aec2929c5..7741f3f3c 100644 --- a/anki/cards.py +++ b/anki/cards.py @@ -132,6 +132,10 @@ streak=?, lapses=?, grade=?, cycles=?, edue=? where id = ?""", def template(self): return self._reviewData()[1].templates[self.ord] + def bgClass(self): + return "cm%s-%s" % (hexifyID(self.model().id), + hexifyID(self.template()['ord'])) + def startTimer(self): self.timerStarted = time.time() diff --git a/anki/models.py b/anki/models.py index d9181fa03..13ae59e9b 100644 --- a/anki/models.py +++ b/anki/models.py @@ -107,7 +107,7 @@ insert or replace into models values (?, ?, ?, ?, ?, ?, ?)""", return "" # fields css = "".join([self._fieldCSS( - ".fm%s.%s" % (hexifyID(self.id), hexifyID(f['ord'])), + ".fm%s-%s" % (hexifyID(self.id), hexifyID(f['ord'])), (f['font'], f['qsize'], f['qcol'], f['rtl'], f['pre'])) for f in self.fields]) # templates diff --git a/tests/test_cards.py b/tests/test_cards.py index 9827c41c6..5034d875a 100644 --- a/tests/test_cards.py +++ b/tests/test_cards.py @@ -85,3 +85,15 @@ def test_delete(): assert deck.factCount() == 0 assert deck.db.scalar("select count() from facts") == 0 assert deck.db.scalar("select count() from cards") == 0 + +def test_misc(): + d = getEmptyDeck() + f = d.newFact() + f['Front'] = u'1' + f['Back'] = u'2' + d.addFact(f) + c = f.cards()[0] + assert c.bgClass() == "cm1-0" + assert c.fact().id == 1 + assert c.model().id == 1 + assert c.template()['ord'] == 0