Skip to content
This repository has been archived by the owner on Jun 30, 2024. It is now read-only.

Commit

Permalink
Merge branch 'subchaptoc'
Browse files Browse the repository at this point in the history
  • Loading branch information
Brad Miller committed Jul 3, 2019
2 parents 19d04a3 + d5bf006 commit dec1d59
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion controllers/ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ def getCompletionStatus():
db.user_sub_chapter_progress.insert(user_id=auth.user.id,
chapter_id = lastPageChapter,
sub_chapter_id = lastPageSubchapter,
status = -1)
status = -1, start_date=datetime.datetime.utcnow())
# the chapter might exist without the subchapter
result = db((db.user_chapter_progress.user_id == auth.user.id) & (db.user_chapter_progress.chapter_id == lastPageChapter)).select()
if not result:
Expand Down
24 changes: 22 additions & 2 deletions controllers/books.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ def _route_book(is_published=True, is_open=False):
if not os.path.isfile(book_path):
raise HTTP(404)
response.view = book_path
chapter = os.path.split(os.path.split(book_path)[0])[1]
subchapter = os.path.basename(os.path.splitext(book_path)[0])

div_counts = {}
if auth.user:
user_id = auth.user.username
email = auth.user.email
Expand Down Expand Up @@ -121,13 +122,32 @@ def _route_book(is_published=True, is_open=False):

return dict(course_name=course.course_name, base_course=base_course, is_logged_in=is_logged_in,
user_id=user_id, user_email=email, is_instructor=user_is_instructor, readings=reading_list,
activity_info=json.dumps(div_counts))
activity_info=json.dumps(div_counts), subchapter_list=_subchaptoc(base_course, chapter))


# This is copied verbatim from https://github.com/pallets/werkzeug/blob/master/werkzeug/security.py#L30.
_os_alt_seps = list(sep for sep in [os.path.sep, os.path.altsep]
if sep not in (None, '/'))

def _subchaptoc(course, chap):
res = db( (db.chapters.id == db.sub_chapters.chapter_id) &
(db.chapters.course_id == course ) &
(db.chapters.chapter_label == chap) ).select(db.chapters.chapter_num,
db.sub_chapters.sub_chapter_num,
db.chapters.chapter_label,
db.sub_chapters.sub_chapter_label,
db.sub_chapters.sub_chapter_name, orderby=db.sub_chapters.sub_chapter_num,
cache=(cache.ram, 3600), cacheable=True)
toclist = []
for row in res:
sc_url = "{}.html".format(row.sub_chapters.sub_chapter_label)
title = "{}.{} {}".format(row.chapters.chapter_num,
row.sub_chapters.sub_chapter_num,
row.sub_chapters.sub_chapter_name)
toclist.append(dict(subchap_uri=sc_url, title=title))

return toclist


# This is copied verbatim from https://github.com/pallets/werkzeug/blob/master/werkzeug/security.py#L216.
def safe_join(directory, *pathnames):
Expand Down
2 changes: 1 addition & 1 deletion models/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
table_migrate_prefix_test = table_migrate_prefix
else:
# WEB2PY_MIGRATE is either "Yes", "No", "Fake", or missing
db = DAL(settings.database_uri, fake_migrate_all=(os.environ.get("WEB2PY_MIGRATE", "Yes") == 'Fake'),
db = DAL(settings.database_uri, pool_size=30, fake_migrate_all=(os.environ.get("WEB2PY_MIGRATE", "Yes") == 'Fake'),
migrate=False, migrate_enabled=(os.environ.get("WEB2PY_MIGRATE", "Yes") in ['Yes', 'Fake']))
session.connect(request, response, db, masterapp=None, migrate=table_migrate_prefix + 'web2py_sessions.table')

Expand Down

0 comments on commit dec1d59

Please sign in to comment.