Dynamically find the start and end pages of a textbook instead of hardcoding to 6.002 values

This commit is contained in:
David Ormsbee
2012-09-19 17:12:08 -04:00
parent 10a838cb01
commit f9a49ece6f
3 changed files with 17 additions and 4 deletions

View File

@@ -7,7 +7,7 @@ from courseware.courses import get_course_with_access
from lxml import etree
@login_required
def index(request, course_id, book_index, page=0):
def index(request, course_id, book_index, page=None):
course = get_course_with_access(request.user, course_id, 'load')
staff_access = has_access(request.user, course, 'staff')
@@ -15,10 +15,15 @@ def index(request, course_id, book_index, page=0):
textbook = course.textbooks[book_index]
table_of_contents = textbook.table_of_contents
if page is None:
page = textbook.start_page
return render_to_response('staticbook.html',
{'book_index': book_index, 'page': int(page),
'course': course, 'book_url': textbook.book_url,
'table_of_contents': table_of_contents,
'start_page' : textbook.start_page,
'end_page' : textbook.end_page,
'staff_access': staff_access})
def index_shifted(request, course_id, page):

View File

@@ -38,14 +38,14 @@ function goto_page(n) {
function prev_page() {
var newpage=page-1;
if(newpage<0) newpage=0;
if(newpage< ${start_page}) newpage=${start_page};
goto_page(newpage);
log_event("book", {"type":"prevpage","new":page});
}
function next_page() {
var newpage=page+1;
if(newpage>1008) newpage=1008;
if(newpage> ${end_page}) newpage=${end_page};
goto_page(newpage);
log_event("book", {"type":"nextpage","new":page});
}