def get_html(self): if isinstance(modulestore(), MongoModuleStore): caption_asset_path = StaticContent.get_base_url_path_for_course_assets(self.location) + "/subs_" else: # VS[compat] # cdodge: filesystem static content support. caption_asset_path = "/static/subs/" return self.system.render_template( "videoalpha.html", { "youtube_streams": self.youtube_streams, "id": self.location.html_id(), "sub": self.sub, "autoplay": self.autoplay, "sources": self.sources, "track": self.track, "display_name": self.display_name_with_default, # This won't work when we move to data that # isn't on the filesystem "data_dir": getattr(self, "data_dir", None), "caption_asset_path": caption_asset_path, "show_captions": self.show_captions, "start": self.start_time, "end": self.end_time, "autoplay": settings.MITX_FEATURES.get("AUTOPLAY_VIDEOS", True), }, )
def course_info_handler(request, tag=None, course_id=None, branch=None, version_guid=None, block=None): """ GET html: return html for editing the course info handouts and updates. """ course_location = BlockUsageLocator(course_id=course_id, branch=branch, version_guid=version_guid, usage_id=block) course_old_location = loc_mapper().translate_locator_to_location(course_location) if 'text/html' in request.META.get('HTTP_ACCEPT', 'text/html'): if not has_access(request.user, course_location): raise PermissionDenied() course_module = modulestore().get_item(course_old_location) handouts_old_location = course_old_location.replace(category='course_info', name='handouts') handouts_locator = loc_mapper().translate_location( course_old_location.course_id, handouts_old_location, False, True ) update_location = course_old_location.replace(category='course_info', name='updates') update_locator = loc_mapper().translate_location( course_old_location.course_id, update_location, False, True ) return render_to_response( 'course_info.html', { 'context_course': course_module, 'updates_url': update_locator.url_reverse('course_info_update/'), 'handouts_locator': handouts_locator, 'base_asset_url': StaticContent.get_base_url_path_for_course_assets(course_old_location) + '/' } ) else: return HttpResponseBadRequest("Only supports html requests")
def course_info_handler(request, tag=None, package_id=None, branch=None, version_guid=None, block=None): """ GET html: return html for editing the course info handouts and updates. """ __, course_module = _get_locator_and_course( package_id, branch, version_guid, block, request.user ) if 'text/html' in request.META.get('HTTP_ACCEPT', 'text/html'): handouts_old_location = course_module.location.replace(category='course_info', name='handouts') handouts_locator = loc_mapper().translate_location( course_module.location.course_id, handouts_old_location, False, True ) update_location = course_module.location.replace(category='course_info', name='updates') update_locator = loc_mapper().translate_location( course_module.location.course_id, update_location, False, True ) return render_to_response( 'course_info.html', { 'context_course': course_module, 'updates_url': update_locator.url_reverse('course_info_update/'), 'handouts_locator': handouts_locator, 'base_asset_url': StaticContent.get_base_url_path_for_course_assets(course_module.location) + '/' } ) else: return HttpResponseBadRequest("Only supports html requests")
def course_info(request, org, course, name, provided_id=None): """ Send models and views as well as html for editing the course info to the client. org, course, name: Attributes of the Location for the item to edit """ location = get_location_and_verify_access(request, org, course, name) course_module = modulestore().get_item(location) # get current updates location = Location(['i4x', org, course, 'course_info', "updates"]) return render_to_response( 'course_info.html', { 'context_course': course_module, 'url_base': "/" + org + "/" + course + "/", 'course_updates': json.dumps(get_course_updates(location)), 'handouts_location': Location(['i4x', org, course, 'course_info', 'handouts']).url(), 'base_asset_url': StaticContent.get_base_url_path_for_course_assets(location) + '/' })
def course_info_handler(request, tag=None, package_id=None, branch=None, version_guid=None, block=None): """ GET html: return html for editing the course info handouts and updates. """ __, course_module = _get_locator_and_course(package_id, branch, version_guid, block, request.user) if "text/html" in request.META.get("HTTP_ACCEPT", "text/html"): handouts_old_location = course_module.location.replace(category="course_info", name="handouts") handouts_locator = loc_mapper().translate_location( course_module.location.course_id, handouts_old_location, False, True ) update_location = course_module.location.replace(category="course_info", name="updates") update_locator = loc_mapper().translate_location(course_module.location.course_id, update_location, False, True) return render_to_response( "course_info.html", { "context_course": course_module, "updates_url": update_locator.url_reverse("course_info_update/"), "handouts_locator": handouts_locator, "base_asset_url": StaticContent.get_base_url_path_for_course_assets(course_module.location) + "/", }, ) else: return HttpResponseBadRequest("Only supports html requests")
def get_html(self): if isinstance(modulestore(), MongoModuleStore): caption_asset_path = StaticContent.get_base_url_path_for_course_assets(self.location) + '/subs_' else: # VS[compat] # cdodge: filesystem static content support. caption_asset_path = "/static/subs/" get_ext = lambda filename: filename.rpartition('.')[-1] sources = {get_ext(src): src for src in self.html5_sources} sources['main'] = self.source return self.system.render_template('videoalpha.html', { 'youtube_streams': _create_youtube_string(self), 'id': self.location.html_id(), 'sub': self.sub, 'sources': sources, 'track': self.track, 'display_name': self.display_name_with_default, # This won't work when we move to data that # isn't on the filesystem 'data_dir': getattr(self, 'data_dir', None), 'caption_asset_path': caption_asset_path, 'show_captions': json.dumps(self.show_captions), 'start': self.start_time, 'end': self.end_time, 'autoplay': settings.MITX_FEATURES.get('AUTOPLAY_VIDEOS', True) })
def rewrite_nonportable_content_links(source_course_id, dest_course_id, text): """ Does a regex replace on non-portable links: /c4x/<org>/<course>/asset/<name> -> /static/<name> /jump_to/i4x://<org>/<course>/<category>/<name> -> /jump_to_id/<id> """ def portable_asset_link_subtitution(match): quote = match.group('quote') rest = match.group('rest') return quote + '/static/' + rest + quote def portable_jump_to_link_substitution(match): quote = match.group('quote') rest = match.group('rest') return quote + '/jump_to_id/' + rest + quote # NOTE: ultimately link updating is not a hard requirement, so if something blows up with # the regex substitution, log the error and continue c4x_link_base = StaticContent.get_base_url_path_for_course_assets( source_course_id) try: text = re.sub(_prefix_only_url_replace_regex(c4x_link_base), portable_asset_link_subtitution, text) except Exception as exc: # pylint: disable=broad-except logging.warning( "Error producing regex substitution %r for text = %r.\n\nError msg = %s", c4x_link_base, text, str(exc)) jump_to_link_base = u'/courses/{course_key_string}/jump_to/i4x://{course_key.org}/{course_key.course}/'.format( course_key_string=source_course_id.to_deprecated_string(), course_key=source_course_id) try: text = re.sub( _prefix_and_category_url_replace_regex(jump_to_link_base), portable_jump_to_link_substitution, text) except Exception as exc: # pylint: disable=broad-except logging.warning( "Error producing regex substitution %r for text = %r.\n\nError msg = %s", jump_to_link_base, text, str(exc)) # Also, there commonly is a set of link URL's used in the format: # /courses/<org>/<course>/<name> which will be broken if migrated to a different course_id # so let's rewrite those, but the target will also be non-portable, # # Note: we only need to do this if we are changing course-id's # if source_course_id != dest_course_id: try: generic_courseware_link_base = u'/courses/{}/'.format( source_course_id.to_deprecated_string()) text = re.sub( _prefix_only_url_replace_regex(generic_courseware_link_base), portable_asset_link_subtitution, text) except Exception as exc: # pylint: disable=broad-except logging.warning( "Error producing regex substitution %r for text = %r.\n\nError msg = %s", source_course_id, text, str(exc)) return text
def get_html(self): if isinstance(modulestore(), MongoModuleStore): caption_asset_path = StaticContent.get_base_url_path_for_course_assets( self.location) + '/subs_' else: # VS[compat] # cdodge: filesystem static content support. caption_asset_path = "/static/subs/" return self.system.render_template( 'videoalpha.html', { 'youtube_streams': self.youtube_streams, 'id': self.location.html_id(), 'sub': self.sub, 'sources': self.sources, 'track': self.track, 'display_name': self.display_name_with_default, # TODO (cpennington): This won't work when we move to data that # isn't on the filesystem 'data_dir': getattr(self, 'data_dir', None), 'caption_asset_path': caption_asset_path, 'show_captions': self.show_captions, 'start': self.start_time, 'end': self.end_time })
def get_context(self): _context = EditingDescriptor.get_context(self) _context.update({'test':self.data}) if self.data == u'': template_data='<poll_compare><compare compare_id="compare_1" from_loc="i4x://[org]/[course]/[category]/[url_name]" to_loc="i4x://[org]/[course]/[category]/[url_name]" display_name="test1"></compare><compare compare_id="compare_2" from_loc="i4x://[org]/[course]/[category]/[url_name]" to_loc="i4x://[org]/[course]/[category]/[url_name]" display_name="test2"></compare></poll_compare>' _context.update({'test':template_data}) _context.update({'base_asset_url': StaticContent.get_base_url_path_for_course_assets(self.location) + '/'}) return _context
def get_context(self): """ an override to add in specific rendering context, in this case we need to add in a base path to our c4x content addressing scheme """ _context = EditingDescriptor.get_context(self) # Add some specific HTML rendering context when editing HTML modules where we pass # the root /c4x/ url for assets. This allows client-side substitutions to occur. _context.update({'base_asset_url': StaticContent.get_base_url_path_for_course_assets(self.location) + '/'}) return _context
def student_state(self): """ Returns a JSON serializable representation of student's state for rendering in client view. """ submission = self.get_submission() if submission: uploaded = {"filename": submission['answer']['filename']} else: uploaded = None if self.annotated_sha1: annotated = {"filename": force_text(self.annotated_filename)} else: annotated = None score = self.score if score is not None: graded = {'score': score, 'comment': force_text(self.comment)} else: graded = None if self.answer_available(): solution = self.runtime.replace_urls(force_text(self.solution)) else: solution = '' if uploaded: answer_checked = not self.fresh else: answer_checked = False return { "display_name": force_text(self.display_name), "uploaded": uploaded, "annotated": annotated, "graded": graded, "answer_checked": answer_checked, "max_score": self.max_score(), "upload_allowed": self.upload_allowed(submission_data=submission), "solution": solution, "base_asset_url": StaticContent.get_base_url_path_for_course_assets( self.location.course_key), }
def studio_view(self, context): """ it will loads studio view :param context: context :return: fragment """ block_id = "xblock-{}".format(self.get_block_id()) course_key = getattr(self.scope_ids.usage_id, 'course_key', None) context['self'] = self context['block_id'] = block_id try: from xmodule.contentstore.content import StaticContent base_asset_url = StaticContent.get_base_url_path_for_course_assets( course_key) except Exception: base_asset_url = '' return self.get_fragment( context, 'studio', { 'base_asset_url': base_asset_url, 'quiz_type': self.quiz_type, 'block_id': block_id, 'results': self.results, 'BUZZFEED_QUIZ_VALUE': self.BUZZFEED_QUIZ_VALUE, 'DIAGNOSTIC_QUIZ_VALUE': self.DIAGNOSTIC_QUIZ_VALUE, 'DEFAULT_GROUP': self.DEFAULT_GROUP, 'questions': self.questions, 'groups': self.groups, 'attachedGroups': self.get_attached_groups(), 'categoryTpl': loader.load_unicode('templates/underscore/category.html'), 'rangeTpl': loader.load_unicode('templates/underscore/range.html'), 'questionTpl': loader.load_unicode('templates/underscore/question.html'), 'choiceTpl': loader.load_unicode('templates/underscore/choice.html') })
def rewrite_nonportable_content_links(source_course_id, dest_course_id, text): """ Does a regex replace on non-portable links: /c4x/<org>/<course>/asset/<name> -> /static/<name> /jump_to/i4x://<org>/<course>/<category>/<name> -> /jump_to_id/<id> """ def portable_asset_link_subtitution(match): quote = match.group('quote') rest = match.group('rest') return quote + '/static/' + rest + quote def portable_jump_to_link_substitution(match): quote = match.group('quote') rest = match.group('rest') return quote + '/jump_to_id/' + rest + quote # NOTE: ultimately link updating is not a hard requirement, so if something blows up with # the regex substitution, log the error and continue c4x_link_base = StaticContent.get_base_url_path_for_course_assets(source_course_id) try: text = re.sub(_prefix_only_url_replace_regex(c4x_link_base), portable_asset_link_subtitution, text) except Exception as exc: # pylint: disable=broad-except logging.warning("Error producing regex substitution %r for text = %r.\n\nError msg = %s", c4x_link_base, text, str(exc)) jump_to_link_base = u'/courses/{course_key_string}/jump_to/i4x://{course_key.org}/{course_key.course}/'.format( course_key_string=source_course_id.to_deprecated_string(), course_key=source_course_id ) try: text = re.sub(_prefix_and_category_url_replace_regex(jump_to_link_base), portable_jump_to_link_substitution, text) except Exception as exc: # pylint: disable=broad-except logging.warning("Error producing regex substitution %r for text = %r.\n\nError msg = %s", jump_to_link_base, text, str(exc)) # Also, there commonly is a set of link URL's used in the format: # /courses/<org>/<course>/<name> which will be broken if migrated to a different course_id # so let's rewrite those, but the target will also be non-portable, # # Note: we only need to do this if we are changing course-id's # if source_course_id != dest_course_id: try: generic_courseware_link_base = u'/courses/{}/'.format(source_course_id.to_deprecated_string()) text = re.sub(_prefix_only_url_replace_regex(generic_courseware_link_base), portable_asset_link_subtitution, text) except Exception as exc: # pylint: disable=broad-except logging.warning("Error producing regex substitution %r for text = %r.\n\nError msg = %s", source_course_id, text, str(exc)) return text
def get_context(self): _context = RawDescriptor.get_context(self) _context.update({ 'markdown': self.markdown, 'enable_markdown': self.markdown is not None, 'enable_latex_compiler': self.use_latex_compiler, 'base_asset_url': StaticContent.get_base_url_path_for_course_assets( self.location.course_key), 'course_key': self.location.course_key, }) return _context
def get_student_view_base_data(self, student_id=None): data = { 'xblock_id': self._get_xblock_loc(), "max_file_size": self.student_upload_max_size(), "base_asset_url": StaticContent.get_base_url_path_for_course_assets( self.location.course_key) } submission = self.get_submission(student_id) if submission: data["filename"] = submission['answer']['filename'] data["result"] = json.loads(submission['answer']['result']) data["score"] = json.loads(submission['answer']['score']) return data
def rewrite_nonportable_content_links(source_course_id, dest_course_id, text): """ Does a regex replace on non-portable links: /c4x/<org>/<course>/asset/<name> -> /static/<name> /jump_to/i4x://<org>/<course>/<category>/<name> -> /jump_to_id/<id> """ course_id_dict = Location.parse_course_id(source_course_id) course_id_dict['tag'] = 'i4x' course_id_dict['category'] = 'course' def portable_asset_link_subtitution(match): quote = match.group('quote') rest = match.group('rest') return quote + '/static/' + rest + quote def portable_jump_to_link_substitution(match): quote = match.group('quote') rest = match.group('rest') return quote + '/jump_to_id/' + rest + quote def generic_courseware_link_substitution(match): parts = Location.parse_course_id(dest_course_id) parts['quote'] = match.group('quote') parts['rest'] = match.group('rest') return u'{quote}/courses/{org}/{course}/{name}/{rest}{quote}'.format( **parts) course_location = Location(course_id_dict) # NOTE: ultimately link updating is not a hard requirement, so if something blows up with # the regex subsitution, log the error and continue try: c4x_link_base = u'{0}/'.format( StaticContent.get_base_url_path_for_course_assets(course_location)) text = re.sub(_prefix_only_url_replace_regex(c4x_link_base), portable_asset_link_subtitution, text) except Exception, e: logging.warning( "Error going regex subtituion %r on text = %r.\n\nError msg = %s", c4x_link_base, text, str(e))
def course_info(request, org, course, name, provided_id=None): """ Send models and views as well as html for editing the course info to the client. org, course, name: Attributes of the Location for the item to edit """ location = get_location_and_verify_access(request, org, course, name) course_module = modulestore().get_item(location) # get current updates location = Location(['i4x', org, course, 'course_info', "updates"]) return render_to_response('course_info.html', { 'context_course': course_module, 'url_base': "/" + org + "/" + course + "/", 'course_updates': json.dumps(get_course_updates(location)), 'handouts_location': Location(['i4x', org, course, 'course_info', 'handouts']).url(), 'base_asset_url': StaticContent.get_base_url_path_for_course_assets(location) + '/'})
def course_info_handler(request, course_key_string): """ GET html: return html for editing the course info handouts and updates. """ course_key = CourseKey.from_string(course_key_string) course_module = _get_course_module(course_key, request.user) if 'text/html' in request.META.get('HTTP_ACCEPT', 'text/html'): return render_to_response( 'course_info.html', { 'context_course': course_module, 'updates_url': reverse_course_url('course_info_update_handler', course_key), 'handouts_locator': course_key.make_usage_key('course_info', 'handouts'), 'base_asset_url': StaticContent.get_base_url_path_for_course_assets(course_module.id) } ) else: return HttpResponseBadRequest("Only supports html requests")
def course_info_handler(request, course_key_string): """ GET html: return html for editing the course info handouts and updates. """ course_key = CourseKey.from_string(course_key_string) course_module = _get_course_module(course_key, request.user) if "text/html" in request.META.get("HTTP_ACCEPT", "text/html"): return render_to_response( "course_info.html", { "context_course": course_module, "updates_url": reverse_course_url("course_info_update_handler", course_key), "handouts_locator": course_key.make_usage_key("course_info", "handouts"), "base_asset_url": StaticContent.get_base_url_path_for_course_assets(course_module.id), }, ) else: return HttpResponseBadRequest("Only supports html requests")
def rewrite_nonportable_content_links(source_course_id, dest_course_id, text): """ Does a regex replace on non-portable links: /c4x/<org>/<course>/asset/<name> -> /static/<name> /jump_to/i4x://<org>/<course>/<category>/<name> -> /jump_to_id/<id> """ org, course, run = source_course_id.split("/") dest_org, dest_course, dest_run = dest_course_id.split("/") def portable_asset_link_subtitution(match): quote = match.group('quote') rest = match.group('rest') return quote + '/static/' + rest + quote def portable_jump_to_link_substitution(match): quote = match.group('quote') rest = match.group('rest') return quote + '/jump_to_id/' + rest + quote def generic_courseware_link_substitution(match): quote = match.group('quote') rest = match.group('rest') dest_generic_courseware_lik_base = '/courses/{org}/{course}/{run}/'.format( org=dest_org, course=dest_course, run=dest_run) return quote + dest_generic_courseware_lik_base + rest + quote course_location = Location(['i4x', org, course, 'course', run]) # NOTE: ultimately link updating is not a hard requirement, so if something blows up with # the regex subsitution, log the error and continue try: c4x_link_base = '{0}/'.format( StaticContent.get_base_url_path_for_course_assets(course_location)) text = re.sub(_prefix_only_url_replace_regex(c4x_link_base), portable_asset_link_subtitution, text) except Exception, e: logging.warning( "Error going regex subtituion %r on text = %r.\n\nError msg = %s", c4x_link_base, text, str(e))
def get_html(self): if isinstance(modulestore(), MongoModuleStore): caption_asset_path = StaticContent.get_base_url_path_for_course_assets(self.location) + '/subs_' else: # VS[compat] # cdodge: filesystem static content support. caption_asset_path = "/static/subs/" return self.system.render_template('videoalpha.html', { 'youtube_streams': self.youtube_streams, 'id': self.location.html_id(), 'sub': self.sub, 'sources': self.sources, 'track': self.track, 'display_name': self.display_name_with_default, # TODO (cpennington): This won't work when we move to data that isn't on the filesystem 'data_dir': getattr(self, 'data_dir', None), 'caption_asset_path': caption_asset_path, 'show_captions': self.show_captions, 'start': self.start_time, 'end': self.end_time })
def rewrite_nonportable_content_links(source_course_id, dest_course_id, text): """ Does a regex replace on non-portable links: /c4x/<org>/<course>/asset/<name> -> /static/<name> /jump_to/i4x://<org>/<course>/<category>/<name> -> /jump_to_id/<id> """ org, course, run = source_course_id.split("/") dest_org, dest_course, dest_run = dest_course_id.split("/") def portable_asset_link_subtitution(match): quote = match.group('quote') rest = match.group('rest') return quote + '/static/' + rest + quote def portable_jump_to_link_substitution(match): quote = match.group('quote') rest = match.group('rest') return quote + '/jump_to_id/' + rest + quote def generic_courseware_link_substitution(match): quote = match.group('quote') rest = match.group('rest') dest_generic_courseware_lik_base = '/courses/{org}/{course}/{run}/'.format( org=dest_org, course=dest_course, run=dest_run ) return quote + dest_generic_courseware_lik_base + rest + quote course_location = Location(['i4x', org, course, 'course', run]) # NOTE: ultimately link updating is not a hard requirement, so if something blows up with # the regex subsitution, log the error and continue try: c4x_link_base = '{0}/'.format(StaticContent.get_base_url_path_for_course_assets(course_location)) text = re.sub(_prefix_only_url_replace_regex(c4x_link_base), portable_asset_link_subtitution, text) except Exception, e: logging.warning("Error going regex subtituion %r on text = %r.\n\nError msg = %s", c4x_link_base, text, str(e))
def studio_view(self, context): """ it will loads studio view :param context: context :return: fragment """ block_id = "xblock-{}".format(self.get_block_id()) course_key = getattr(self.scope_ids.usage_id, 'course_key', None) context['self'] = self context['block_id'] = block_id try: from xmodule.contentstore.content import StaticContent base_asset_url = StaticContent.get_base_url_path_for_course_assets(course_key) except: base_asset_url = '' return self.get_fragment( context, 'studio', { 'base_asset_url': base_asset_url, 'quiz_type': self.quiz_type, 'block_id': block_id, 'results': self.results, 'BUZZFEED_QUIZ_VALUE': self.BUZZFEED_QUIZ_VALUE, 'DIAGNOSTIC_QUIZ_VALUE': self.DIAGNOSTIC_QUIZ_VALUE, 'DEFAULT_GROUP': self.DEFAULT_GROUP, 'questions': self.questions, 'groups': self.groups, 'attachedGroups': self.get_attached_groups(), 'categoryTpl': loader.load_unicode('templates/underscore/category.html'), 'rangeTpl': loader.load_unicode('templates/underscore/range.html'), 'questionTpl': loader.load_unicode('templates/underscore/question.html'), 'choiceTpl': loader.load_unicode('templates/underscore/choice.html') } )
def rewrite_nonportable_content_links(source_course_id, dest_course_id, text): """ Does a regex replace on non-portable links: /c4x/<org>/<course>/asset/<name> -> /static/<name> /jump_to/i4x://<org>/<course>/<category>/<name> -> /jump_to_id/<id> """ course_id_dict = Location.parse_course_id(source_course_id) course_id_dict["tag"] = "i4x" course_id_dict["category"] = "course" def portable_asset_link_subtitution(match): quote = match.group("quote") rest = match.group("rest") return quote + "/static/" + rest + quote def portable_jump_to_link_substitution(match): quote = match.group("quote") rest = match.group("rest") return quote + "/jump_to_id/" + rest + quote def generic_courseware_link_substitution(match): parts = Location.parse_course_id(dest_course_id) parts["quote"] = match.group("quote") parts["rest"] = match.group("rest") return u"{quote}/courses/{org}/{course}/{name}/{rest}{quote}".format(**parts) course_location = Location(course_id_dict) # NOTE: ultimately link updating is not a hard requirement, so if something blows up with # the regex subsitution, log the error and continue try: c4x_link_base = u"{0}/".format(StaticContent.get_base_url_path_for_course_assets(course_location)) text = re.sub(_prefix_only_url_replace_regex(c4x_link_base), portable_asset_link_subtitution, text) except Exception, e: logging.warning("Error going regex subtituion %r on text = %r.\n\nError msg = %s", c4x_link_base, text, str(e))
def student_state(self): """ Returns a JSON serializable representation of student's state for rendering in client view. """ submission = self.get_submission() if submission: uploaded = {"filename": submission['answer']['filename']} else: uploaded = None if self.annotated_sha1: annotated = {"filename": force_text(self.annotated_filename)} else: annotated = None score = self.score if score is not None: graded = {'score': score, 'comment': force_text(self.comment)} else: graded = None if self.answer_available(): solution = self.runtime.replace_urls(force_text(self.solution)) else: solution = '' return { "display_name": force_text(self.display_name), "uploaded": uploaded, "annotated": annotated, "graded": graded, "max_score": self.max_score(), "upload_allowed": self.upload_allowed(submission_data=submission), "solution": solution, "base_asset_url": StaticContent.get_base_url_path_for_course_assets(self.location.course_key), }
def _find_asset_urls_in_block( task_id, value, block_loc, block_assets, course_key, environment, staff_user_id, update, dictionary=None, value_key=None, ): if type(value) == dict: for key, val in value.items(): _find_asset_urls_in_block(task_id, val, block_loc, block_assets, course_key, environment, staff_user_id, update, dictionary=value, value_key=key) elif type(value) == list: for item in value: _find_asset_urls_in_block(task_id, item, block_loc, block_assets, course_key, environment, staff_user_id, update, dictionary=dictionary, value_key=value_key) elif type(value) in (str, unicode): save_updated = False urls = re.findall(URL_RE, value) for url in urls: url = strip_tags(url) parsed_url = urlparse(url) asset_url = StaticContent.ASSET_URL_RE.match(parsed_url.path) if asset_url is not None: # check if asset URL belongs to some other server or course if parsed_url.hostname != environment or \ asset_url.groupdict().get('course') != course_key.course or \ asset_url.groupdict().get('org') != course_key.org: asset_info = { 'name': asset_url.groupdict().get('name'), 'module': block_loc, 'available': False } asset_path = '{}{}'.format( StaticContent.get_base_url_path_for_course_assets( course_key), asset_url.groupdict().get('name')) # check if asset exists in this course try: loc = StaticContent.get_location_from_path(asset_path) except (InvalidLocationError, InvalidKeyError): pass else: try: AssetManager.find(loc, as_stream=True) except (ItemNotFoundError, NotFoundError): pass else: asset_info['available'] = True if update: # replace url with the `asset_path` full_asset_path = urljoin( 'https://{}'.format(environment), asset_path) value = value.replace(url, full_asset_path, 1) save_updated = True log.info( '[{}] Replacing `{}` with new path `{}` in module `{}`' .format(task_id, url, full_asset_path, block_loc)) block_assets.append(asset_info) if urls and save_updated and update: dictionary[value_key] = value