From 8934cf35ba85b50bd9ae5ed246264be6c55955a3 Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Wed, 19 Jun 2013 09:51:05 -0400 Subject: [PATCH] Add pdf_textbooks tab when textbooks are created --- cms/djangoapps/contentstore/views/course.py | 12 +++++++++++- cms/djangoapps/contentstore/views/tabs.py | 5 +++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/cms/djangoapps/contentstore/views/course.py b/cms/djangoapps/contentstore/views/course.py index 4f4aa8c173..d1c2b5d3a4 100644 --- a/cms/djangoapps/contentstore/views/course.py +++ b/cms/djangoapps/contentstore/views/course.py @@ -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, diff --git a/cms/djangoapps/contentstore/views/tabs.py b/cms/djangoapps/contentstore/views/tabs.py index 38a8f35ea1..d18612c41e 100644 --- a/cms/djangoapps/contentstore/views/tabs.py +++ b/cms/djangoapps/contentstore/views/tabs.py @@ -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):