Browse Source

don't let two questions have the same name

resolves #53
pull/67/head
adam j hartz 1 month ago
parent
commit
f228eb127c
2 changed files with 15 additions and 1 deletions
  1. +2
    -0
      CHANGELOG.md
  2. +13
    -1
      catsoop/language.py

+ 2
- 0
CHANGELOG.md View File

@@ -12,6 +12,8 @@ _Work toward next release. Currently under development._

**FIXED:**

* Show an error message when two questions would have the same name (#53)

**SECURITY:**

**DOCUMENTATION:**


+ 13
- 1
catsoop/language.py View File

@@ -108,6 +108,7 @@ def xml_pre_handle(context):
tmp = text.split("<question")
qcount = 0
o = [tmp[0]]
names_seen = set()
for piece in tmp[1:]:
chunks = piece.strip().split(">", 1)
if len(chunks) != 2:
@@ -138,9 +139,20 @@ def xml_pre_handle(context):
if "csq_name" not in e:
e["csq_name"] = "q%06d" % qcount
qcount += 1
if _valid_qname.match(e["csq_name"]):
if e["csq_name"] in names_seen:
o.append(
(
'<div class="question">'
'<font color="red">'
"ERROR: Duplicate question name <code>%r</code>"
"</font></div>"
)
% e["csq_name"]
)
elif _valid_qname.match(e["csq_name"]):
if type_ != "dummy":
o.append(tutor.question(context, type_, **e))
names_seen.add(e["csq_name"])
else:
o.append(
(


Loading…
Cancel
Save