Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit ca208d1

Browse files
committed
Write datafiles to DB
1 parent 8ca5e31 commit ca208d1

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

runestone/pretext/chapter_pop.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ def manifest_data_to_db(course_name, manifest_path):
9494
logger.debug(subchapter.find("./id").text, subchapter.find("./title").text)
9595
titletext = subchapter.find("./title").text
9696
if not titletext:
97+
# ET.tostring converts the tag and everything to text
98+
# el.text gets the text inside the element
9799
titletext = " ".join(
98100
[
99101
ET.tostring(y).decode("utf8")
@@ -220,19 +222,11 @@ def manifest_data_to_db(course_name, manifest_path):
220222
ins = questions.insert().values(**valudict)
221223
sess.execute(ins)
222224
if qtype == "datafile":
223-
d = el.find("./*pre")
224-
if d is not None:
225-
file_contents = ET.tostring(d).decode("utf8")
225+
if "data-isimage" in el.attrib:
226+
file_contents = el.attrib["src"]
226227
else:
227-
d = el.find("./*textarea")
228-
if d is not None:
229-
file_contents = ET.tostring(d).decode("utf8")
230-
else:
231-
d = el.find("./*img")
232-
if d is not None:
233-
file_contents = d.attrib["src"]
234-
235-
if "data-filename" in el.attrib["data-filename"]:
228+
file_contents = el.text
229+
if "data-filename" in el.attrib:
236230
filename = el.attrib["data-filename"]
237231
else:
238232
filename = el.attrib["id"]
@@ -241,6 +235,7 @@ def manifest_data_to_db(course_name, manifest_path):
241235
res = res = sess.execute(
242236
f"""select * from source_code where acid='{filename}' and course_id='{course_name}'"""
243237
).first()
238+
244239
vdict = dict(
245240
acid=filename, course_id=course_name, main_code=file_contents
246241
)
@@ -256,7 +251,8 @@ def manifest_data_to_db(course_name, manifest_path):
256251
.values(**vdict)
257252
)
258253
else:
259-
ins = source_code.insert().values(**vdict)
254+
upd = source_code.insert().values(**vdict)
255+
sess.execute(upd)
260256

261257
latex = root.find("./latex-macros")
262258
logger.info("Setting attributes for this base course")

0 commit comments

Comments
 (0)