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)
|
||||
d[type] = runFilter(
|
||||
"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
|
||||
|
||||
def _qaData(self, where=""):
|
||||
|
|
|
@ -532,7 +532,7 @@ select id from notes where mid = ?)""" % " ".join(map),
|
|||
avail.append(ord)
|
||||
return avail
|
||||
|
||||
def _availClozeOrds(self, m, flds):
|
||||
def _availClozeOrds(self, m, flds, allowEmpty=True):
|
||||
sflds = splitFields(flds)
|
||||
map = self.fieldMap(m)
|
||||
ords = set()
|
||||
|
@ -544,7 +544,7 @@ select id from notes where mid = ?)""" % " ".join(map),
|
|||
"{{c(\d+)::[^}]*?}}", sflds[ord])])
|
||||
if -1 in ords:
|
||||
ords.remove(-1)
|
||||
if not ords:
|
||||
if not ords and allowEmpty:
|
||||
# empty clozes use first ord
|
||||
return [0]
|
||||
return list(ords)
|
||||
|
|
|
@ -4,7 +4,6 @@ import collections
|
|||
from anki.utils import stripHTML
|
||||
from anki.hooks import runFilter
|
||||
from anki.template import furigana; furigana.install()
|
||||
from anki.consts import HELP_SITE
|
||||
from anki.lang import _
|
||||
|
||||
clozeReg = r"\{\{c%s::(.*?)(::(.*?))?\}\}"
|
||||
|
@ -198,11 +197,7 @@ class Template(object):
|
|||
reg = clozeReg
|
||||
m = re.search(reg%ord, txt)
|
||||
if not m:
|
||||
# cloze doesn't exist; return whole text
|
||||
return (txt + "<p><font size=2>" + _(
|
||||
"No cloze deletions found; showing whole field. (%s)") % (
|
||||
"<a href=%s#cloze>%s</a>" % (HELP_SITE, _("help"))) +
|
||||
"</font>")
|
||||
return ""
|
||||
# replace chosen cloze with type
|
||||
if type == "q":
|
||||
if m.group(3):
|
||||
|
|
Loading…
Reference in a new issue