How to use the runestone.server.componentdb.sess.execute function in runestone

To help you get started, we’ve selected a few runestone examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RunestoneInteractive / RunestoneComponents / runestone / chapterdb / dbchapterinfo.py View on Github external
questions.c.question_type == "page",
                        questions.c.base_course == basecourse,
                    ),
                )
            )
            res = sess.execute(sel).first()
            if res and (
                (res.name != q_name) or (res.chapter != chap) or (res.subchapter != sub)
            ):
                # Something changed
                upd = (
                    questions.update()
                    .where(questions.c.id == res["id"])
                    .values(name=q_name, chapter=chap, from_source="T", subchapter=sub)
                )
                sess.execute(upd)
            if not res:
                # this is a new subchapter
                ins = questions.insert().values(
                    chapter=chap,
                    subchapter=sub,
                    question_type="page",
                    from_source="T",
                    name=q_name,
                    timestamp=datetime.datetime.now(),
                    base_course=basecourse,
                )
                sess.execute(ins)
github RunestoneInteractive / RunestoneComponents / runestone / chapterdb / dbchapterinfo.py View on Github external
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
        logger.info(u"Adding chapter subchapter info for {}".format(chap))
        ins = chapters.insert().values(
            chapter_name=chaptitles.get(chap, chap),
            course_id=cname,
            chapter_label=chap,
            chapter_num=chapnum,
        )
        res = sess.execute(ins)
        currentRowId = res.inserted_primary_key[0]
        for subchapnum, sub in enumerate(subtitles[chap], start=1):
github RunestoneInteractive / RunestoneComponents / runestone / chapterdb / dbchapterinfo.py View on Github external
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
        logger.info(u"Adding chapter subchapter info for {}".format(chap))
        ins = chapters.insert().values(
            chapter_name=chaptitles.get(chap, chap),
            course_id=cname,
            chapter_label=chap,
            chapter_num=chapnum,
        )
        res = sess.execute(ins)
        currentRowId = res.inserted_primary_key[0]
        for subchapnum, sub in enumerate(subtitles[chap], start=1):
            if (chap, sub) in skips:
                skipreading = "T"
            else:
                skipreading = "F"
            # insert row for subchapter
            # todo: check if this chapter/subchapter is in the non-reading list
            q_name = u"{}/{}".format(chaptitles.get(chap, chap), subtitles[chap][sub])
            ins = sub_chapters.insert().values(
                sub_chapter_name=subtitles[chap][sub],
                chapter_id=str(currentRowId),
                sub_chapter_label=sub,
                skipreading=skipreading,
                sub_chapter_num=subchapnum,
            )
github RunestoneInteractive / RunestoneComponents / runestone / chapterdb / dbchapterinfo.py View on Github external
sel = select([questions]).where(
                or_(
                    and_(
                        questions.c.chapter == chap,
                        questions.c.subchapter == sub,
                        questions.c.question_type == "page",
                        questions.c.base_course == basecourse,
                    ),
                    and_(
                        questions.c.name == q_name,
                        questions.c.question_type == "page",
                        questions.c.base_course == basecourse,
                    ),
                )
            )
            res = sess.execute(sel).first()
            if res and (
                (res.name != q_name) or (res.chapter != chap) or (res.subchapter != sub)
            ):
                # Something changed
                upd = (
                    questions.update()
                    .where(questions.c.id == res["id"])
                    .values(name=q_name, chapter=chap, from_source="T", subchapter=sub)
                )
                sess.execute(upd)
            if not res:
                # this is a new subchapter
                ins = questions.insert().values(
                    chapter=chap,
                    subchapter=sub,
                    question_type="page",
github RunestoneInteractive / RunestoneComponents / runestone / chapterdb / dbchapterinfo.py View on Github external
.where(questions.c.id == res["id"])
                    .values(name=q_name, chapter=chap, from_source="T", subchapter=sub)
                )
                sess.execute(upd)
            if not res:
                # this is a new subchapter
                ins = questions.insert().values(
                    chapter=chap,
                    subchapter=sub,
                    question_type="page",
                    from_source="T",
                    name=q_name,
                    timestamp=datetime.datetime.now(),
                    base_course=basecourse,
                )
                sess.execute(ins)
github RunestoneInteractive / RunestoneComponents / runestone / chapterdb / dbchapterinfo.py View on Github external
for subchapnum, sub in enumerate(subtitles[chap], start=1):
            if (chap, sub) in skips:
                skipreading = "T"
            else:
                skipreading = "F"
            # insert row for subchapter
            # todo: check if this chapter/subchapter is in the non-reading list
            q_name = u"{}/{}".format(chaptitles.get(chap, chap), subtitles[chap][sub])
            ins = sub_chapters.insert().values(
                sub_chapter_name=subtitles[chap][sub],
                chapter_id=str(currentRowId),
                sub_chapter_label=sub,
                skipreading=skipreading,
                sub_chapter_num=subchapnum,
            )
            sess.execute(ins)
            # Three possibilities:
            # 1) The chapter and subchapter labels match existing, but the q_name doesn't match; because you changed
            # heading in a file.
            # 2) The chapter and subchapter labels don't match (new file name), but there is an existing q_name match,
            # because you renamed the file
            # 3) Neither match, so insert a new question
            sel = select([questions]).where(
                or_(
                    and_(
                        questions.c.chapter == chap,
                        questions.c.subchapter == sub,
                        questions.c.question_type == "page",
                        questions.c.base_course == basecourse,
                    ),
                    and_(
                        questions.c.name == q_name,