Skip to content
Snippets Groups Projects
Commit 03846e22 authored by Carla Duarte's avatar Carla Duarte
Browse files

AA-545: Include has_scheduled_content in StartDateTransformer

parent 278e66e3
Branches
Tags release-2021-01-05-15.23
No related merge requests found
......@@ -72,6 +72,7 @@ def get_blocks(
if requested_fields is None:
requested_fields = []
include_completion = 'completion' in requested_fields
include_has_scheduled_content = 'has_scheduled_content' in requested_fields
include_special_exams = 'special_exam_info' in requested_fields
include_gated_sections = 'show_gated_sections' in requested_fields
......@@ -106,7 +107,12 @@ def get_blocks(
# transform
blocks = course_blocks_api.get_course_blocks(
user, usage_key, transformers, allow_start_dates_in_future=allow_start_dates_in_future)
user,
usage_key,
transformers,
allow_start_dates_in_future=allow_start_dates_in_future,
include_has_scheduled_content=include_has_scheduled_content
)
# filter blocks by types
if block_types_filter:
......
......@@ -52,6 +52,7 @@ SUPPORTED_FIELDS = [
SupportedFieldType('due'),
SupportedFieldType('contains_gated_content'),
SupportedFieldType('has_score'),
SupportedFieldType('has_scheduled_content'),
SupportedFieldType('weight'),
SupportedFieldType('show_correctness'),
# 'student_view_data'
......
......@@ -61,6 +61,7 @@ def get_course_blocks(
collected_block_structure=None,
allow_start_dates_in_future=False,
include_completion=False,
include_has_scheduled_content=False,
):
"""
A higher order function implemented on top of the
......@@ -96,7 +97,12 @@ def get_course_blocks(
transformers = BlockStructureTransformers(get_course_block_access_transformers(user))
if include_completion:
transformers += [BlockCompletionTransformer()]
transformers.usage_info = CourseUsageInfo(starting_block_usage_key.course_key, user, allow_start_dates_in_future)
transformers.usage_info = CourseUsageInfo(
starting_block_usage_key.course_key,
user,
allow_start_dates_in_future,
include_has_scheduled_content
)
return get_block_structure_manager(starting_block_usage_key.course_key).get_transformed(
transformers,
......
......@@ -43,6 +43,23 @@ class StartDateTransformer(FilteringTransformerMixin, BlockStructureTransformer)
"""
return "start_date"
@classmethod
def _check_has_scheduled_content(cls, block_structure, scheduled_content_condition):
'''
Returns a block structure where the root course block has been
updated to include a has_scheduled_content field (True if the course
has any blocks with release dates in the future, False otherwise).
'''
has_scheduled_content = False
for block_key in block_structure.topological_traversal():
if scheduled_content_condition(block_key):
has_scheduled_content = True
break
block_structure.override_xblock_field(
block_structure.root_block_usage_key, 'has_scheduled_content', has_scheduled_content
)
@classmethod
def _get_merged_start_date(cls, block_structure, block_key):
"""
......@@ -85,4 +102,8 @@ class StartDateTransformer(FilteringTransformerMixin, BlockStructureTransformer)
usage_info.course_key,
now=now,
)
if usage_info.include_has_scheduled_content:
self._check_has_scheduled_content(block_structure, removal_condition)
return [block_structure.create_removal_filter(removal_condition)]
......@@ -14,7 +14,7 @@ class CourseUsageInfo(object):
an instance of it in calls to BlockStructureTransformer.transform
methods.
'''
def __init__(self, course_key, user, allow_start_dates_in_future=False):
def __init__(self, course_key, user, allow_start_dates_in_future=False, include_has_scheduled_content=False):
# Course identifier (opaque_keys.edx.keys.CourseKey)
self.course_key = course_key
......@@ -27,6 +27,11 @@ class CourseUsageInfo(object):
# assignments that have not yet been released.
self.allow_start_dates_in_future = allow_start_dates_in_future
# This value is used within the StartDateTransformer in the case where we
# would like to know whether there are future start dates, while still
# filtering the blocks with start dates in the future.
self.include_has_scheduled_content = include_has_scheduled_content
# Cached value of whether the user has staff access (bool/None)
self._has_staff_access = None
......
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