First set of fixes from the pull request This does not include some of the testing files. The textannotation and videoannotation test files are not ready. waiting for an answer on the issue. Deleted token line in api.py and added test for token generator Added notes_spec.coffee remove spec file fixed minor error with the test fixes some quality errors fixed unit test fixed unit test added advanced module Added notes_spec.coffee remove spec file Quality and Testing Coverage 1. in test_textannotation.py I already check for line 75 as it states in the diff in line 43, same with test_videoanntotation 2. Like you said, exceptions cannot be checked for firebase_token_generator.py. The version of python that is active on the edx server is 2.7 or higher, but the code is there for correctness. Error checking works the same way. 3. I added a test for student/views/.py within tests and deleted the unused secret assignment. 4. test_token_generator.py is now its own file Added Secret Token data input fixed token generator Annotation Tools in Place The purpose of this pull request is to install two major modules: (1) a module to annotate text and (2) a module to annotate video. In either case an instructor can declare them in advanced settings under advanced_modules and input content (HTML in text, mp4 or YouTube videos for video). Students will be able to highlight portions and add their comments as well as reply to each other. There needs to be a storage server set up per course as well as a secret token to talk with said storage. Changes: 1. Added test to check for the creation of a token in tests.py (along with the rest of the tests for student/view.py) 2. Removed items in cms pertaining to annotation as this will only be possible in the lms 3. Added more comments to firebase_token_generator.py, the test files, students/views.py 4. Added some internationalization stuff to textannotation.html and videoannotation.html. I need some help with doing it in javascript, but the html is covered. incorporated lib for traslate fixed quality errors fixed my notes with catch token Text and Video Annotation Modules - First Iteration The following code-change is the first iteration of the modules for text and video annotation. Installing Modules: 1. Under “Advanced Settings”, add “textannotation” and “videoannotation” to the list of advanced_modules. 2. Add link to an external storage for annotations under “annotation_storage_url” 3. Add the secret token for talking with said storage under “annotation_token_secret” Using Modules 1. When creating new unit, you can find Text and Video annotation modules under “Advanced” component 2. Make sure you have either Text or Video in one unit, but not both. 3. Annotations are only allowed on Live/Public version and not Studio. Added missing templates and fixed more of the quality errors Fixed annotator not existing issue in cmd and tried to find the get_html() from the annotation module class to the descriptor Added a space after # in comments Fixed issue with an empty Module and token links Added licenses and fixed vis naming scheme and location.
146 lines
4.9 KiB
Python
146 lines
4.9 KiB
Python
"""
|
|
Views for serving static textbooks.
|
|
"""
|
|
|
|
from django.contrib.auth.decorators import login_required
|
|
from django.http import Http404
|
|
from edxmako.shortcuts import render_to_response
|
|
|
|
from courseware.access import has_access
|
|
from courseware.courses import get_course_with_access
|
|
from notes.utils import notes_enabled_for_course
|
|
from static_replace import replace_static_urls
|
|
|
|
|
|
@login_required
|
|
def index(request, course_id, book_index, page=None):
|
|
"""
|
|
Serve static image-based textbooks.
|
|
"""
|
|
course = get_course_with_access(request.user, course_id, 'load')
|
|
staff_access = has_access(request.user, course, 'staff')
|
|
|
|
book_index = int(book_index)
|
|
if book_index < 0 or book_index >= len(course.textbooks):
|
|
raise Http404("Invalid book index value: {0}".format(book_index))
|
|
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 remap_static_url(original_url, course):
|
|
"""Remap a URL in the ways the course requires."""
|
|
# Ick: this should be possible without having to quote and unquote the URL...
|
|
input_url = "'" + original_url + "'"
|
|
output_url = replace_static_urls(
|
|
input_url,
|
|
getattr(course, 'data_dir', None),
|
|
course_id=course.location.course_id,
|
|
)
|
|
# strip off the quotes again...
|
|
return output_url[1:-1]
|
|
|
|
|
|
@login_required
|
|
def pdf_index(request, course_id, book_index, chapter=None, page=None):
|
|
"""
|
|
Display a PDF textbook.
|
|
|
|
course_id: course for which to display text. The course should have
|
|
"pdf_textbooks" property defined.
|
|
|
|
book index: zero-based index of which PDF textbook to display.
|
|
|
|
chapter: (optional) one-based index into the chapter array of textbook PDFs to display.
|
|
Defaults to first chapter. Specifying this assumes that there are separate PDFs for
|
|
each chapter in a textbook.
|
|
|
|
page: (optional) one-based page number to display within the PDF. Defaults to first page.
|
|
"""
|
|
course = get_course_with_access(request.user, course_id, 'load')
|
|
staff_access = has_access(request.user, course, 'staff')
|
|
|
|
book_index = int(book_index)
|
|
if book_index < 0 or book_index >= len(course.pdf_textbooks):
|
|
raise Http404("Invalid book index value: {0}".format(book_index))
|
|
textbook = course.pdf_textbooks[book_index]
|
|
|
|
if 'url' in textbook:
|
|
textbook['url'] = remap_static_url(textbook['url'], course)
|
|
# then remap all the chapter URLs as well, if they are provided.
|
|
if 'chapters' in textbook:
|
|
for entry in textbook['chapters']:
|
|
entry['url'] = remap_static_url(entry['url'], course)
|
|
|
|
return render_to_response(
|
|
'static_pdfbook.html',
|
|
{
|
|
'book_index': book_index,
|
|
'course': course,
|
|
'textbook': textbook,
|
|
'chapter': chapter,
|
|
'page': page,
|
|
'staff_access': staff_access,
|
|
},
|
|
)
|
|
|
|
|
|
@login_required
|
|
def html_index(request, course_id, book_index, chapter=None):
|
|
"""
|
|
Display an HTML textbook.
|
|
|
|
course_id: course for which to display text. The course should have
|
|
"html_textbooks" property defined.
|
|
|
|
book index: zero-based index of which HTML textbook to display.
|
|
|
|
chapter: (optional) one-based index into the chapter array of textbook HTML files to display.
|
|
Defaults to first chapter. Specifying this assumes that there are separate HTML files for
|
|
each chapter in a textbook.
|
|
"""
|
|
course = get_course_with_access(request.user, course_id, 'load')
|
|
staff_access = has_access(request.user, course, 'staff')
|
|
notes_enabled = notes_enabled_for_course(course)
|
|
|
|
book_index = int(book_index)
|
|
if book_index < 0 or book_index >= len(course.html_textbooks):
|
|
raise Http404("Invalid book index value: {0}".format(book_index))
|
|
textbook = course.html_textbooks[book_index]
|
|
|
|
if 'url' in textbook:
|
|
textbook['url'] = remap_static_url(textbook['url'], course)
|
|
# then remap all the chapter URLs as well, if they are provided.
|
|
if 'chapters' in textbook:
|
|
for entry in textbook['chapters']:
|
|
entry['url'] = remap_static_url(entry['url'], course)
|
|
|
|
student = request.user
|
|
return render_to_response(
|
|
'static_htmlbook.html',
|
|
{
|
|
'book_index': book_index,
|
|
'course': course,
|
|
'textbook': textbook,
|
|
'chapter': chapter,
|
|
'student': student,
|
|
'staff_access': staff_access,
|
|
'notes_enabled': notes_enabled,
|
|
},
|
|
)
|