mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 06:52:21 -04:00
fix empty cloze check
This commit is contained in:
parent
312786c9eb
commit
7c67e292db
3 changed files with 9 additions and 8 deletions
|
@ -497,6 +497,12 @@ where c.nid = n.id and c.id in %s group by nid""" % ids2str(cids)):
|
||||||
html = anki.template.render(format, fields)
|
html = anki.template.render(format, fields)
|
||||||
d[type] = runFilter(
|
d[type] = runFilter(
|
||||||
"mungeQA", html, type, fields, model, data, self)
|
"mungeQA", html, type, fields, model, data, self)
|
||||||
|
# empty cloze?
|
||||||
|
if type == 'q' and model['type'] == MODEL_CLOZE:
|
||||||
|
if not self.models._availClozeOrds(model, data[6], False):
|
||||||
|
d['q'] += ("<p>" + _(
|
||||||
|
"Please edit this note and add some cloze deletions. (%s)") % (
|
||||||
|
"<a href=%s#cloze>%s</a>" % (HELP_SITE, _("help"))))
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def _qaData(self, where=""):
|
def _qaData(self, where=""):
|
||||||
|
|
|
@ -532,7 +532,7 @@ select id from notes where mid = ?)""" % " ".join(map),
|
||||||
avail.append(ord)
|
avail.append(ord)
|
||||||
return avail
|
return avail
|
||||||
|
|
||||||
def _availClozeOrds(self, m, flds):
|
def _availClozeOrds(self, m, flds, allowEmpty=True):
|
||||||
sflds = splitFields(flds)
|
sflds = splitFields(flds)
|
||||||
map = self.fieldMap(m)
|
map = self.fieldMap(m)
|
||||||
ords = set()
|
ords = set()
|
||||||
|
@ -544,7 +544,7 @@ select id from notes where mid = ?)""" % " ".join(map),
|
||||||
"{{c(\d+)::[^}]*?}}", sflds[ord])])
|
"{{c(\d+)::[^}]*?}}", sflds[ord])])
|
||||||
if -1 in ords:
|
if -1 in ords:
|
||||||
ords.remove(-1)
|
ords.remove(-1)
|
||||||
if not ords:
|
if not ords and allowEmpty:
|
||||||
# empty clozes use first ord
|
# empty clozes use first ord
|
||||||
return [0]
|
return [0]
|
||||||
return list(ords)
|
return list(ords)
|
||||||
|
|
|
@ -4,7 +4,6 @@ import collections
|
||||||
from anki.utils import stripHTML
|
from anki.utils import stripHTML
|
||||||
from anki.hooks import runFilter
|
from anki.hooks import runFilter
|
||||||
from anki.template import furigana; furigana.install()
|
from anki.template import furigana; furigana.install()
|
||||||
from anki.consts import HELP_SITE
|
|
||||||
from anki.lang import _
|
from anki.lang import _
|
||||||
|
|
||||||
clozeReg = r"\{\{c%s::(.*?)(::(.*?))?\}\}"
|
clozeReg = r"\{\{c%s::(.*?)(::(.*?))?\}\}"
|
||||||
|
@ -198,11 +197,7 @@ class Template(object):
|
||||||
reg = clozeReg
|
reg = clozeReg
|
||||||
m = re.search(reg%ord, txt)
|
m = re.search(reg%ord, txt)
|
||||||
if not m:
|
if not m:
|
||||||
# cloze doesn't exist; return whole text
|
return ""
|
||||||
return (txt + "<p><font size=2>" + _(
|
|
||||||
"No cloze deletions found; showing whole field. (%s)") % (
|
|
||||||
"<a href=%s#cloze>%s</a>" % (HELP_SITE, _("help"))) +
|
|
||||||
"</font>")
|
|
||||||
# replace chosen cloze with type
|
# replace chosen cloze with type
|
||||||
if type == "q":
|
if type == "q":
|
||||||
if m.group(3):
|
if m.group(3):
|
||||||
|
|
Loading…
Reference in a new issue