mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
fix availOrds() when conditional expressions have extra text
This commit is contained in:
parent
cb24e106e6
commit
bc2112a127
2 changed files with 30 additions and 4 deletions
|
@ -464,7 +464,7 @@ select id from notes where mid = ?)""" % " ".join(map),
|
|||
a = []
|
||||
b = []
|
||||
for f in flds:
|
||||
a.append("1")
|
||||
a.append("ankiflag")
|
||||
b.append("")
|
||||
data = [1, 1, m['id'], 1, t['ord'], "", joinFields(a)]
|
||||
full = self.col._renderQA(data)['q']
|
||||
|
@ -480,8 +480,8 @@ select id from notes where mid = ?)""" % " ".join(map),
|
|||
tmp = a[:]
|
||||
tmp[i] = ""
|
||||
data[6] = joinFields(tmp)
|
||||
# if the result is same as empty, field is required
|
||||
if self.col._renderQA(data)['q'] == empty:
|
||||
# if no field content appeared, field is required
|
||||
if "ankiflag" not in self.col._renderQA(data)['q']:
|
||||
req.append(i)
|
||||
if req:
|
||||
return type, req
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# coding: utf-8
|
||||
|
||||
from tests.shared import getEmptyDeck, assertException
|
||||
from anki.utils import stripHTML
|
||||
from anki.utils import stripHTML, joinFields
|
||||
|
||||
def test_modelDelete():
|
||||
deck = getEmptyDeck()
|
||||
|
@ -230,3 +230,29 @@ def test_modelChange():
|
|||
f.load()
|
||||
assert f['Text'] == "f2"
|
||||
assert len(f.cards()) == 2
|
||||
|
||||
def test_availOrds():
|
||||
d = getEmptyDeck()
|
||||
m = d.models.current(); mm = d.models
|
||||
t = m['tmpls'][0]
|
||||
f = d.newNote()
|
||||
f['Front'] = "1"
|
||||
# simple templates
|
||||
assert mm.availOrds(m, joinFields(f.fields)) == [0]
|
||||
t['qfmt'] = "{{Back}}"
|
||||
mm.save(m, templates=True)
|
||||
assert not mm.availOrds(m, joinFields(f.fields))
|
||||
# AND
|
||||
t['qfmt'] = "{{#Front}}{{#Back}}{{Front}}{{/Back}}{{/Front}}"
|
||||
mm.save(m, templates=True)
|
||||
assert not mm.availOrds(m, joinFields(f.fields))
|
||||
t['qfmt'] = "{{#Front}}\n{{#Back}}\n{{Front}}\n{{/Back}}\n{{/Front}}"
|
||||
mm.save(m, templates=True)
|
||||
assert not mm.availOrds(m, joinFields(f.fields))
|
||||
# OR
|
||||
t['qfmt'] = "{{Front}}\n{{Back}}"
|
||||
mm.save(m, templates=True)
|
||||
assert mm.availOrds(m, joinFields(f.fields)) == [0]
|
||||
t['Front'] = ""
|
||||
t['Back'] = "1"
|
||||
assert mm.availOrds(m, joinFields(f.fields)) == [0]
|
||||
|
|
Loading…
Reference in a new issue