Commit 4070e019 by Arthur Barrett

modified the html static book to only enable annotator.js when notes are enabled for the course

parent 45cca10f
......@@ -2,6 +2,8 @@ from django.contrib.auth.decorators import login_required
from django.http import HttpResponse, Http404
from django.core.exceptions import ValidationError
from notes.models import Note
from notes.utils import notes_enabled_for_course
from courseware.courses import get_course_with_access
import json
import logging
......@@ -34,6 +36,11 @@ def api_request(request, course_id, **kwargs):
Raises a 404 if the resource type doesn't exist, or if there is no action
method associated with the HTTP method.
'''
course = get_course_with_access(request.user, course_id, 'load')
if not notes_enabled_for_course(course):
log.debug('Notes not enabled for course')
raise Http404
resource_map = api_resource_map()
resource_name = kwargs.pop('resource')
resource = resource_map.get(resource_name)
......
# TODO: make a separate policy setting to enable/disable notes.
def notes_enabled_for_course(course):
''' Returns True if notes are enabled for the course, False otherwise. '''
notes_tab_type = 'notes'
return next((True for tab in course.tabs if tab['type'] == notes_tab_type), False)
from django.contrib.auth.decorators import login_required
from django.http import Http404
from mitxmako.shortcuts import render_to_response
from courseware.courses import get_course_with_access
from notes.models import Note
from notes.utils import notes_enabled_for_course
import json
@login_required
def notes(request, course_id):
''' Displays a student's notes in a course. '''
''' Displays the student's notes. '''
course = get_course_with_access(request.user, course_id, 'load')
if not notes_enabled_for_course(course):
raise Http404
notes = Note.objects.filter(course_id=course_id, user=request.user).order_by('-created', 'uri')
json_notes = json.dumps([n.as_dict() for n in notes])
......
......@@ -5,6 +5,7 @@ from mitxmako.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
......@@ -102,6 +103,7 @@ def html_index(request, course_id, book_index, chapter=None):
"""
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):
......@@ -130,4 +132,5 @@ def html_index(request, course_id, book_index, chapter=None):
'course': course,
'textbook': textbook,
'chapter': chapter,
'staff_access': staff_access})
'staff_access': staff_access,
'notes_enabled': notes_enabled})
......@@ -31,11 +31,14 @@
anchorToLoad = options.anchor_id;
}
var onComplete = function(url) {
return function() {
$('#viewerContainer').trigger('notes:init', [url]);
}
};
var onComplete = function() {};
if(options.notesEnabled) {
onComplete = function(url) {
return function() {
$('#viewerContainer').trigger('notes:init', [url]);
}
};
}
loadUrl = function htmlViewLoadUrl(url, anchorId) {
// clear out previous load, if any:
......@@ -102,6 +105,11 @@
options.anchor_id = ${anchor_id};
%endif
options.notesEnabled = false;
%if notes_enabled is not UNDEFINED and notes_enabled:
options.notesEnabled = true;
%endif
$('#outerContainer').myHTMLViewer(options);
});
</script>
......
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