Skip to content

Commit

Permalink
feat: add gender choices patch
Browse files Browse the repository at this point in the history
This limits the gender options to Male and Female, and also includes a new pipeline flow for the methods that must run after the app registration
  • Loading branch information
andrey-canon committed Jul 24, 2023
1 parent d8c831a commit 2dd392c
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
3 changes: 3 additions & 0 deletions eox_nelp/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

from django.apps import AppConfig

from eox_nelp.init_pipeline import run_init_pipeline


class EoxNelpConfig(AppConfig):
"""
Expand Down Expand Up @@ -56,6 +58,7 @@ def ready(self):
# pylint: disable=unused-import, import-error, import-outside-toplevel
# This is required in order to register the receiver inside handlers module.
from cms.djangoapps.contentstore.signals import handlers # noqa: F401
run_init_pipeline()


class EoxNelpCMSConfig(AppConfig):
Expand Down
15 changes: 14 additions & 1 deletion eox_nelp/edxapp_wrapper/backends/student_m_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
This file contains all the necessary student dependencies from
https://github.com/eduNEXT/edunext-platform/tree/ednx-release/mango.master/common/djangoapps/student
"""
from common.djangoapps.student.models import CourseAccessRole, CourseEnrollment # pylint: disable=import-error
from common.djangoapps.student.models import ( # pylint: disable=import-error
CourseAccessRole,
CourseEnrollment,
UserProfile,
)


def get_course_enrollment_model():
Expand All @@ -21,3 +25,12 @@ def get_course_access_role_model():
CourseAccessRole Model.
"""
return CourseAccessRole


def get_user_profile_model():
"""Allow to get the UserProfile Model from
https://github.com/eduNEXT/edunext-platform/blob/ednx-release/mango.master/common/djangoapps/student/models.py#L478
Returns:
UserProfile Model.
"""
return UserProfile
1 change: 1 addition & 0 deletions eox_nelp/edxapp_wrapper/student.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@

CourseEnrollment = backend.get_course_enrollment_model()
CourseAccessRole = backend.get_course_access_role_model()
UserProfile = backend.get_user_profile_model()
8 changes: 8 additions & 0 deletions eox_nelp/edxapp_wrapper/test_backends/student_m_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,11 @@ def get_course_access_role_model():
Mock class.
"""
return Mock()


def get_user_profile_model():
"""Return test Model.
Returns:
Mock class.
"""
return Mock()
32 changes: 32 additions & 0 deletions eox_nelp/init_pipeline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
This file contains all the processes that must run after app registration.
Functions:
run_init_pipeline: Wrapper for all the init methods, this avoids to import methods outside this file.
patch_user_gender_choices: Change the current openedx gender options (Male, Female, Other)
"""
from django.utils.translation import gettext_noop


def run_init_pipeline():
"""
Executes multiple processes that must run before starting the django application.
"""
patch_user_gender_choices()


def patch_user_gender_choices():
"""
This overwrites the available gender choices in order to allow the Male and Female options.
"""
# pylint: disable=import-error, import-outside-toplevel
# This cannot be at the top of the file since this file is imported the plugin initialization
# and therefore the settings has not been set yet
from eox_nelp.edxapp_wrapper.student import UserProfile

UserProfile.GENDER_CHOICES = (
('m', gettext_noop('Male')),
('f', gettext_noop('Female')),
)

0 comments on commit 2dd392c

Please sign in to comment.