diff --git a/anki/collection.py b/anki/collection.py index 3e42e326e..5bb7b12d9 100644 --- a/anki/collection.py +++ b/anki/collection.py @@ -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'] += ("
" + _( + "Please edit this note and add some cloze deletions. (%s)") % ( + "%s" % (HELP_SITE, _("help")))) return d def _qaData(self, where=""): diff --git a/anki/models.py b/anki/models.py index eefa15699..4f4a99dfb 100644 --- a/anki/models.py +++ b/anki/models.py @@ -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) diff --git a/anki/template/template.py b/anki/template/template.py index 5c33736d3..7456b5a06 100644 --- a/anki/template/template.py +++ b/anki/template/template.py @@ -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 + "
" + _( - "No cloze deletions found; showing whole field. (%s)") % ( - "%s" % (HELP_SITE, _("help"))) + - "") + return "" # replace chosen cloze with type if type == "q": if m.group(3):