def restore_ccx(val, ccx_id):
 if isinstance(val, CourseLocator):
  return CCXLocator.from_course_locator(val, ccx_id)
 elif isinstance(val, BlockUsageLocator):
  ccx_key = restore_ccx(val.course_key, ccx_id)
  val = CCXBlockUsageLocator(ccx_key, val.block_type, val.block_id)
 for field_name in XMODULE_FIELDS_WITH_USAGE_KEYS:
  if hasattr(val, field_name):
   setattr(val, field_name, restore_ccx(getattr(val, field_name), ccx_id))
 if hasattr(val, 'children'):
  val.children = restore_ccx_collection(val.children, ccx_id)
 return val

def restore_ccx ( val , ccx_id ) : if isinstance ( val , CourseLocator ) : return CCXLocator . from_course_locator ( val , ccx_id ) elif isinstance ( val , BlockUsageLocator ) : ccx_key = restore_ccx ( val . course_key , ccx_id ) val = CCXBlockUsageLocator ( ccx_key , val . block_type , val . block_id ) for field_name in XMODULE_FIELDS_WITH_USAGE_KEYS : if hasattr ( val , field_name ) : setattr ( val , field_name , restore_ccx ( getattr ( val , field_name ) , ccx_id ) ) if hasattr ( val , 'children' ) : val . children = restore_ccx_collection ( val . children , ccx_id ) return val
restore references to a ccx to the incoming value returns the value converted to a ccx-aware state .