Add Unit & Nested blocks to breadcrumbs

hide links that has no url

Hide sequence nav in nested pages

Improve doc
This commit is contained in:
Shimul Chowdhury
2020-11-12 18:24:29 +06:00
parent e01c07775c
commit e339cc1b07
2 changed files with 42 additions and 14 deletions

View File

@@ -122,10 +122,36 @@ def container_handler(request, usage_key_string):
component_templates = get_component_templates(course)
ancestor_xblocks = []
parent = get_parent_xblock(xblock)
action = request.GET.get('action', 'view')
is_unit_page = is_unit(xblock)
unit = xblock if is_unit_page else get_parent_xblock(xblock)
unit = xblock if is_unit_page else None
is_first = True
block = xblock
# Build the breadcrumbs and find the ``Unit`` ancestor
# if it is not the immediate parent.
while parent:
if unit is None and is_unit(block):
unit = block
# add all to nav except current xblock page
if xblock != block:
current_block = {
'title': block.display_name_with_default,
'children': parent.get_children(),
'is_last': is_first
}
is_first = False
ancestor_xblocks.append(current_block)
block = parent
parent = get_parent_xblock(parent)
ancestor_xblocks.reverse()
assert unit is not None, "Could not determine unit page"
subsection = get_parent_xblock(unit)
@@ -134,15 +160,6 @@ def container_handler(request, usage_key_string):
section = get_parent_xblock(subsection)
assert section is not None, "Could not determine ancestor section from unit " + six.text_type(unit.location)
# build the breadcrumbs
for block in (section, subsection):
parent = get_parent_xblock(block)
ancestor_xblocks.append({
'title': block.display_name_with_default,
'children': parent.get_children(),
'is_last': block.category == 'sequential'
})
# for the sequence navigator
prev_url, next_url = get_sibling_urls(subsection)
# these are quoted here because they'll end up in a query string on the page,