Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def update_database(chaptitles, subtitles, skips, app):
"""
When the build is completely finished output the information gathered about
chapters and subchapters into the database.
"""
if not sess:
logger.info("You need to install a DBAPI module - psycopg2 for Postgres")
logger.info("Or perhaps you have not set your DBURL environment variable")
return
chapters = Table("chapters", meta, autoload=True, autoload_with=engine)
sub_chapters = Table("sub_chapters", meta, autoload=True, autoload_with=engine)
questions = Table("questions", meta, autoload=True, autoload_with=engine)
basecourse = app.config.html_context.get("basecourse", "unknown")
dynamic_pages = app.config.html_context.get("dynamic_pages", False)
if dynamic_pages:
cname = basecourse
else:
cname = app.env.config.html_context.get("course_id", "unknown")
logger.info("Cleaning up old chapters info for {}".format(cname))
sess.execute(chapters.delete().where(chapters.c.course_id == basecourse))
logger.info("Populating the database with Chapter information")
chapnum = 1
for chapnum, chap in enumerate(chaptitles, start=1):
:pct_required:
:points:
"""
if not engine:
self.state.document.settings.env.warn(
self.state.document.settings.env.docname,
"Environment variables not set for DB access; can't save usageassignment to DB",
)
return [usageAssignmentNode(self.options)]
# create a configured "Session" class
Session = sessionmaker(bind=engine)
session = Session()
Chapter = Table("chapters", meta, autoload=True, autoload_with=engine)
SubChapter = Table("sub_chapters", meta, autoload=True, autoload_with=engine)
# Problem = Table('problems', meta, autoload=True, autoload_with=engine)
# Questions = Table('questions', meta, autoload=True, autoload_with=engine)
# AssignmentType = Table('assignment_types', meta, autoload=True, autoload_with=engine)
# Section = Table('sections', meta, autoload=True, autoload_with=engine)
course_name = self.state.document.settings.env.config.html_context["course_id"]
self.options["course_name"] = course_name
# course_id = getCourseID(course_name)
# basecourse_name = self.state.document.settings.env.config.html_context.get('basecourse', "unknown")
# Accumulate all the Chapters and SubChapters that are to be visited
# For each chapter, accumulate all subchapters
self.options["chapter_data"] = []
sub_chs = []
if "chapters" in self.options:
try:
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)
:sections:
:pct_required:
:points:
"""
if not engine:
self.state.document.settings.env.warn(
self.state.document.settings.env.docname,
"Environment variables not set for DB access; can't save usageassignment to DB",
)
return [usageAssignmentNode(self.options)]
# create a configured "Session" class
Session = sessionmaker(bind=engine)
session = Session()
Chapter = Table("chapters", meta, autoload=True, autoload_with=engine)
SubChapter = Table("sub_chapters", meta, autoload=True, autoload_with=engine)
# Problem = Table('problems', meta, autoload=True, autoload_with=engine)
# Questions = Table('questions', meta, autoload=True, autoload_with=engine)
# AssignmentType = Table('assignment_types', meta, autoload=True, autoload_with=engine)
# Section = Table('sections', meta, autoload=True, autoload_with=engine)
course_name = self.state.document.settings.env.config.html_context["course_id"]
self.options["course_name"] = course_name
# course_id = getCourseID(course_name)
# basecourse_name = self.state.document.settings.env.config.html_context.get('basecourse', "unknown")
# Accumulate all the Chapters and SubChapters that are to be visited
# For each chapter, accumulate all subchapters
self.options["chapter_data"] = []
sub_chs = []
if "chapters" in self.options:
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)
from runestone.server.componentdb import addQuestionToDB, addHTMLToDB, engine, meta
from runestone.common.runestonedirective import (
RunestoneIdDirective,
RunestoneNode,
add_i18n_js,
add_codemirror_css_and_js,
add_skulpt_js,
)
try:
from html import escape # py3
except ImportError:
from cgi import escape # py2
if engine:
Source_code = Table("source_code", meta, autoload=True, autoload_with=engine)
def setup(app):
app.add_directive("activecode", ActiveCode)
app.add_directive("actex", ActiveExercise)
app.add_role("textfield", textfield_role)
app.add_config_value(
"activecode_div_class",
"runestone explainer ac_section alert alert-warning",
"html",
)
app.add_config_value("activecode_hide_load_history", False, "html")
app.add_autoversioned_stylesheet("activecode.css")
app.add_autoversioned_javascript("jquery.highlight.js")
source = "\n"
self.options["filecontent"] = source
if "hide" in self.options:
self.options["hidden"] = "data-hidden"
else:
self.options["hidden"] = ""
if "edit" in self.options:
self.options["edit"] = "true"
else:
self.options["edit"] = "false"
if engine:
Source_code = Table(
"source_code", meta, autoload=True, autoload_with=engine
)
course_name = env.config.html_context["course_id"]
divid = self.options["divid"]
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
)
)
else:
print(
def update_database(chaptitles, subtitles, skips, app):
"""
When the build is completely finished output the information gathered about
chapters and subchapters into the database.
"""
if not sess:
logger.info("You need to install a DBAPI module - psycopg2 for Postgres")
logger.info("Or perhaps you have not set your DBURL environment variable")
return
chapters = Table("chapters", meta, autoload=True, autoload_with=engine)
sub_chapters = Table("sub_chapters", meta, autoload=True, autoload_with=engine)
questions = Table("questions", meta, autoload=True, autoload_with=engine)
basecourse = app.config.html_context.get("basecourse", "unknown")
dynamic_pages = app.config.html_context.get("dynamic_pages", False)
if dynamic_pages:
cname = basecourse
else:
cname = app.env.config.html_context.get("course_id", "unknown")
logger.info("Cleaning up old chapters info for {}".format(cname))
sess.execute(chapters.delete().where(chapters.c.course_id == basecourse))
logger.info("Populating the database with Chapter information")
chapnum = 1
for chapnum, chap in enumerate(chaptitles, start=1):
# insert row for chapter in the chapter table and get the id