openedx.core.lib.xblock_utils package#
Module contents#
Functions that are used to modify XBlock fragments for use in the LMS and Studio
- openedx.core.lib.xblock_utils.add_staff_markup(user, disable_staff_debug_info, block, view, frag, context)#
Updates the supplied block with a new get_html function that wraps the output of the old get_html function with additional information for admin users only, including a histogram of student answers, the definition of the xblock, and a link to view the block in Studio if it is a Studio edited, mongo stored course.
Does nothing if block is a SequenceBlock.
- openedx.core.lib.xblock_utils.get_aside_from_xblock(xblock, aside_type)#
Gets an instance of an XBlock aside from the XBlock that it’s decorating. This also configures the aside instance with the runtime and fields of the given XBlock.
- Parameters:
xblock (xblock.core.XBlock) – The XBlock that the desired aside is decorating
aside_type (str) – The aside type
- Returns:
Instance of an xblock aside
- Return type:
xblock.core.XBlockAside
- openedx.core.lib.xblock_utils.get_course_update_items(course_updates, provided_index=0)#
Returns list of course_updates data dictionaries either from new format if available or from old. This function don’t modify old data to new data (in db), instead returns data in common old dictionary format. New Format: {“items” : [{“id”: computed_id, “date”: date, “content”: html-string}],
“data”: “<ol>[<li><h2>date</h2>content</li>]</ol>”}
Old Format: {“data”: “<ol>[<li><h2>date</h2>content</li>]</ol>”}
- openedx.core.lib.xblock_utils.get_css_dependencies(group)#
Returns list of CSS dependencies belonging to group in settings.PIPELINE[‘STYLESHEETS’].
Respects PIPELINE[‘PIPELINE_ENABLED’] setting.
- openedx.core.lib.xblock_utils.get_icon(block)#
A function that returns the CSS class representing an icon to use for this particular XBlock (in the courseware navigation bar). Mostly used for Vertical/Unit XBlocks. It can be overridden by setting OVERRIDE_GET_UNIT_ICON to an alternative implementation.
- openedx.core.lib.xblock_utils.get_js_dependencies(group)#
Returns list of JS dependencies belonging to group in settings.PIPELINE[‘JAVASCRIPT’].
Respects PIPELINE[‘PIPELINE_ENABLED’] setting.
- openedx.core.lib.xblock_utils.grade_histogram(block_id)#
Print out a histogram of grades on a given problem in staff member debug info.
Warning: If a student has just looked at an xblock and not attempted it, their grade is None. Since there will always be at least one such student this function almost always returns [].
- openedx.core.lib.xblock_utils.hash_resource(resource)#
Hash a :class:`web_fragments.fragment.FragmentResource Those hash values are used to avoid loading the resources multiple times.
- openedx.core.lib.xblock_utils.is_xblock_aside(usage_key)#
Returns True if the given usage key is for an XBlock aside
- Parameters:
usage_key (opaque_keys.edx.keys.UsageKey) – A usage key
- Returns:
Whether or not the usage key is an aside key type
- Return type:
bool
- openedx.core.lib.xblock_utils.request_token(request)#
Return a unique token for the supplied request. This token will be the same for all calls to request_token made on the same request object.
- openedx.core.lib.xblock_utils.sanitize_html_id(html_id)#
Template uses element_id in js function names, so can’t allow dashes and colons.
- openedx.core.lib.xblock_utils.wrap_fragment(fragment, new_content)#
Returns a new Fragment that has new_content and all as its content, and all of the resources from fragment
- openedx.core.lib.xblock_utils.wrap_xblock(runtime_class, block, view, frag, context, usage_id_serializer, request_token, display_name_only=False, extra_data=None)#
Wraps the results of rendering an XBlock view in a standard <section> with identifying data so that the appropriate javascript module can be loaded onto it.
- Parameters:
runtime_class – The name of the javascript runtime class to use to load this block
block – An XBlock (that may be an XModule or XModuleDescriptor)
view – The name of the view that rendered the fragment being wrapped
frag – The
Fragmentto be wrappedcontext – The context passed to the view being rendered
usage_id_serializer – A function to serialize the block’s usage_id for use by the front-end Javascript Runtime.
request_token – An identifier that is unique per-request, so that only xblocks rendered as part of this request will have their javascript initialized.
display_name_only – If true, don’t render the fragment content at all. Instead, just render the display_name of block
extra_data – A dictionary with extra data values to be set on the wrapper
- openedx.core.lib.xblock_utils.wrap_xblock_aside(runtime_class, aside, view, frag, context, usage_id_serializer, request_token, extra_data=None, extra_classes=None)#
Wraps the results of rendering an XBlockAside view in a standard <section> with identifying data so that the appropriate javascript module can be loaded onto it.
- Parameters:
runtime_class – The name of the javascript runtime class to use to load this block
aside – An XBlockAside
view – The name of the view that rendered the fragment being wrapped
frag – The
Fragmentto be wrappedcontext – The context passed to the view being rendered
usage_id_serializer – A function to serialize the block’s usage_id for use by the front-end Javascript Runtime.
request_token – An identifier that is unique per-request, so that only xblocks rendered as part of this request will have their javascript initialized.
extra_data – A dictionary with extra data values to be set on the wrapper
extra_classes – A list with extra classes to be set on the wrapper element
- openedx.core.lib.xblock_utils.xblock_local_resource_url(block, uri)#
Returns the URL for an XBlock’s local resource.
Note: when running with the full Django pipeline, the file will be accessed as a static asset which will use a CDN in production.
- openedx.core.lib.xblock_utils.xblock_resource_pkg(block)#
Return the module name needed to find an XBlock’s shared static assets.
This method will return the full module name that is one level higher than the one the block is in. For instance, problem_builder.answer.AnswerBlock has a __module__ value of ‘problem_builder.answer’. This method will return ‘problem_builder’ instead. However, for edx-ora2’s openassessment.xblock.openassessmentblock.OpenAssessmentBlock, the value returned is ‘openassessment.xblock’.
Built-in edx-platform XBlocks (defined under ./xmodule/) are special cases. They currently use two different mechanisms to load assets: 1. The builtin_assets utilities, which let the blocks add JS and CSS
compiled completely outside of the XBlock pipeline. Used by HtmlBlock, ProblemBlock, and most other built-in blocks currently. Handling for these assets does not interact with this function.
The (preferred) standard XBlock runtime resource loading system, used by LegacyLibraryContentBlock. Handling for these assets does interact with this function.
We hope to migrate to (2) eventually, tracked by: openedx/edx-platform#32618.