Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add filter design to modify the instructor dashboard render #96

Merged
merged 3 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[seeking advice] should we use: org.openedx.learning.instructor_dashboard.render.started.v1 instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have used "." for separating "course.enrollment" in the past. I think here it's the same kind of separation and thus "." is correct.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here for the docs! Thanks for the help :)


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