3535#
3636# Supporting functions
3737# ====================
38+
39+
3840def _route_book (is_published = True ):
3941 # Get the base course passed in ``request.args[0]``, or return a 404 if that argument is missing.
4042 base_course = request .args (0 )
@@ -43,18 +45,23 @@ def _route_book(is_published=True):
4345
4446 # See `caching selects <http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Caching-selects>`_.
4547 cache_kwargs = dict (cache = (cache .ram , 3600 ), cacheable = True )
46-
48+ allow_pairs = 'false'
4749 # Find the course to access.
4850 if auth .user :
4951 # Given a logged-in user, use ``auth.user.course_id``.
5052 course = db (db .courses .id == auth .user .course_id ).select (
51- db .courses .course_name , db .courses .base_course , ** cache_kwargs ).first ()
53+ db .courses .course_name ,
54+ db .courses .base_course ,
55+ db .courses .allow_pairs ,
56+ ** cache_kwargs ).first ()
5257
5358 # Ensure the base course in the URL agrees with the base course in ``course``. If not, ask the user to select a course.
5459 if not course or course .base_course != base_course :
5560 session .flash = "{} is not the course your are currently in, switch to or add it to go there" .format (base_course )
5661 redirect (URL (c = 'default' , f = 'courses' ))
5762
63+ allow_pairs = 'true' if course .allow_pairs else 'false'
64+
5865 # Ensure the user has access to this book.
5966 if is_published and not db (
6067 (db .user_courses .user_id == auth .user .id ) &
@@ -87,8 +94,8 @@ def dummy():
8794
8895 # Make this an absolute path.
8996 book_path = safe_join (os .path .join (request .folder , 'books' , base_course ,
90- 'published' if is_published else 'build' , base_course ),
91- * request .args [1 :])
97+ 'published' if is_published else 'build' , base_course ),
98+ * request .args [1 :])
9299 if not book_path :
93100 logger .error ("No Safe Path for {}" .format (request .args [1 :]))
94101 raise HTTP (404 )
@@ -145,9 +152,16 @@ def dummy():
145152
146153 user_is_instructor = 'true' if auth .user and verifyInstructorStatus (auth .user .course_name , auth .user ) else 'false'
147154
148- return dict (course_name = course .course_name , base_course = base_course , is_logged_in = is_logged_in ,
149- user_id = user_id , user_email = email , is_instructor = user_is_instructor , readings = XML (reading_list ),
150- activity_info = json .dumps (div_counts ), subchapter_list = _subchaptoc (base_course , chapter ))
155+ return dict (course_name = course .course_name ,
156+ base_course = base_course ,
157+ is_logged_in = is_logged_in ,
158+ user_id = user_id ,
159+ user_email = email ,
160+ is_instructor = user_is_instructor ,
161+ allow_pairs = allow_pairs ,
162+ readings = XML (reading_list ),
163+ activity_info = json .dumps (div_counts ),
164+ subchapter_list = _subchaptoc (base_course , chapter ))
151165
152166
153167def _subchaptoc (course , chap ):
0 commit comments