Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def addChapterInfoToDB(subChapD, chapTitles, course_id):
if not engine:
print("You need to install a DBAPI module - psycopg2 for Postgres")
return
chapters = Table('chapters', meta, autoload=True, autoload_with=engine)
sub_chapters = Table('sub_chapters', meta, autoload=True, autoload_with=engine)
engine.execute(chapters.delete().where(chapters.c.course_id == course_id))
for chapter in subChapD:
print(chapter)
ins = chapters.insert().values(chapter_name=chapTitles[chapter],
course_id=course_id, chapter_label=chapter)
res = engine.execute(ins)
currentRowId = res.inserted_primary_key[0]
for subchaptername in subChapD[chapter]:
ins = sub_chapters.insert().values(sub_chapter_name=unCamel(subchaptername),
chapter_id=str(currentRowId),
sub_chapter_label=subchaptername)
engine.execute(ins)
if "====" in self.content:
idx = self.content.index("====")
source = "\n".join(self.content[:idx])
suffix = "\n".join(self.content[idx + 1 :])
else:
source = "\n".join(self.content)
suffix = "\n"
else:
source = "\n"
suffix = "\n"
course_name = env.config.html_context["course_id"]
divid = self.options["divid"]
if engine:
engine.execute(
Source_code.delete()
.where(Source_code.c.acid == divid)
.where(Source_code.c.course_id == course_name)
)
engine.execute(
Source_code.insert().values(
acid=divid,
course_id=course_name,
main_code=source,
suffix_code=suffix,
includes=self.options["include"],
available_files=self.options.get("available_files", ""),
)
)
else:
if (
chapters = Table('chapters', meta, autoload=True, autoload_with=engine)
sub_chapters = Table('sub_chapters', meta, autoload=True, autoload_with=engine)
engine.execute(chapters.delete().where(chapters.c.course_id == course_id))
for chapter in subChapD:
print(chapter)
ins = chapters.insert().values(chapter_name=chapTitles[chapter],
course_id=course_id, chapter_label=chapter)
res = engine.execute(ins)
currentRowId = res.inserted_primary_key[0]
for subchaptername in subChapD[chapter]:
ins = sub_chapters.insert().values(sub_chapter_name=unCamel(subchaptername),
chapter_id=str(currentRowId),
sub_chapter_label=subchaptername)
engine.execute(ins)
def addChapterInfoToDB(subChapD, chapTitles, course_id):
if not engine:
print("You need to install a DBAPI module - psycopg2 for Postgres")
return
chapters = Table('chapters', meta, autoload=True, autoload_with=engine)
sub_chapters = Table('sub_chapters', meta, autoload=True, autoload_with=engine)
engine.execute(chapters.delete().where(chapters.c.course_id == course_id))
for chapter in subChapD:
print(chapter)
ins = chapters.insert().values(chapter_name=chapTitles[chapter],
course_id=course_id, chapter_label=chapter)
res = engine.execute(ins)
currentRowId = res.inserted_primary_key[0]
for subchaptername in subChapD[chapter]:
ins = sub_chapters.insert().values(sub_chapter_name=unCamel(subchaptername),
chapter_id=str(currentRowId),
sub_chapter_label=subchaptername)
engine.execute(ins)