feat: allow overriding unit icons (#21433)

This:
1. Introduces a new override using the `pluggable_override` decorator.
It is now possible to specify a custom way of getting XBlock's icon
by defining `GET_UNIT_ICON_IMPL` in settings.
2. Introduces a way to add custom `XBLOCK_MIXINS` by defining
`XBLOCK_EXTRA_MIXINS` in settings. This allows, e.g. to add
new fields to XBlocks.
This commit is contained in:
Piotr Surowiec
2021-04-07 15:42:12 +02:00
committed by GitHub
parent 3d20c848f8
commit bc1e9afe4b
7 changed files with 26 additions and 3 deletions

View File

@@ -692,6 +692,9 @@ class SequenceBlock(
display_items. Returns a list of dict objects with information about
the given display_items.
"""
# Avoid circular imports.
from openedx.core.lib.xblock_utils import get_icon
render_items = not context.get('exclude_units', False)
is_user_authenticated = self.is_user_authenticated(context)
completion_service = self.runtime.service(self, 'completion')
@@ -708,8 +711,7 @@ class SequenceBlock(
]
contents = []
for item in display_items:
# NOTE (CCB): This seems like a hack, but I don't see a better method of determining the type/category.
item_type = item.get_icon_class()
item_type = get_icon(item)
usage_id = item.scope_ids.usage_id
show_bookmark_button = False

View File

@@ -134,6 +134,9 @@ Here are the different integration points that python plugins can use:
* - XBlock unit tests (``xblock.test.v0``)
- Assess, Limited
- XBlocks can also install test code that will then be run alongside the platform's usual python unit tests. It's unclear how well-supported this is at the moment.
* - Pluggable override (``edx_django_utils.plugins.pluggable_override.pluggable_override``)
- Trial, Stable
- This decorator allows overriding any function or method by pointing to an alternative implementation in settings. Read the |pluggable_override docstring|_ to learn more.
.. _Application: https://docs.djangoproject.com/en/3.0/ref/applications/
.. _Django app plugin documentation: https://github.com/edx/edx-platform/blob/master/openedx/core/djangoapps/plugins/README.rst
@@ -146,6 +149,8 @@ Here are the different integration points that python plugins can use:
.. _learning_context.py: https://github.com/edx/edx-platform/blob/master/openedx/core/djangoapps/xblock/learning_context/learning_context.py
.. |UserPartition docstring| replace:: ``UserPartition`` docstring
.. _UserPartition docstring: https://github.com/edx/edx-platform/blob/f8cc58618a39c9f7b8e9e1001eb2d7a10395797e/common/lib/xmodule/xmodule/partitions/partitions.py#L105-L120
.. |pluggable_override docstring| replace:: ``pluggable_override`` docstring
.. _pluggable_override docstring: https://github.com/edx/edx-django-utils/blob/master/edx_django_utils/plugins/pluggable_override.py
Platform Look & Feel
====================

View File

@@ -563,6 +563,7 @@ VIDEO_UPLOAD_PIPELINE:
ROOT_PATH: ''
WIKI_ENABLED: true
WRITABLE_GRADEBOOK_URL: null
XBLOCK_EXTRA_MIXINS: []
XBLOCK_FS_STORAGE_BUCKET: null
XBLOCK_FS_STORAGE_PREFIX: null
XBLOCK_SETTINGS: {}

View File

@@ -1424,6 +1424,7 @@ from xmodule.x_module import XModuleMixin
# This should be moved into an XBlock Runtime/Application object
# once the responsibility of XBlock creation is moved out of modulestore - cpennington
XBLOCK_MIXINS = (LmsBlockMixin, InheritanceMixin, XModuleMixin, EditInfoMixin)
XBLOCK_EXTRA_MIXINS = ()
# .. setting_name: XBLOCK_SELECT_FUNCTION
# .. setting_default: prefer_xmodules

View File

@@ -1047,3 +1047,6 @@ EXPLICIT_QUEUES = {
}
LOGO_IMAGE_EXTRA_TEXT = ENV_TOKENS.get('LOGO_IMAGE_EXTRA_TEXT', '')
############## XBlock extra mixins ############################
XBLOCK_MIXINS += tuple(XBLOCK_EXTRA_MIXINS)

View File

@@ -19,6 +19,7 @@ from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imp
from django.contrib.staticfiles.storage import staticfiles_storage
from django.urls import reverse
from django.utils.html import escape
from edx_django_utils.plugins import pluggable_override
from lxml import etree, html
from opaque_keys.edx.asides import AsideUsageKeyV1, AsideUsageKeyV2
from pytz import UTC
@@ -554,3 +555,13 @@ def hash_resource(resource):
else:
md5.update(repr(data).encode('utf-8'))
return md5.hexdigest()
@pluggable_override('OVERRIDE_GET_UNIT_ICON')
def 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 `GET_UNIT_ICON_IMPL` to an alternative implementation.
"""
return block.get_icon_class()

View File

@@ -78,7 +78,7 @@ edx-celeryutils
edx-completion
edx-django-release-util # Release utils for the edx release pipeline
edx-django-sites-extensions
edx-django-utils>=3.12.0 # Utilities for cache, monitoring, and plugins; 3.12.0+ for set_code_owner_attribute method
edx-django-utils>=3.16.0 # Utilities for cache, monitoring, and plugins; 3.16.0+ for the `pluggable_override`
edx-drf-extensions
edx-enterprise
edx-event-routing-backends