Commit 8934cf35 by David Baumgold

Add pdf_textbooks tab when textbooks are created

parent c59d515c
......@@ -437,9 +437,19 @@ def textbook_index(request, org, course, name):
except ValueError:
msg = {"error": "invalid JSON"}
return HttpResponseBadRequest(json.dumps(msg), content_type="application/json")
if not isinstance(obj, (list, tuple)):
msg = {"error": "must be JSON list"}
return HttpResponseBadRequest(json.dumps(msg), content_type="application/json")
for textbook in obj:
if not textbook.get("tab_title"):
msg = {"error": "every textbook must have a tab_title"}
return HttpResponseBadRequest(json.dumps(msg), content_type="application/json")
course_module.pdf_textbooks = obj
if not any(tab['type'] == 'pdf_textbooks' for tab in course_module.tabs):
course_module.tabs.append({"type": "pdf_textbooks"})
store.update_metadata(course_module.location, own_metadata(course_module))
return HttpResponse('', content_type="application/json", status=201)
return HttpResponse('', content_type="application/json", status=204)
else:
upload_asset_callback_url = reverse('upload_asset', kwargs={
'org': org,
......
......@@ -10,7 +10,7 @@ from mitxmako.shortcuts import render_to_response
from xmodule.modulestore import Location
from xmodule.modulestore.inheritance import own_metadata
from xmodule.modulestore.django import modulestore
from ..utils import get_course_for_item
from ..utils import get_course_for_item, get_modulestore
from .access import get_location_and_verify_access
__all__ = ['edit_tabs', 'reorder_static_tabs', 'static_pages', 'edit_static']
......@@ -82,7 +82,8 @@ def reorder_static_tabs(request):
@ensure_csrf_cookie
def edit_tabs(request, org, course, coursename):
location = ['i4x', org, course, 'course', coursename]
course_item = modulestore().get_item(location)
store = get_modulestore(location)
course_item = store.get_item(location)
# check that logged in user has permissions to this item
if not has_access(request.user, location):
......
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