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 schedule queryset requested filter #235

Merged
merged 7 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ Unreleased
----------
* Configuration for automatic filters docs generation.


[1.12.0] - 2024-12-10
---------------------

Added
~~~~~

* ScheduleQuerySetRequested filter added which can be used to modify the Schedule QuerySet.

[1.11.0] - 2024-09-30
---------------------

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.11.0"
__version__ = "1.12.0"
28 changes: 28 additions & 0 deletions openedx_filters/learning/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from typing import Optional

from django.db.models.query import QuerySet

from openedx_filters.exceptions import OpenEdxFilterException
from openedx_filters.tooling import OpenEdxPublicFilter
from openedx_filters.utils import SensitiveDataManagementMixin
Expand Down Expand Up @@ -818,3 +820,29 @@ def run_filter(cls, url, org):
"""
data = super().run_pipeline(url=url, org=org)
return data.get("url"), data.get("org")


class ScheduleQuerySetRequested(OpenEdxPublicFilter):
"""
Filter class designed to apply additional filtering to a given QuerySet of Schedules.
mariajgrimaldi marked this conversation as resolved.
Show resolved Hide resolved
"""

filter_type = "org.openedx.learning.schedule.queryset.requested.v1"

@classmethod
def run_filter(cls, schedules: QuerySet) -> QuerySet:
"""
Execute the filtering logic for the given QuerySet of schedules.

This method processes the input QuerySet using the configured pipeline steps
to applies additional filtering rules. It returns the filtered QuerySet for
further processing.

Arguments:
schedules (QuerySet): The original QuerySet of schedules to be filtered.

Returns:
QuerySet: A refined QuerySet of schedules after applying the filter.
"""
data = super().run_pipeline(schedules=schedules)
return data.get("schedules")
24 changes: 24 additions & 0 deletions openedx_filters/learning/tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
InstructorDashboardRenderStarted,
ORASubmissionViewRenderStarted,
RenderXBlockStarted,
ScheduleQuerySetRequested,
StudentLoginRequested,
StudentRegistrationRequested,
VerticalBlockChildRenderStarted,
Expand Down Expand Up @@ -776,3 +777,26 @@ def test_lms_page_url_requested(self):

self.assertEqual(url, url_result)
self.assertEqual(org, org_result)


@ddt
class TestScheduleFilters(TestCase):
"""
Test class to verify standard behavior of the schedule filters.

You'll find test suites for:
- `ScheduleQuerySetRequested`
"""

def test_schedule_requested(self):
"""
Test schedule requested filter.

Expected behavior:
- The filter should return the filtered schedules.
"""
schedules = Mock()

result = ScheduleQuerySetRequested.run_filter(schedules)

self.assertEqual(schedules, result)
Loading