mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
Merge pull request #383 from agentydragon/all-ref
Move repeated calls to _renderQA into local function
This commit is contained in:
commit
b51cf71d35
1 changed files with 9 additions and 8 deletions
|
@ -516,10 +516,13 @@ select id from notes where mid = ?)""" % " ".join(map),
|
||||||
for f in flds:
|
for f in flds:
|
||||||
a.append("ankiflag")
|
a.append("ankiflag")
|
||||||
b.append("")
|
b.append("")
|
||||||
data = [1, 1, m['id'], 1, t['ord'], "", joinFields(a), 0]
|
|
||||||
full = self.col._renderQA(data)['q']
|
def renderWithFields(fields):
|
||||||
data = [1, 1, m['id'], 1, t['ord'], "", joinFields(b), 0]
|
return self.col._renderQA(
|
||||||
empty = self.col._renderQA(data)['q']
|
(1, 1, m['id'], 1, t['ord'], "", joinFields(fields), 0))['q']
|
||||||
|
|
||||||
|
full = renderWithFields(a)
|
||||||
|
empty = renderWithFields(b)
|
||||||
# if full and empty are the same, the template is invalid and there is
|
# if full and empty are the same, the template is invalid and there is
|
||||||
# no way to satisfy it
|
# no way to satisfy it
|
||||||
if full == empty:
|
if full == empty:
|
||||||
|
@ -529,9 +532,8 @@ select id from notes where mid = ?)""" % " ".join(map),
|
||||||
for i in range(len(flds)):
|
for i in range(len(flds)):
|
||||||
tmp = a[:]
|
tmp = a[:]
|
||||||
tmp[i] = ""
|
tmp[i] = ""
|
||||||
data[6] = joinFields(tmp)
|
|
||||||
# if no field content appeared, field is required
|
# if no field content appeared, field is required
|
||||||
if "ankiflag" not in self.col._renderQA(data)['q']:
|
if "ankiflag" not in renderWithFields(tmp):
|
||||||
req.append(i)
|
req.append(i)
|
||||||
if req:
|
if req:
|
||||||
return type, req
|
return type, req
|
||||||
|
@ -541,9 +543,8 @@ select id from notes where mid = ?)""" % " ".join(map),
|
||||||
for i in range(len(flds)):
|
for i in range(len(flds)):
|
||||||
tmp = b[:]
|
tmp = b[:]
|
||||||
tmp[i] = "1"
|
tmp[i] = "1"
|
||||||
data[6] = joinFields(tmp)
|
|
||||||
# if not the same as empty, this field can make the card non-blank
|
# if not the same as empty, this field can make the card non-blank
|
||||||
if self.col._renderQA(data)['q'] != empty:
|
if renderWithFields(tmp) != empty:
|
||||||
req.append(i)
|
req.append(i)
|
||||||
return type, req
|
return type, req
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue