From 62663a7aff7d1b73fb61843394174d9cf2393703 Mon Sep 17 00:00:00 2001 From: Arunmozhi Date: Sat, 23 Jul 2022 23:36:35 +0530 Subject: [PATCH] feat: adds the VerticalBlockChildRenderStarted filter This adds the VerticalBlockChildRenderStarted filter which passes the child XBlock and it's rendering context dictionary to the filter allowing the filter pipeline to alter the content of the XBlock based on the context. Private-ref: https://gitlab.com/mooc-floss/mooc-floss/-/issues/112 --- CHANGELOG.rst | 7 ++++++ openedx_filters/__init__.py | 2 +- openedx_filters/learning/filters.py | 20 +++++++++++++++++ .../learning/tests/test_filters.py | 22 +++++++++++++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index faf610a7..2a6d663b 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -13,6 +13,13 @@ Change Log Unreleased ~~~~~~~~~~ +[0.8.0] - 2022-08-18 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Added +_____ + +* VerticalBlockChildRenderStarted filter added that is called when every child block of a VericalBlock is about to be rendered. [0.7.0] - 2022-05-26 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/openedx_filters/__init__.py b/openedx_filters/__init__.py index 770d93c1..94cdce39 100644 --- a/openedx_filters/__init__.py +++ b/openedx_filters/__init__.py @@ -3,4 +3,4 @@ """ from openedx_filters.filters import * -__version__ = "0.7.0" +__version__ = "0.8.0" diff --git a/openedx_filters/learning/filters.py b/openedx_filters/learning/filters.py index d789f601..6bbdb858 100644 --- a/openedx_filters/learning/filters.py +++ b/openedx_filters/learning/filters.py @@ -422,3 +422,23 @@ def run_filter(cls, context, template_name): """ data = super().run_pipeline(context=context, template_name=template_name) return data.get("context"), data.get("template_name") + + +class VerticalBlockChildRenderStarted(OpenEdxPublicFilter): + """ + Custom class used to create vertical block children's render filters. + """ + + filter_type = "org.openedx.learning.vertical_block_child.render.started.v1" + + @classmethod + def run_filter(cls, block, context): + """ + Execute a filter with the signature specified. + + Arguments: + block (XBlock): the XBlock that is about to be rendered into HTML + context (dict): rendering context values like is_mobile_app, show_title..etc + """ + data = super().run_pipeline(block=block, context=context) + return data.get("block"), data.get("context") diff --git a/openedx_filters/learning/tests/test_filters.py b/openedx_filters/learning/tests/test_filters.py index 1eb79391..a3f6d8d8 100644 --- a/openedx_filters/learning/tests/test_filters.py +++ b/openedx_filters/learning/tests/test_filters.py @@ -17,6 +17,7 @@ DashboardRenderStarted, StudentLoginRequested, StudentRegistrationRequested, + VerticalBlockChildRenderStarted, ) @@ -272,6 +273,7 @@ class TestRenderingFilters(TestCase): - CourseAboutRenderStarted - DashboardRenderStarted + - VerticalBlockChildRenderStarted """ def setUp(self): @@ -354,6 +356,26 @@ def test_halt_course_about_render(self, course_about_exception, attributes): self.assertDictContainsSubset(attributes, exception.__dict__) + def test_verticalblock_child_render_started(self): + """ + Test VerticalBlockChildRenderStarted filter behavior under normal conditions. + + Expected behavior: + - The filter must have the signature specified. + - The filter should return the child block and its context in that order. + """ + block = Mock("child_block") + context = { + "is_mobile_view": False, + "username": "edx", + "child_of_veritcal": True, + "bookmarked": False + } + + result = VerticalBlockChildRenderStarted.run_filter(block, context) + + self.assertTupleEqual((block, context,), result) + class TestCohortFilters(TestCase): """