From 5021001e789ab3816981a191681bde5c86c146ed Mon Sep 17 00:00:00 2001 From: Maria Grimaldi Date: Tue, 13 Jun 2023 16:53:33 -0400 Subject: [PATCH 1/3] feat: add filter design to modify the instructor dashboard render --- openedx_filters/learning/filters.py | 73 +++++++++++++++++++ .../learning/tests/test_filters.py | 36 +++++++++ 2 files changed, 109 insertions(+) diff --git a/openedx_filters/learning/filters.py b/openedx_filters/learning/filters.py index 4751a88..447d928 100644 --- a/openedx_filters/learning/filters.py +++ b/openedx_filters/learning/filters.py @@ -589,3 +589,76 @@ def run_filter(cls, course_key, course_home_url): """ data = super().run_pipeline(course_key=course_key, course_home_url=course_home_url) return data.get("course_key"), data.get("course_home_url") + + +class InstructorDashboardRenderStarted(OpenEdxPublicFilter): + """ + Custom class used to create instructor dashboard filters and its custom methods. + """ + + filter_type = "org.openedx.learning.instructor.dashboard.render.started.v1" + + class RedirectToPage(OpenEdxFilterException): + """ + Custom class used to stop the instructor dashboard process. + """ + + def __init__(self, message, redirect_to=""): + """ + Override init that defines specific arguments used in the instructor dashboard render process. + + Arguments: + message: error message for the exception. + redirect_to: URL to redirect to. + """ + super().__init__(message, redirect_to=redirect_to) + + class RenderInvalidDashboard(OpenEdxFilterException): + """ + Custom class used to stop the instructor dashboard render process. + """ + + def __init__(self, message, dashboard_template="", template_context=None): + """ + Override init that defines specific arguments used in the instructor dashboard render process. + + Arguments: + message: error message for the exception. + dashboard_template: template path rendered instead. + template_context: context used to the new dashboard_template. + """ + super().__init__( + message, + dashboard_template=dashboard_template, + template_context=template_context, + ) + + class RenderCustomResponse(OpenEdxFilterException): + """ + Custom class used to stop the instructor dashboard rendering process. + """ + + def __init__(self, message, response=None): + """ + Override init that defines specific arguments used in the instructor dashboard render process. + + Arguments: + message: error message for the exception. + response: custom response which will be returned by the dashboard view. + """ + super().__init__( + message, + response=response, + ) + + @classmethod + def run_filter(cls, context, template_name): + """ + Execute a filter with the signature specified. + + Arguments: + context (dict): context dictionary for instructor's tab template. + template_name (str): template name to be rendered by the instructor's tab. + """ + data = super().run_pipeline(context=context, template_name=template_name) + return data.get("context"), data.get("template_name") diff --git a/openedx_filters/learning/tests/test_filters.py b/openedx_filters/learning/tests/test_filters.py index acdcd4d..7b4f770 100644 --- a/openedx_filters/learning/tests/test_filters.py +++ b/openedx_filters/learning/tests/test_filters.py @@ -18,6 +18,7 @@ CourseHomeUrlCreationStarted, CourseUnenrollmentStarted, DashboardRenderStarted, + InstructorDashboardRenderStarted, StudentLoginRequested, StudentRegistrationRequested, VerticalBlockChildRenderStarted, @@ -508,6 +509,41 @@ def test_halt_account_rendering_process(self, AccountSettingsException, attribut self.assertDictContainsSubset(attributes, exception.__dict__) + def test_instructor_dashboard_render_started(self): + """ + Test InstructorDashboardRenderStarted filter behavior under normal conditions. + + Expected behavior: + - The filter must have the signature specified. + - The filter should return context and template_name in that order. + """ + result = InstructorDashboardRenderStarted.run_filter(self.context, self.template_name) + + self.assertTupleEqual((self.context, self.template_name,), result) + + @data( + (InstructorDashboardRenderStarted.RedirectToPage, {"redirect_to": "custom-dashboard.html"}), + ( + InstructorDashboardRenderStarted.RenderInvalidDashboard, + { + "dashboard_template": "custom-dasboard.html", + "template_context": {"course": Mock()}, + } + ), + (InstructorDashboardRenderStarted.RenderCustomResponse, {"response": Mock()}), + ) + @unpack + def test_halt_instructor_dashboard_render(self, dashboard_exception, attributes): + """ + Test for the instructor dashboard exceptions attributes. + + Expected behavior: + - The exception must have the attributes specified. + """ + exception = dashboard_exception(message="You can't access the dashboard", **attributes) + + self.assertDictContainsSubset(attributes, exception.__dict__) + class TestCohortFilters(TestCase): """ From f56956d87931f78c37235846f53051b3000f9800 Mon Sep 17 00:00:00 2001 From: Maria Grimaldi Date: Tue, 18 Jul 2023 11:26:00 -0400 Subject: [PATCH 2/3] refactor: address PR reviews --- openedx_filters/learning/filters.py | 14 +++++++------- openedx_filters/learning/tests/test_filters.py | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/openedx_filters/learning/filters.py b/openedx_filters/learning/filters.py index 447d928..2e7e876 100644 --- a/openedx_filters/learning/filters.py +++ b/openedx_filters/learning/filters.py @@ -600,7 +600,7 @@ class InstructorDashboardRenderStarted(OpenEdxPublicFilter): class RedirectToPage(OpenEdxFilterException): """ - Custom class used to stop the instructor dashboard process. + Custom class used to stop the instructor dashboard render by redirecting to a new page. """ def __init__(self, message, redirect_to=""): @@ -615,27 +615,27 @@ def __init__(self, message, redirect_to=""): class RenderInvalidDashboard(OpenEdxFilterException): """ - Custom class used to stop the instructor dashboard render process. + Custom class used to render a custom template instead of the instructor dashboard. """ - def __init__(self, message, dashboard_template="", template_context=None): + def __init__(self, message, instructor_template="", template_context=None): """ Override init that defines specific arguments used in the instructor dashboard render process. Arguments: message: error message for the exception. - dashboard_template: template path rendered instead. - template_context: context used to the new dashboard_template. + instructor_template: template path rendered instead. + template_context: context used to the new instructor_template. """ super().__init__( message, - dashboard_template=dashboard_template, + instructor_template=instructor_template, template_context=template_context, ) class RenderCustomResponse(OpenEdxFilterException): """ - Custom class used to stop the instructor dashboard rendering process. + Custom class used to stop the instructor dashboard rendering by returning a custom response. """ def __init__(self, message, response=None): diff --git a/openedx_filters/learning/tests/test_filters.py b/openedx_filters/learning/tests/test_filters.py index 7b4f770..cefaf76 100644 --- a/openedx_filters/learning/tests/test_filters.py +++ b/openedx_filters/learning/tests/test_filters.py @@ -526,7 +526,7 @@ def test_instructor_dashboard_render_started(self): ( InstructorDashboardRenderStarted.RenderInvalidDashboard, { - "dashboard_template": "custom-dasboard.html", + "instructor_template": "custom-dasboard.html", "template_context": {"course": Mock()}, } ), From 4f49035cfa89ba6120db2e7d53707b0fa6ee1e8d Mon Sep 17 00:00:00 2001 From: Maria Grimaldi Date: Tue, 18 Jul 2023 11:41:22 -0400 Subject: [PATCH 3/3] docs: update docs for new version --- CHANGELOG.rst | 10 ++++++++++ openedx_filters/__init__.py | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 7bdd933..29d134a 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -13,6 +13,16 @@ Change Log Unreleased ---------- + +[1.4.0] - 2023-07-18 +-------------------- + +Added +~~~~~ + +* InstructorDashboardRenderStarted filter added which can be used to modify the instructor dashboard rendering process. + + [1.3.0] - 2023-05-25 -------------------- diff --git a/openedx_filters/__init__.py b/openedx_filters/__init__.py index 286d400..f6d72db 100644 --- a/openedx_filters/__init__.py +++ b/openedx_filters/__init__.py @@ -3,4 +3,4 @@ """ from openedx_filters.filters import * -__version__ = "1.3.0" +__version__ = "1.4.0"