Commit 46cd9b0a by John Eskew

Add bulk_operations wrapper around all course-query-intensive Studio views.

parent 2f060733
...@@ -141,74 +141,75 @@ def container_handler(request, usage_key_string): ...@@ -141,74 +141,75 @@ def container_handler(request, usage_key_string):
if 'text/html' in request.META.get('HTTP_ACCEPT', 'text/html'): if 'text/html' in request.META.get('HTTP_ACCEPT', 'text/html'):
usage_key = UsageKey.from_string(usage_key_string) usage_key = UsageKey.from_string(usage_key_string)
try: with modulestore().bulk_operations(usage_key.course_key):
course, xblock, lms_link = _get_item_in_course(request, usage_key) try:
except ItemNotFoundError: course, xblock, lms_link = _get_item_in_course(request, usage_key)
return HttpResponseBadRequest() except ItemNotFoundError:
return HttpResponseBadRequest()
component_templates = get_component_templates(course)
ancestor_xblocks = [] component_templates = get_component_templates(course)
parent = get_parent_xblock(xblock) ancestor_xblocks = []
action = request.REQUEST.get('action', 'view') parent = get_parent_xblock(xblock)
action = request.REQUEST.get('action', 'view')
is_unit_page = is_unit(xblock)
unit = xblock if is_unit_page else None is_unit_page = is_unit(xblock)
unit = xblock if is_unit_page else None
while parent and parent.category != 'course':
if unit is None and is_unit(parent): while parent and parent.category != 'course':
unit = parent if unit is None and is_unit(parent):
ancestor_xblocks.append(parent) unit = parent
parent = get_parent_xblock(parent) ancestor_xblocks.append(parent)
ancestor_xblocks.reverse() parent = get_parent_xblock(parent)
ancestor_xblocks.reverse()
assert unit is not None, "Could not determine unit page"
subsection = get_parent_xblock(unit) assert unit is not None, "Could not determine unit page"
assert subsection is not None, "Could not determine parent subsection from unit " + unicode(unit.location) subsection = get_parent_xblock(unit)
section = get_parent_xblock(subsection) assert subsection is not None, "Could not determine parent subsection from unit " + unicode(unit.location)
assert section is not None, "Could not determine ancestor section from unit " + unicode(unit.location) section = get_parent_xblock(subsection)
assert section is not None, "Could not determine ancestor section from unit " + unicode(unit.location)
# Fetch the XBlock info for use by the container page. Note that it includes information
# about the block's ancestors and siblings for use by the Unit Outline. # Fetch the XBlock info for use by the container page. Note that it includes information
xblock_info = create_xblock_info(xblock, include_ancestor_info=is_unit_page) # about the block's ancestors and siblings for use by the Unit Outline.
xblock_info = create_xblock_info(xblock, include_ancestor_info=is_unit_page)
# Create the link for preview.
preview_lms_base = settings.FEATURES.get('PREVIEW_LMS_BASE') # Create the link for preview.
# need to figure out where this item is in the list of children as the preview_lms_base = settings.FEATURES.get('PREVIEW_LMS_BASE')
# preview will need this # need to figure out where this item is in the list of children as the
index = 1 # preview will need this
for child in subsection.get_children(): index = 1
if child.location == unit.location: for child in subsection.get_children():
break if child.location == unit.location:
index += 1 break
preview_lms_link = ( index += 1
u'//{preview_lms_base}/courses/{org}/{course}/{course_name}/courseware/{section}/{subsection}/{index}' preview_lms_link = (
).format( u'//{preview_lms_base}/courses/{org}/{course}/{course_name}/courseware/{section}/{subsection}/{index}'
preview_lms_base=preview_lms_base, ).format(
lms_base=settings.LMS_BASE, preview_lms_base=preview_lms_base,
org=course.location.org, lms_base=settings.LMS_BASE,
course=course.location.course, org=course.location.org,
course_name=course.location.name, course=course.location.course,
section=section.location.name, course_name=course.location.name,
subsection=subsection.location.name, section=section.location.name,
index=index subsection=subsection.location.name,
) index=index
)
return render_to_response('container.html', {
'context_course': course, # Needed only for display of menus at top of page. return render_to_response('container.html', {
'action': action, 'context_course': course, # Needed only for display of menus at top of page.
'xblock': xblock, 'action': action,
'xblock_locator': xblock.location, 'xblock': xblock,
'unit': unit, 'xblock_locator': xblock.location,
'is_unit_page': is_unit_page, 'unit': unit,
'subsection': subsection, 'is_unit_page': is_unit_page,
'section': section, 'subsection': subsection,
'new_unit_category': 'vertical', 'section': section,
'ancestor_xblocks': ancestor_xblocks, 'new_unit_category': 'vertical',
'component_templates': json.dumps(component_templates), 'ancestor_xblocks': ancestor_xblocks,
'xblock_info': xblock_info, 'component_templates': json.dumps(component_templates),
'draft_preview_link': preview_lms_link, 'xblock_info': xblock_info,
'published_preview_link': lms_link, 'draft_preview_link': preview_lms_link,
}) 'published_preview_link': lms_link,
})
else: else:
return HttpResponseBadRequest("Only supports HTML requests") return HttpResponseBadRequest("Only supports HTML requests")
......
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