Commit 0d3b566d by Brian Wilson

finish piping URL through to pdf.js

parent f0258b8d
14bab45163f93a24ad55d82faafc3e56bce0a222
\ No newline at end of file
from django.conf import settings
from lxml import etree
# from django.conf import settings
from django.contrib.auth.decorators import login_required
from mitxmako.shortcuts import render_to_response
from courseware.access import has_access
from courseware.courses import get_course_with_access
from lxml import etree
from static_replace import replace_static_urls
@login_required
......@@ -40,6 +42,19 @@ def pdf_index(request, course_id, book_index, chapter=None, page=None):
book_index = int(book_index)
textbook = course.pdf_textbooks[book_index]
def remap_static_url(original_url, course):
input_url = "'" + original_url + "'"
output_url = replace_static_urls(
input_url,
course.metadata['data_dir'],
course_namespace=course.location
)
# strip off the quotes again...
return output_url[1:-1]
textbook['url'] = remap_static_url(textbook['url'], course)
# then remap all the chapter URLs as well, if they are provided.
# if page is None:
# page = textbook.start_page
......
......@@ -9,8 +9,7 @@
<%block name="js_extra">
<!-- Use latest PDF.js build from Github -->
<script type="text/javascript" src="https://raw.github.com/mozilla/pdf.js/gh-pages/build/pdf.js"></script>
<script type="text/javascript" src="/static/js/vendor/pdf.js"></script>
<script type="text/javascript">
//
......@@ -28,7 +27,7 @@
PDFJS.disableWorker = true;
var pdfDoc = null,
pageNum = 1,
pageNum = ${int(page) if page is not None else 1},
scale = 0.8,
canvas = document.getElementById('the-canvas'),
ctx = canvas.getContext('2d');
......@@ -86,8 +85,7 @@
</script>
</%block>
<!-- TODO: what should active_page be set to here???? textbook/0 or pdftextbook/0? -->
<%include file="/courseware/course_navigation.html" args="active_page='textbook/{0}'.format(book_index)" />
<%include file="/courseware/course_navigation.html" args="active_page='pdftextbook/{0}'.format(book_index)" />
<section class="container">
<div class="book-wrapper">
......
......@@ -239,10 +239,11 @@ if settings.COURSEWARE_ENABLED:
url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/]+)/pdfbook/(?P<book_index>[^/]*)/(?P<page>[^/]*)$',
'staticbook.views.pdf_index'),
url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/]+)/pdfbook/(?P<book_index>[^/]*)/chapter/(?P<chapter>[^/]*)/$',
'staticbook.views.pdf_index'),
url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/]+)/pdfbook/(?P<book_index>[^/]*)/chapter/(?P<chapter>[^/]*)/(?P<page>[^/]*)$',
'staticbook.views.pdf_index'),
# Doesn't yet support loading individual chapters...
# url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/]+)/pdfbook/(?P<book_index>[^/]*)/chapter/(?P<chapter>[^/]*)/$',
# 'staticbook.views.pdf_index'),
# url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/]+)/pdfbook/(?P<book_index>[^/]*)/chapter/(?P<chapter>[^/]*)/(?P<page>[^/]*)$',
# 'staticbook.views.pdf_index'),
url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/]+)/courseware/?$',
'courseware.views.index', name="courseware"),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment