Skip to content
Closed
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
43 changes: 43 additions & 0 deletions openedx_filters/learning/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,3 +422,46 @@ 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 XBlockRenderStarted(OpenEdxPublicFilter):
"""
Custom class to change the XBlock Fragment of the units before rendering it to response

Arguments:
context (dict): contains the full context object that will be rendered in the
template_name (str): path to the template being used for rendering the XBlock
defaults to `lms/templates/courseware/courseware-chromeless.html`
"""

filter_type = "org.openedx.learning.xblock.render.started.v1"

class RenderCustomReponse(OpenEdxFilterException):
"""
Custom class used to stop the XBlock rendering process
"""
def __init__(self, message, response=None):
"""
Override init that defines specific arguments used in the XBlock render process.

Arguments:
message: error message for the exception.
response: custom response which will be returned by the render_xblock view.
"""
super().__init__( message, response=response)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I know these kinds of warnings are cumbersome, but to mitigate them you can follow these tests examples


@classmethod
def run_filter(cls, block, context, template_name):
"""
Execute the filter with the context.

Arguments:
block (VerticalBlock): The VerticalBlock containing the XBlocks to be
rendered
context (dict): the xblock rendering context with fragment and all other
related values.
template_name (str): the name of the template that will render the final
view
"""
data = super().run_pipeline(block=block, context=context, template_name=template_name)
return data.get("context"), data.get("template_name")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

And here you can follow this one