Skip to content

Commit

Permalink
refactor: address PR reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
mariajgrimaldi committed Jan 14, 2025
1 parent 350dea3 commit 35ffa69
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 31 deletions.
9 changes: 7 additions & 2 deletions openedx_filters/course_authoring/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ def run_filter(cls, url: str, org: str) -> tuple[str, str]:
Process the inputs using the configured pipeline steps to modify the URL of the page requested by the user.
Arguments:
url (str): the URL of the page to be modified.
org (str): Course org filter used as context data to get LMS configurations.
- url (str): the URL of the page to be modified.
- org (str): Course org filter used as context data to get LMS configurations.
Returns:
tuple[str, str]:
- str: the modified URL of the page requested by the user.
- str: the course org.
"""
data = super().run_pipeline(url=url, org=org)
return data.get("url"), data.get("org")
71 changes: 42 additions & 29 deletions openedx_filters/learning/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import Any, Optional

from django.db.models.query import QuerySet
from django.http import HttpResponse
from django.http import HttpResponse, QueryDict
from opaque_keys.edx.keys import CourseKey

from openedx_filters.exceptions import OpenEdxFilterException
Expand Down Expand Up @@ -102,8 +102,9 @@ def run_filter(cls, context: dict, template_name: str) -> tuple[dict, str]:
- template_name (str): template path used to render the account settings page.
Returns:
- dict: context dictionary for the account settings page, possibly modified.
- str: template name to be rendered by the account settings page, possibly modified.
tuple[dict, str]:
- dict: context dictionary for the account settings page, possibly modified.
- str: template name to be rendered by the account settings page, possibly modified.
"""
data = super().run_pipeline(context=context, template_name=template_name)
return data.get("context"), data.get("template_name")
Expand Down Expand Up @@ -141,15 +142,15 @@ class PreventRegistration(OpenEdxFilterException):
"""

@classmethod
def run_filter(cls, form_data: dict) -> dict:
def run_filter(cls, form_data: QueryDict) -> QueryDict:
"""
Process the registration form data using the configured pipeline steps to modify the registration process.
Arguments:
- form_data (QueryDict): contains the request.data submitted by the registration form.
Returns:
- dict: form data dictionary, possibly modified.
- QueryDict: form data dictionary, possibly modified.
"""
sensitive_data = cls.extract_sensitive_data(form_data)
data = super().run_pipeline(form_data=form_data)
Expand Down Expand Up @@ -458,8 +459,9 @@ def run_filter(cls, context: dict, custom_template: Any) -> tuple[dict, Any]:
- custom_template (CertificateTemplate): custom web certificate template.
Returns:
- dict: context dictionary for the certificate template, possibly modified.
- CertificateTemplate: custom web certificate template, possibly modified.
tuple[dict, CertificateTemplate]:
- dict: context dictionary for the certificate template, possibly modified.
- CertificateTemplate: custom web certificate template, possibly modified.
"""
data = super().run_pipeline(context=context, custom_template=custom_template)
return data.get("context"), data.get("custom_template")
Expand Down Expand Up @@ -500,8 +502,9 @@ def run_filter(cls, current_membership: Any, target_cohort: Any) -> tuple[Any, A
- target_cohort (CourseUserGroup): CourseUserGroup instance representing the new user's cohort.
Returns:
- CohortMembership: CohortMembership instance representing the current user's cohort.
- CourseUserGroup: CourseUserGroup instance representing the new user's cohort.
tuple[CohortMembership, CourseUserGroup]:
- CohortMembership: CohortMembership instance representing the current user's cohort.
- CourseUserGroup: CourseUserGroup instance representing the new user's cohort.
"""
data = super().run_pipeline(current_membership=current_membership, target_cohort=target_cohort)
return data.get("current_membership"), data.get("target_cohort")
Expand Down Expand Up @@ -542,8 +545,9 @@ def run_filter(cls, user: Any, target_cohort: Any) -> tuple[Any, Any]:
- target_cohort (CourseUserGroup): CourseUserGroup instance representing the new user's cohort.
Returns:
- User: Django User object representing the user.
- CourseUserGroup: CourseUserGroup instance representing the new user's cohort.
tuple[User, CourseUserGroup]:
- User: Django User object representing the user.
- CourseUserGroup: CourseUserGroup instance representing the new user's cohort.
"""
data = super().run_pipeline(user=user, target_cohort=target_cohort)
return data.get("user"), data.get("target_cohort")
Expand Down Expand Up @@ -638,8 +642,9 @@ def run_filter(cls, context: dict, template_name: str) -> tuple[dict, str]:
- template_name (str): template name to be rendered by the course about.
Returns:
- dict: context dictionary for the course about template, possibly modified.
- str: template name to be rendered by the course about, possibly modified.
tuple[dict, str]:
- dict: context dictionary for the course about template, possibly modified.
- str: template name to be rendered by the course about, possibly modified.
"""
data = super().run_pipeline(context=context, template_name=template_name)
return data.get("context"), data.get("template_name")
Expand Down Expand Up @@ -735,8 +740,9 @@ def run_filter(cls, context: dict, template_name: str) -> tuple[dict, str]:
- template_name (str): template name to be rendered by the student's dashboard.
Returns:
- dict: context dictionary for the student's dashboard template, possibly modified.
- str: template name to be rendered by the student's dashboard, possibly modified.
tuple[dict, str]:
- dict: context dictionary for the student's dashboard template, possibly modified.
- str: template name to be rendered by the student's dashboard, possibly modified.
"""
data = super().run_pipeline(context=context, template_name=template_name)
return data.get("context"), data.get("template_name")
Expand Down Expand Up @@ -778,8 +784,9 @@ def run_filter(cls, block: Any, context: dict) -> tuple[Any, dict]:
- context (dict): rendering context values like is_mobile_app, show_title..etc
Returns:
- XBlock: the XBlock that is about to be rendered into HTML
- dict: rendering context values like is_mobile_app, show_title..etc
tuple[XBlock, dict]:
- XBlock: the XBlock that is about to be rendered into HTML
- 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")
Expand Down Expand Up @@ -873,8 +880,9 @@ def run_filter(cls, context: dict, student_view_context: dict):
- student_view_context (dict): context passed to the student_view of the block context.
Returns:
- dict: rendering context values like is_mobile_app, show_title, etc.
- dict: context passed to the student_view of the block context.
tuple[dict, dict]:
- dict: rendering context values like is_mobile_app, show_title, etc.
- dict: context passed to the student_view of the block context.
"""
data = super().run_pipeline(context=context, student_view_context=student_view_context)
return data.get("context"), data.get("student_view_context")
Expand Down Expand Up @@ -955,8 +963,9 @@ def run_filter(cls, course_key: CourseKey, course_home_url: str) -> tuple[Course
course_home_url (str): The url string for the course home.
Returns:
CourseKey: The course key for which the home url is being requested.
str: The url string for the course home.
tuple[CourseKey, str]:
CourseKey: The course key for which the home url is being requested.
str: The url string for the course home.
"""
data = super().run_pipeline(course_key=course_key, course_home_url=course_home_url)
return data.get("course_key"), data.get("course_home_url")
Expand Down Expand Up @@ -990,8 +999,9 @@ def run_filter(cls, course_key: CourseKey, serialized_enrollment: dict) -> tuple
- serialized_enrollment (dict): enrollment data.
Returns:
- CourseKey: The course key for which isStarted is being modify.
- dict: enrollment data.
tuple[CourseKey, dict]:
- CourseKey: The course key for which isStarted is being modify.
- dict: enrollment data.
"""
data = super().run_pipeline(course_key=course_key, serialized_enrollment=serialized_enrollment)
return data.get("course_key"), data.get("serialized_enrollment")
Expand Down Expand Up @@ -1119,8 +1129,9 @@ def run_filter(cls, context: dict, template_name: str) -> tuple[dict, str]:
- template_name (str): template name to be rendered by the instructor's tab.
Returns:
- dict: context dictionary for the instructor's tab template, possibly modified.
- str: template name to be rendered by the instructor's tab, possibly modified.
tuple[dict, str]:
- dict: context dictionary for the instructor's tab template, possibly modified.
- str: template name to be rendered by the instructor's tab, possibly modified.
"""
data = super().run_pipeline(context=context, template_name=template_name)
return data.get("context"), data.get("template_name")
Expand Down Expand Up @@ -1175,8 +1186,9 @@ def run_filter(cls, context: dict, template_name: str) -> tuple[dict, str]:
- template_name (str): template name to be rendered by the student's dashboard.
Returns:
- dict: context dictionary for the submission view template, possibly modified.
- str: template name to be rendered by the submission view, possibly modified.
tuple[dict, str]:
- dict: context dictionary for the submission view template, possibly modified.
- str: template name to be rendered by the submission view, possibly modified.
"""
data = super().run_pipeline(context=context, template_name=template_name, )
return data.get("context"), data.get("template_name")
Expand Down Expand Up @@ -1243,8 +1255,9 @@ def run_filter(cls, url: str, org: str) -> tuple[str, str]:
- org (str): Course org filter used as context data to get LMS configurations.
Returns:
- str: the modified URL of the page.
- str: Course org filter used as context data to get LMS configurations
tuple[str, str]:
- str: the modified URL of the page.
- str: Course org filter used as context data to get LMS configurations.
"""
data = super().run_pipeline(url=url, org=org)
return data.get("url"), data.get("org")
Expand Down

0 comments on commit 35ffa69

Please sign in to comment.