def get_redirect_url(course_key, usage_key):
 (course_key, chapter, section, vertical_unused, position, final_target_id) = path_to_location(modulestore(), usage_key)
 if (chapter is None):
  redirect_url = reverse('courseware', args=(unicode(course_key),))
 elif (section is None):
  redirect_url = reverse('courseware_chapter', args=(unicode(course_key), chapter))
 elif (position is None):
  redirect_url = reverse('courseware_section', args=(unicode(course_key), chapter, section))
 else:
  redirect_url = reverse('courseware_position', args=(unicode(course_key), chapter, section, navigation_index(position)))
 redirect_url += '?{}'.format(urlencode({'activate_block_id': unicode(final_target_id)}))
 return redirect_url

def get_redirect_url ( course_key , usage_key ) : ( course_key , chapter , section , vertical_unused , position , final_target_id ) = path_to_location ( modulestore ( ) , usage_key ) if ( chapter is None ) : redirect_url = reverse ( 'courseware' , args = ( unicode ( course_key ) , ) ) elif ( section is None ) : redirect_url = reverse ( 'courseware_chapter' , args = ( unicode ( course_key ) , chapter ) ) elif ( position is None ) : redirect_url = reverse ( 'courseware_section' , args = ( unicode ( course_key ) , chapter , section ) ) else : redirect_url = reverse ( 'courseware_position' , args = ( unicode ( course_key ) , chapter , section , navigation_index ( position ) ) ) redirect_url += '?{}' . format ( urlencode ( { 'activate_block_id' : unicode ( final_target_id ) } ) ) return redirect_url
returns the redirect url back to courseware args: course_id: course id string location: the location id of course component raises: itemnotfounderror if no data at the location or nopathtoitem if location not in any class returns: redirect url string .