Skip to content

Commit

Permalink
feat: add example for AccountSettingsRenderStarted filter (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Henrrypg authored Mar 6, 2023
1 parent 1625f7c commit 5e6f82b
Show file tree
Hide file tree
Showing 10 changed files with 301 additions and 266 deletions.
42 changes: 35 additions & 7 deletions openedx_filters_samples/samples/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@
from django.http import HttpResponse
from openedx_filters import PipelineStep
from openedx_filters.learning.filters import (
AccountSettingsRenderStarted,
CertificateCreationRequested,
CertificateRenderStarted,
CohortAssignmentRequested,
CohortChangeRequested,
CourseAboutRenderStarted,
CourseEnrollmentStarted,
CourseUnenrollmentStarted,
DashboardRenderStarted,
StudentLoginRequested,
StudentRegistrationRequested,
CohortAssignmentRequested,
)


Expand Down Expand Up @@ -120,7 +121,7 @@ class ModifyCertificateModeBeforeCreation(PipelineStep):
}
}
"""
def run_filter(self, user, course_id, mode, status, *args, **kwargs): # pylint: disable=arguments-differ, unused-argument
def run_filter(self, user, course_id, mode, status, *args, **kwargs): # pylint: disable=arguments-differ
if mode == 'honor':
return {
'mode': 'no-id-professional',
Expand Down Expand Up @@ -196,7 +197,7 @@ def run_filter(self, current_membership, target_cohort, *args, **kwargs): # pyl
user = current_membership.user
user.profile.set_meta(
{
"cohort_info": f"Changed from Cohort {str(current_membership.course_user_group)} to Cohort {str(target_cohort)}"
"cohort_info": f"Changed from Cohort {str(current_membership.course_user_group)} to Cohort {str(target_cohort)}" # pylint: disable=line-too-long
}
)
user.profile.save()
Expand Down Expand Up @@ -243,7 +244,7 @@ class StopEnrollment(PipelineStep):
}
"""

def run_filter(self, *args, **kwargs): # pylint: disable=arguments-differ
def run_filter(self, *args, **kwargs):
raise CourseEnrollmentStarted.PreventEnrollment("You can't enroll on this course.")


Expand All @@ -265,7 +266,7 @@ class StopRegister(PipelineStep):
}
"""

def run_filter(self, *args, **kwargs): # pylint: disable=arguments-differ
def run_filter(self, *args, **kwargs):
raise StudentRegistrationRequested.PreventRegistration("You can't register on this site.", status_code=403)


Expand Down Expand Up @@ -642,7 +643,7 @@ def run_filter(self, context, custom_template): # pylint: disable=arguments-dif
Pipeline steps that gets or creates a new custom template to render instead
of the original.
"""
from opaque_keys.edx.keys import CourseKey
from opaque_keys.edx.keys import CourseKey # pylint: disable=import-outside-toplevel

course_key = CourseKey.from_string(context["course_id"])
custom_template = self._get_or_create_custom_template(mode='honor', course_key=course_key)
Expand All @@ -652,7 +653,7 @@ def _get_or_create_custom_template(self, org_id=None, mode=None, course_key=None
"""
Creates a custom certificate template entry in DB.
"""
from lms.djangoapps.certificates.models import CertificateTemplate
from lms.djangoapps.certificates.models import CertificateTemplate # pylint: disable=E0401, C0415

template_html = """
<%namespace name='static' file='static_content.html'/>
Expand Down Expand Up @@ -751,3 +752,30 @@ def run_filter(self, context, template_name): # pylint: disable=arguments-diffe
return {
"context": context, template_name: template_name,
}


class StopAccountSettingsRender(PipelineStep):
"""
Stop account settings render process raising RedirectToPage exception.
Example usage:
Add the following configurations to your configuration file:
"OPEN_EDX_FILTERS_CONFIG": {
"org.openedx.learning.student.settings.render.started.v1": {
"fail_silently": false,
"pipeline": [
"openedx_filters_samples.samples.pipeline.StopAccountSettingsRender"
]
}
},
"""
def run_filter(self, context, *args, **kwargs): # pylint: disable=arguments-differ
"""
Pipeline step that stop access to account settings page.
"""
raise AccountSettingsRenderStarted.RedirectToPage(
"You can't access to account settings.",
redirect_to="",
)
3 changes: 1 addition & 2 deletions pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ enable =
wrong-spelling-in-comment,
wrong-spelling-in-docstring,

unused-argument,
unused-import,
unused-variable,

Expand Down Expand Up @@ -383,7 +382,7 @@ disable =
unicode-builtin,
unpacking-in-except,
xrange-builtin,

unused-argument,
logging-fstring-interpolation,
invalid-name,
django-not-configured,
Expand Down
18 changes: 9 additions & 9 deletions requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
#
# This file is autogenerated by pip-compile with python 3.8
# This file is autogenerated by pip-compile with python 3.10
# To update, run:
#
# make upgrade
#
asgiref==3.5.0
asgiref==3.6.0
# via django
django==3.2.12
django==3.2.18
# via
# -c https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt
# -r requirements/base.in
# openedx-filters
edx-opaque-keys[django]==2.3.0
# via -r requirements/base.in
openedx-filters==0.6.0
openedx-filters==1.2.0
# via -r requirements/base.in
pbr==5.8.1
pbr==5.11.1
# via stevedore
pymongo==3.12.3
pymongo==3.13.0
# via edx-opaque-keys
pytz==2022.1
pytz==2022.7.1
# via django
sqlparse==0.4.2
sqlparse==0.4.3
# via django
stevedore==3.5.0
stevedore==5.0.0
# via edx-opaque-keys
38 changes: 18 additions & 20 deletions requirements/ci.txt
Original file line number Diff line number Diff line change
@@ -1,46 +1,44 @@
#
# This file is autogenerated by pip-compile with python 3.8
# This file is autogenerated by pip-compile with python 3.10
# To update, run:
#
# make upgrade
#
certifi==2021.10.8
certifi==2022.12.7
# via requests
charset-normalizer==2.0.12
charset-normalizer==3.0.1
# via requests
codecov==2.1.12
# via -r requirements/ci.in
coverage==6.3.2
coverage==7.2.1
# via codecov
distlib==0.3.4
distlib==0.3.6
# via virtualenv
filelock==3.6.0
filelock==3.9.0
# via
# tox
# virtualenv
idna==3.3
idna==3.4
# via requests
packaging==21.3
packaging==23.0
# via tox
platformdirs==2.5.1
platformdirs==3.0.0
# via virtualenv
pluggy==1.0.0
# via tox
py==1.11.0
# via tox
pyparsing==3.0.7
# via packaging
requests==2.27.1
requests==2.28.2
# via codecov
six==1.16.0
# via
# tox
# virtualenv
toml==0.10.2
# via tox
tox==3.24.5
# via -r requirements/ci.in
urllib3==1.26.9
tomli==2.0.1
# via tox
tox==3.28.0
# via
# -c https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt
# -r requirements/ci.in
urllib3==1.26.14
# via requests
virtualenv==20.14.0
virtualenv==20.20.0
# via tox
Loading

0 comments on commit 5e6f82b

Please sign in to comment.