feat: create feature flag for PLS custom pacing

This commit is contained in:
Sofia Yoon
2021-06-21 10:38:52 -04:00
parent 87a620612f
commit 4d96449134
10 changed files with 132 additions and 6 deletions

View File

@@ -1,8 +1,11 @@
"""Signal handlers for writing course dates into edx_when."""
from datetime import timedelta, datetime
import datetime
import logging
from cms.djangoapps.contentstore.config.waffle import custom_pls_is_active
from django.dispatch import receiver
from edx_when.api import FIELDS_TO_EXTRACT, set_dates_for_course
@@ -27,6 +30,11 @@ def _field_values(fields, xblock):
if field_name not in xblock.fields:
continue
field = xblock.fields[field_name]
if field_name == 'due':
print("THIS IS THE FIELD ", field)
print(xblock)
result[field.name] = field.read_from(xblock)
continue
if field.scope == Scope.settings and field.is_set_on(xblock):
try:
result[field.name] = field.read_from(xblock)
@@ -83,7 +91,34 @@ def extract_dates_from_course(course):
Extract all dates from the supplied course.
"""
log.info('Extracting course dates for %s', course.id)
if course.self_paced:
if course.self_paced and custom_pls_is_active(course.id):
print("This is self paced ")
date_items = []
store = modulestore()
with store.branch_setting(ModuleStoreEnum.Branch.published_only, course.id):
items = store.get_items(course.id)
log.info('Extracting dates from %d items in %s', len(items), course.id)
print("B4 the items sections")
# new_fields_to_extract = FIELDS_TO_EXTRACT + ('due_num_weeks',)
# print("THe new fields to extract ", new_fields_to_extract)
for item in items:
metadata = _field_values(FIELDS_TO_EXTRACT, item)
print("THIS IS THE METADATA ", metadata)
metadata['due'] = datetime.datetime.now() - metadata['due']
# print("TYPE OF DATES: ", metadata)
# print("RIGHT NOW, ", datetime.datetime.now())
# print(metadata['due'])
# metadata['due'] = datetime.datetime.now() - metadata['due']
# print('metadata due: ', metadata['due'])
metadata.pop('due_num_weeks',None)
# print("THIS IS THE DUE DATE: ", metadata['due'])
date_items.append((item.location, metadata))
# date_items.append((item.location, _field_values(FIELDS_TO_EXTRACT, item)))
print("Here are the date items: ", date_items)
elif course.self_paced and not custom_pls_is_active(course.id):
metadata = _field_values(FIELDS_TO_EXTRACT, course)
# self-paced courses may accidentally have a course due date
metadata.pop('due', None)
@@ -94,6 +129,7 @@ def extract_dates_from_course(course):
# unless that item already has a relative date set
for _, section, weeks_to_complete in spaced_out_sections(course):
section_date_items = []
print("THESE IS THE WEEKS TO COMPLETE ,", weeks_to_complete)
for subsection in section.get_children():
section_date_items.extend(_gather_graded_items(subsection, weeks_to_complete))
@@ -108,6 +144,7 @@ def extract_dates_from_course(course):
log.info('Extracting dates from %d items in %s', len(items), course.id)
for item in items:
date_items.append((item.location, _field_values(FIELDS_TO_EXTRACT, item)))
return date_items