def _get_legacy_courseware_url( usage_key: UsageKey, request: Optional[HttpRequest] = None, ) -> str: """ Return the URL to Legacy (LMS-rendered) courseware content. Raises: * ItemNotFoundError if no data at the usage_key. * NoPathToItem if location not in any class. """ (course_key, chapter, section, vertical_unused, position, final_target_id) = path_to_location(modulestore(), usage_key, request) # choose the appropriate view (and provide the necessary args) based on the # args provided by the redirect. # Rely on index to do all error handling and access control. if chapter is None: redirect_url = reverse('courseware', args=(str(course_key), )) elif section is None: redirect_url = reverse('courseware_chapter', args=(str(course_key), chapter)) elif position is None: redirect_url = reverse('courseware_section', args=(str(course_key), chapter, section)) else: # Here we use the navigation_index from the position returned from # path_to_location - we can only navigate to the topmost vertical at the # moment redirect_url = reverse('courseware_position', args=(str(course_key), chapter, section, navigation_index(position))) redirect_url += "?{}".format( urlencode({'activate_block_id': str(final_target_id)})) return redirect_url
def location(self): """ Blend "location" property into the resultset, so that the path to the found component can be shown within the UI """ # TODO: update whern changes to "cohorted-courseware" branch are merged in (course_key, chapter, section, position) = path_to_location(self.get_module_store(), self.get_usage_key()) def get_display_name(item_key): """ gets display name from object's key """ item = self.get_item(item_key) display_name = getattr(item, "display_name", None) return display_name if display_name else UNNAMED_MODULE_NAME def get_position_name(section, position): """ helper to fetch name corresponding to the position therein """ if position: section_item = self.get_item(course_key.make_usage_key("sequential", section)) if section_item.has_children and len(section_item.children) >= position: return get_display_name(section_item.children[position - 1]) return None location_description = [] if chapter: location_description.append(get_display_name(course_key.make_usage_key("chapter", chapter))) if section: location_description.append(get_display_name(course_key.make_usage_key("sequential", section))) if position: # We're only wanting to show the first vertical, so we use the # navigation_index function to display the same location to which one # would be sent if navigating location_description.append(get_position_name(section, navigation_index(position))) return location_description
def get_redirect_url(course_key, usage_key, child=None): """ Returns the redirect url back to courseware Args: course_id(str): Course Id string location(str): The location id of course component child(str): Optional child parameter to pass to the URL Raises: ItemNotFoundError if no data at the location or NoPathToItem if location not in any class Returns: Redirect url string """ ( course_key, chapter, section, vertical_unused, position, final_target_id ) = path_to_location(modulestore(), usage_key) # choose the appropriate view (and provide the necessary args) based on the # args provided by the redirect. # Rely on index to do all error handling and access control. 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: # Here we use the navigation_index from the position returned from # path_to_location - we can only navigate to the topmost vertical at the # moment 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)})) if child: redirect_url += "&child={}".format(child) return redirect_url
def get_redirect_url(course_key, usage_key, child=None): """ Returns the redirect url back to courseware Args: course_id(str): Course Id string location(str): The location id of course component child(str): Optional child parameter to pass to the URL Raises: ItemNotFoundError if no data at the location or NoPathToItem if location not in any class Returns: Redirect url string """ (course_key, chapter, section, vertical_unused, position, final_target_id) = path_to_location(modulestore(), usage_key) # choose the appropriate view (and provide the necessary args) based on the # args provided by the redirect. # Rely on index to do all error handling and access control. 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: # Here we use the navigation_index from the position returned from # path_to_location - we can only navigate to the topmost vertical at the # moment 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)})) if child: redirect_url += "&child={}".format(child) return redirect_url
def get_redirect_url(course_key, usage_key, unified_course_view=False): """ Returns the redirect url back to courseware Args: course_id(str): Course Id string location(str): The location id of course component unified_course_view (bool): temporary parameter while this feature is behind a waffle flag. Is the unified_course_view waffle flag on? Raises: ItemNotFoundError if no data at the location or NoPathToItem if location not in any class Returns: Redirect url string """ if usage_key.block_type == 'course' and unified_course_view: return reverse('openedx.course_experience.course_home', args=[unicode(course_key)]) (course_key, chapter, section, vertical_unused, position, final_target_id) = path_to_location(modulestore(), usage_key) # choose the appropriate view (and provide the necessary args) based on the # args provided by the redirect. # Rely on index to do all error handling and access control. 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: # Here we use the navigation_index from the position returned from # path_to_location - we can only navigate to the topmost vertical at the # moment 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_legacy_courseware_url(course_key, usage_key, request=None): """ Return a str with the URL for the specified legacy (LMS-rendered) coursweare content. Args: course_id(str): Course Id string usage_key(str): 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 """ (course_key, chapter, section, vertical_unused, position, final_target_id) = path_to_location(modulestore(), usage_key, request) # choose the appropriate view (and provide the necessary args) based on the # args provided by the redirect. # Rely on index to do all error handling and access control. if chapter is None: redirect_url = reverse('courseware', args=(six.text_type(course_key), )) elif section is None: redirect_url = reverse('courseware_chapter', args=(six.text_type(course_key), chapter)) elif position is None: redirect_url = reverse('courseware_section', args=(six.text_type(course_key), chapter, section)) else: # Here we use the navigation_index from the position returned from # path_to_location - we can only navigate to the topmost vertical at the # moment redirect_url = reverse('courseware_position', args=(six.text_type(course_key), chapter, section, navigation_index(position))) redirect_url += "?{}".format( urlencode({'activate_block_id': six.text_type(final_target_id)})) return redirect_url