def set_due_date_extension(course, unit, student, due_date): """ Sets a due date extension. Raises DashboardError if the unit or extended due date is invalid. """ if due_date: # Check that the new due date is valid: with disable_overrides(): original_due_date = getattr(unit, 'due', None) if not original_due_date: raise DashboardError( _("Unit {0} has no due date to extend.").format(unit.location)) if due_date < original_due_date: raise DashboardError( _("An extended due date must be later than the original due date." )) override_field_for_user(student, unit, 'due', due_date) else: # We are deleting a due date extension. Check that it exists: if not get_override_for_user(student, unit, 'due'): raise DashboardError( _("No due date extension is set for that student and unit.")) clear_override_for_user(student, unit, 'due')
def get_ccx_schedule(course, ccx): """ Generate a JSON serializable CCX schedule. """ 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. """ for child in node.get_children(): # in case the children are visible to staff only, skip them if child.visible_to_staff_only: continue start = get_override_for_ccx(ccx, child, 'start', None) if start: start = str(start)[:-9] due = get_override_for_ccx(ccx, child, 'due', None) if due: due = str(due)[:-9] hidden = get_override_for_ccx( ccx, child, 'visible_to_staff_only', child.visible_to_staff_only) visited = { 'location': str(child.location), 'display_name': child.display_name, 'category': child.category, 'start': start, 'due': due, 'hidden': hidden, } if depth < 3: children = tuple(visit(child, depth + 1)) if children: visited['children'] = children yield visited else: yield visited with disable_overrides(): return tuple(visit(course))
def set_due_date_extension(course, unit, student, due_date): """ Sets a due date extension. Raises DashboardError if the unit or extended due date is invalid. """ if due_date: # Check that the new due date is valid: with disable_overrides(): original_due_date = getattr(unit, 'due', None) if not original_due_date: raise DashboardError(_("Unit {0} has no due date to extend.").format(unit.location)) if due_date < original_due_date: raise DashboardError(_("An extended due date must be later than the original due date.")) override_field_for_user(student, unit, 'due', due_date) else: # We are deleting a due date extension. Check that it exists: if not get_override_for_user(student, unit, 'due'): raise DashboardError(_("No due date extension is set for that student and unit.")) clear_override_for_user(student, unit, 'due')
def get_ccx_schedule(course, ccx): """ Generate a JSON serializable CCX schedule. """ 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. """ for child in node.get_children(): start = get_override_for_ccx(ccx, child, "start", None) if start: start = str(start)[:-9] due = get_override_for_ccx(ccx, child, "due", None) if due: due = str(due)[:-9] hidden = get_override_for_ccx(ccx, child, "visible_to_staff_only", child.visible_to_staff_only) visited = { "location": str(child.location), "display_name": child.display_name, "category": child.category, "start": start, "due": due, "hidden": hidden, } if depth < 3: children = tuple(visit(child, depth + 1)) if children: visited["children"] = children yield visited else: yield visited with disable_overrides(): return tuple(visit(course))
def get_ccx_schedule(course, ccx): """ Generate a JSON serializable CCX schedule. """ 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 with disable_overrides(): return tuple(visit(course))
def get_ccx_schedule(course, ccx): """ Generate a JSON serializable CCX schedule. """ 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 with disable_overrides(): return tuple(visit(course))