Skip to content

Commit

Permalink
feat: add filter design to modify the instructor dashboard render (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
mariajgrimaldi authored Jul 18, 2023
1 parent ac4befd commit c982791
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 1 deletion.
10 changes: 10 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------------

Expand Down
2 changes: 1 addition & 1 deletion openedx_filters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"""
from openedx_filters.filters import *

__version__ = "1.3.0"
__version__ = "1.4.0"
73 changes: 73 additions & 0 deletions openedx_filters/learning/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 render by redirecting to a new page.
"""

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 render a custom template instead of the instructor dashboard.
"""

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.
instructor_template: template path rendered instead.
template_context: context used to the new instructor_template.
"""
super().__init__(
message,
instructor_template=instructor_template,
template_context=template_context,
)

class RenderCustomResponse(OpenEdxFilterException):
"""
Custom class used to stop the instructor dashboard rendering by returning a custom response.
"""

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")
36 changes: 36 additions & 0 deletions openedx_filters/learning/tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
CourseHomeUrlCreationStarted,
CourseUnenrollmentStarted,
DashboardRenderStarted,
InstructorDashboardRenderStarted,
StudentLoginRequested,
StudentRegistrationRequested,
VerticalBlockChildRenderStarted,
Expand Down Expand Up @@ -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,
{
"instructor_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):
"""
Expand Down

0 comments on commit c982791

Please sign in to comment.