Commit 033f5ce7 by Vik Paruchuri

Make process to add open ended tab to studio reversible

parent b8e6c94d
...@@ -210,3 +210,19 @@ def add_open_ended_panel_tab(course): ...@@ -210,3 +210,19 @@ def add_open_ended_panel_tab(course):
course_tabs.append(OPEN_ENDED_PANEL) course_tabs.append(OPEN_ENDED_PANEL)
changed = True changed = True
return changed, course_tabs return changed, course_tabs
def remove_open_ended_panel_tab(course):
"""
Used to remove the open ended panel tab from a course if it exists.
@param course: A course object from the modulestore.
@return: Boolean indicating whether or not a tab was added and a list of tabs for the course.
"""
#Copy course tabs
course_tabs = copy.copy(course.tabs)
changed = False
#Check to see if open ended panel is defined in the course
if OPEN_ENDED_PANEL in course_tabs:
#Add panel to the tabs if it is not defined
course_tabs = [ct for ct in course_tabs if ct!=OPEN_ENDED_PANEL]
changed = True
return changed, course_tabs
...@@ -52,7 +52,8 @@ from auth.authz import is_user_in_course_group_role, get_users_in_course_group_b ...@@ -52,7 +52,8 @@ from auth.authz import is_user_in_course_group_role, get_users_in_course_group_b
from auth.authz import get_user_by_email, add_user_to_course_group, remove_user_from_course_group from auth.authz import get_user_by_email, add_user_to_course_group, remove_user_from_course_group
from auth.authz import INSTRUCTOR_ROLE_NAME, STAFF_ROLE_NAME, create_all_course_groups from auth.authz import INSTRUCTOR_ROLE_NAME, STAFF_ROLE_NAME, create_all_course_groups
from .utils import get_course_location_for_item, get_lms_link_for_item, compute_unit_state, \ from .utils import get_course_location_for_item, get_lms_link_for_item, compute_unit_state, \
get_date_display, UnitState, get_course_for_item, get_url_reverse, add_open_ended_panel_tab get_date_display, UnitState, get_course_for_item, get_url_reverse, add_open_ended_panel_tab, \
remove_open_ended_panel_tab
from xmodule.modulestore.xml_importer import import_from_xml from xmodule.modulestore.xml_importer import import_from_xml
from contentstore.course_info_model import get_course_updates, \ from contentstore.course_info_model import get_course_updates, \
...@@ -1287,13 +1288,14 @@ def course_advanced_updates(request, org, course, name): ...@@ -1287,13 +1288,14 @@ def course_advanced_updates(request, org, course, name):
filter_tabs = True filter_tabs = True
#Check to see if the user instantiated any advanced components. This is a hack to add the open ended panel tab #Check to see if the user instantiated any advanced components. This is a hack to add the open ended panel tab
#to a course automatically if the user has indicated that they want to edit the combinedopenended or peergrading #to a course automatically if the user has indicated that they want to edit the combinedopenended or peergrading
#module. #module, and to remove it if they have removed the open ended elements.
if ADVANCED_COMPONENT_POLICY_KEY in request_body: if ADVANCED_COMPONENT_POLICY_KEY in request_body:
#Check to see if the user instantiated any open ended components #Check to see if the user instantiated any open ended components
found_oe_type = False
#Get the course so that we can scrape current tabs
course_module = modulestore().get_item(location)
for oe_type in OPEN_ENDED_COMPONENT_TYPES: for oe_type in OPEN_ENDED_COMPONENT_TYPES:
if oe_type in request_body[ADVANCED_COMPONENT_POLICY_KEY]: if oe_type in request_body[ADVANCED_COMPONENT_POLICY_KEY]:
#Get the course so that we can scrape current tabs
course_module = modulestore().get_item(location)
#Add an open ended tab to the course if needed #Add an open ended tab to the course if needed
changed, new_tabs = add_open_ended_panel_tab(course_module) changed, new_tabs = add_open_ended_panel_tab(course_module)
#If a tab has been added to the course, then send the metadata along to CourseMetadata.update_from_json #If a tab has been added to the course, then send the metadata along to CourseMetadata.update_from_json
...@@ -1301,7 +1303,18 @@ def course_advanced_updates(request, org, course, name): ...@@ -1301,7 +1303,18 @@ def course_advanced_updates(request, org, course, name):
request_body.update({'tabs': new_tabs}) request_body.update({'tabs': new_tabs})
#Indicate that tabs should not be filtered out of the metadata #Indicate that tabs should not be filtered out of the metadata
filter_tabs = False filter_tabs = False
#Set this flag to avoid the open ended tab removal code below.
found_oe_type = True
break break
#If we did not find an open ended module type in the advanced settings,
# we may need to remove the open ended tab from the course.
if not found_oe_type:
#Remove open ended tab to the course if needed
changed, new_tabs = remove_open_ended_panel_tab(course_module)
if changed:
request_body.update({'tabs': new_tabs})
#Indicate that tabs should not be filtered out of the metadata
filter_tabs = False
response_json = json.dumps(CourseMetadata.update_from_json(location, request_body, filter_tabs=filter_tabs)) response_json = json.dumps(CourseMetadata.update_from_json(location, request_body, filter_tabs=filter_tabs))
return HttpResponse(response_json, mimetype="application/json") return HttpResponse(response_json, mimetype="application/json")
......
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