From ee93e967a9030788ee5a610978cbe18ec9a1ad04 Mon Sep 17 00:00:00 2001 From: Ivo Branco Date: Wed, 11 Mar 2026 16:32:22 +0000 Subject: [PATCH] refactor: Extract get_additional_student_profile_attributes function Extract the configuration_helpers.get_value_for_org() call for fetching additional student profile attributes into a dedicated function to eliminate code duplication between instructor_analytics.basic and instructor.views.api. fccn/nau-technical#797 --- lms/djangoapps/instructor/views/api.py | 5 +--- lms/djangoapps/instructor_analytics/basic.py | 26 +++++++++++++++++--- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/lms/djangoapps/instructor/views/api.py b/lms/djangoapps/instructor/views/api.py index 90a0076782..179c7ade41 100644 --- a/lms/djangoapps/instructor/views/api.py +++ b/lms/djangoapps/instructor/views/api.py @@ -1493,10 +1493,7 @@ def post(self, request, course_id, csv=False): # pylint: disable=redefined-oute 'enrollment_date', ] - additional_attributes = configuration_helpers.get_value_for_org( - course_key.org, - "additional_student_profile_attributes" - ) + additional_attributes = instructor_analytics_basic.get_additional_student_profile_attributes(course_key) if additional_attributes: # Fail fast: must be list/tuple of strings. if not isinstance(additional_attributes, (list, tuple)): diff --git a/lms/djangoapps/instructor_analytics/basic.py b/lms/djangoapps/instructor_analytics/basic.py index 1b06907cbf..75b042b90e 100644 --- a/lms/djangoapps/instructor_analytics/basic.py +++ b/lms/djangoapps/instructor_analytics/basic.py @@ -141,10 +141,7 @@ def get_employment_status(self): Returns: tuple: Combined tuple of standard STUDENT_FEATURES and custom attributes """ - additional_attributes = configuration_helpers.get_value_for_org( - course_key.org, - "additional_student_profile_attributes" - ) + additional_attributes = get_additional_student_profile_attributes(course_key) if additional_attributes: return STUDENT_FEATURES + tuple(additional_attributes) @@ -152,6 +149,27 @@ def get_employment_status(self): return STUDENT_FEATURES +def get_additional_student_profile_attributes(course_key): + """ + Return list of additional student profile attributes configured for the course organization. + + This function retrieves any custom student profile attributes that have been configured for + a specific course organization. These attributes can be used to extend the standard set of + student features included in analytics exports. + + Args: + course_key: CourseKey object for the course + + Returns: + list: List of additional student profile attributes configured for the course organization + """ + return configuration_helpers.get_value_for_org( + course_key.org, + "additional_student_profile_attributes", + default=[] + ) + + def get_available_features(course_key): """ Return all available features including custom student attributes for a course.