def visit(node, depth=1): """ Recursive generator function which yields CCX schedule nodes. We convert dates to string to get them ready for use by the js date widgets, which use text inputs. Visits students visible nodes only; nodes children of hidden ones are skipped as well. Dates: Only start date is applicable to a section. If ccx coach did not override start date then getting it from the master course. Both start and due dates are applicable to a subsection (aka sequential). If ccx coach did not override these dates then getting these dates from corresponding subsection in master course. Unit inherits start date and due date from its subsection. If ccx coach did not override these dates then getting them from corresponding subsection in master course. """ for child in node.get_children(): # in case the children are visible to staff only, skip them if child.visible_to_staff_only: continue hidden = get_override_for_ccx(ccx, child, 'visible_to_staff_only', child.visible_to_staff_only) start = get_date(ccx, child, 'start') if depth > 1: # Subsection has both start and due dates and unit inherit dates from their subsections if depth == 2: due = get_date(ccx, child, 'due') elif depth == 3: # Get start and due date of subsection in case unit has not override dates. due = get_date(ccx, child, 'due', node) start = get_date(ccx, child, 'start', node) visited = { 'location': str(child.location), 'display_name': child.display_name, 'category': child.category, 'start': start, 'due': due, 'hidden': hidden, } else: visited = { 'location': str(child.location), 'display_name': child.display_name, 'category': child.category, 'start': start, 'hidden': hidden, } if depth < 3: children = tuple(visit(child, depth + 1)) if children: visited['children'] = children yield visited elif return_xblocks and depth == 3: visited['children'] = child.children yield visited else: yield visited
def visit(node, depth=1): """ Recursive generator function which yields CCX schedule nodes. We convert dates to string to get them ready for use by the js date widgets, which use text inputs. Visits students visible nodes only; nodes children of hidden ones are skipped as well. Dates: Only start date is applicable to a section. If ccx coach did not override start date then getting it from the master course. Both start and due dates are applicable to a subsection (aka sequential). If ccx coach did not override these dates then getting these dates from corresponding subsection in master course. Unit inherits start date and due date from its subsection. If ccx coach did not override these dates then getting them from corresponding subsection in master course. """ for child in node.get_children(): # in case the children are visible to staff only, skip them if child.visible_to_staff_only: continue hidden = get_override_for_ccx( ccx, child, 'visible_to_staff_only', child.visible_to_staff_only) start = get_date(ccx, child, 'start') if depth > 1: # Subsection has both start and due dates and unit inherit dates from their subsections if depth == 2: due = get_date(ccx, child, 'due') elif depth == 3: # Get start and due date of subsection in case unit has not override dates. due = get_date(ccx, child, 'due', node) start = get_date(ccx, child, 'start', node) visited = { 'location': str(child.location), 'display_name': child.display_name, 'category': child.category, 'start': start, 'due': due, 'hidden': hidden, } else: visited = { 'location': str(child.location), 'display_name': child.display_name, 'category': child.category, 'start': start, 'hidden': hidden, } if depth < 3: children = tuple(visit(child, depth + 1)) if children: visited['children'] = children yield visited else: yield visited