Skip to content

Commit 5d5c68f

Browse files
committed
feat: Add a filter for changing the course about page URL.
1 parent cb4152c commit 5d5c68f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

backend/sample_plugin/pipeline.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import logging
2+
import re
3+
4+
from openedx_filters.filters import PipelineStep
5+
6+
logger = logging.getLogger(__name__)
7+
8+
9+
class ChangeCourseAboutPageUrl(PipelineStep):
10+
def run_filter(self, url, org, **kwargs):
11+
"""
12+
The `run_filter` function must return eiter a dictonary with keys matching the names of the params passed in, or
13+
none. More info can be found in the run_filter base docs:
14+
https://docs.openedx.org/projects/openedx-filters/en/latest/reference/filters-tooling.html#openedx_filters.filters.PipelineStep.run_filter
15+
"""
16+
17+
# Extract the course ID from the existing URL
18+
pattern = r'(?P<course_id>course-v1:[^/]+)'
19+
20+
match = re.search(pattern, url)
21+
if match:
22+
course_id = match.group('course_id')
23+
new_url = f"https://example.com/new_about_page/{course_id}"
24+
logging.debug(f"Replacing old course about url for {course_id} with a different site.")
25+
return {"url": new_url, "org": org}
26+
27+
data = {"url": url, "org": org}
28+
return data

0 commit comments

Comments
 (0)