Exemplo n.º 1
0
def get_course_assignment_date_blocks(course,
                                      user,
                                      request,
                                      num_return=None,
                                      include_past_dates=False,
                                      include_access=False):
    """
    Returns a list of assignment (at the subsection/sequential level) due date
    blocks for the given course. Will return num_return results or all results
    if num_return is None in date increasing order.
    """
    date_blocks = []
    for assignment in get_course_assignments(course.id,
                                             user,
                                             request,
                                             include_access=include_access):
        date_block = CourseAssignmentDate(course, user)
        date_block.date = assignment.date
        date_block.requires_full_access = assignment.requires_full_access
        date_block.set_title(assignment.title, link=assignment.url)
        date_blocks.append(date_block)
    date_blocks = sorted(
        (b for b in date_blocks if b.is_enabled or include_past_dates),
        key=date_block_key_fn)
    if num_return:
        return date_blocks[:num_return]
    return date_blocks
Exemplo n.º 2
0
def get_course_assignment_due_dates(course,
                                    user,
                                    request,
                                    num_return=None,
                                    include_past_dates=False,
                                    include_access=False):
    """
    Returns a list of assignment (at the subsection/sequential level) due date
    blocks for the given course. Will return num_return results or all results
    if num_return is None in date increasing order.
    """
    store = modulestore()
    all_course_dates = get_dates_for_course(course.id, user)
    date_blocks = []
    for (block_key, date_type), date in all_course_dates.items():
        if date_type == 'due' and block_key.block_type == 'sequential':
            try:
                item = store.get_item(block_key)
            except ItemNotFoundError:
                continue
            if item.graded:
                date_block = CourseAssignmentDate(course, user)
                date_block.date = date

                if include_access:
                    date_block.requires_full_access = _requires_full_access(
                        store, user, block_key)

                block_url = None
                now = datetime.now().replace(tzinfo=pytz.UTC)
                assignment_released = item.start < now if item.start else None
                if assignment_released:
                    block_url = reverse('jump_to', args=[course.id, block_key])
                    block_url = request.build_absolute_uri(
                        block_url) if request else None
                assignment_title = item.display_name if item.display_name else _(
                    'Assignment')
                date_block.set_title(assignment_title, link=block_url)

                date_blocks.append(date_block)
    date_blocks = sorted(
        (b for b in date_blocks if b.is_enabled or include_past_dates),
        key=date_block_key_fn)
    if num_return:
        return date_blocks[:num_return]
    return date_blocks