From 38d350f48c726820779a73a372b6598b49111086 Mon Sep 17 00:00:00 2001 From: "Kyle D. McCormick" Date: Tue, 19 Mar 2024 12:11:11 -0400 Subject: [PATCH] docs: document XBLOCK_MIXINS and XBLOCK_EXTRA_MIXINS --- cms/envs/common.py | 17 ++++++++++++++--- lms/envs/common.py | 24 ++++++++++++++++++++---- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/cms/envs/common.py b/cms/envs/common.py index a33c415789bd..9c9d900a1af9 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -995,16 +995,27 @@ from xmodule.modulestore.inheritance import InheritanceMixin from xmodule.x_module import XModuleMixin -# These are the Mixins that should be added to every XBlock. -# This should be moved into an XBlock Runtime/Application object -# once the responsibility of XBlock creation is moved out of modulestore - cpennington +# These are the Mixins that will be added to every Blocklike upon instantiation. +# DO NOT EXPAND THIS LIST!! We want it eventually to be EMPTY. Why? Because dynamically adding functions/behaviors to +# objects at runtime is confusing for both developers and static tooling (pylint/mypy). Instead... +# - to add special Blocklike behaviors just for your site: override `XBLOCK_EXTRA_MIXINS` with your own XBlockMixins. +# - to add new functionality to all Blocklikes: add it to the base Blocklike class in the core openedx/XBlock repo. XBLOCK_MIXINS = ( + # TODO: For each of these, either + # (a) merge their functionality into the base Blocklike class, or + # (b) refactor their functionality out of the Blocklike objects and into the edx-platform block runtimes. LmsBlockMixin, InheritanceMixin, XModuleMixin, EditInfoMixin, AuthoringMixin, ) + +# .. setting_name: XBLOCK_EXTRA_MIXINS +# .. setting_default: () +# .. setting_description: Custom mixins that will be dynamically added to every XBlock and XBlockAside instance. +# These can be classes or dotted-path references to classes. +# For example: `XBLOCK_EXTRA_MIXINS = ('my_custom_package.my_module.MyCustomMixin',)` XBLOCK_EXTRA_MIXINS = () # Paths to wrapper methods which should be applied to every XBlock's FieldData. diff --git a/lms/envs/common.py b/lms/envs/common.py index 27e689035204..30ba71f62aad 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -1640,12 +1640,28 @@ def _make_mako_template_dirs(settings): from xmodule.modulestore.inheritance import InheritanceMixin # lint-amnesty, pylint: disable=wrong-import-order, wrong-import-position from xmodule.x_module import XModuleMixin # lint-amnesty, pylint: disable=wrong-import-order, wrong-import-position -# These are the Mixins that should be added to every XBlock. -# 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) +# These are the Mixins that will be added to every Blocklike upon instantiation. +# DO NOT EXPAND THIS LIST!! We want it eventually to be EMPTY. Why? Because dynamically adding functions/behaviors to +# objects at runtime is confusing for both developers and static tooling (pylint/mypy). Instead... +# - to add special Blocklike behaviors just for your site: override `XBLOCK_EXTRA_MIXINS` with your own XBlockMixins. +# - to add new functionality to all Blocklikes: add it to the base Blocklike class in the core openedx/XBlock repo. +XBLOCK_MIXINS = ( + # TODO: For each of these, either + # (a) merge their functionality into the base Blocklike class, or + # (b) refactor their functionality out of the Blocklike objects and into the edx-platform block runtimes. + LmsBlockMixin, + InheritanceMixin, + XModuleMixin, + EditInfoMixin, +) if SkillTaggingMixin: XBLOCK_MIXINS += (SkillTaggingMixin,) + +# .. setting_name: XBLOCK_EXTRA_MIXINS +# .. setting_default: () +# .. setting_description: Custom mixins that will be dynamically added to every XBlock and XBlockAside instance. +# These can be classes or dotted-path references to classes. +# For example: `XBLOCK_EXTRA_MIXINS = ('my_custom_package.my_module.MyCustomMixin',)` XBLOCK_EXTRA_MIXINS = () # .. setting_name: XBLOCK_FIELD_DATA_WRAPPERS