From 1767838455882d1901e4fdda99aa813694dde27a Mon Sep 17 00:00:00 2001 From: Josh McLaughlin Date: Mon, 19 Apr 2021 07:48:49 -0700 Subject: [PATCH] fix: Use UserProfile.meta for city field if set in the profile information report There are two distinct ways to store a city for users in edx-platform: one directly in UserProfile.city, and another in UserProfile.meta. Depending on configuration, both fields can be used. Though the UserProfile.meta['city'] field is not set unless specifically configured, so we choose this over the UserProfile.city field when generating the student features report. Additional details and discussion available on edx/edx-platform#23171 --- lms/djangoapps/instructor_analytics/basic.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lms/djangoapps/instructor_analytics/basic.py b/lms/djangoapps/instructor_analytics/basic.py index fefe8324a8a9..afce0620aab0 100644 --- a/lms/djangoapps/instructor_analytics/basic.py +++ b/lms/djangoapps/instructor_analytics/basic.py @@ -97,6 +97,7 @@ def enrolled_students_features(course_key, features): """ include_cohort_column = 'cohort' in features include_team_column = 'team' in features + include_city_column = 'city' in features include_enrollment_mode = 'enrollment_mode' in features include_verification_status = 'verification_status' in features include_program_enrollments = 'external_user_key' in features @@ -152,6 +153,13 @@ def extract_student(student, features): for meta_feature, meta_key in meta_features: student_dict[meta_feature] = meta_dict.get(meta_key) + # There are two separate places where the city value can be stored, + # one used by account settings and the other used by the registration form. + # If the account settings value (meta.city) is set, it takes precedence. + meta_city = meta_dict.get('city') + if include_city_column and meta_city: + student_dict['city'] = meta_city + if include_cohort_column: # Note that we use student.course_groups.all() here instead of # student.course_groups.filter(). The latter creates a fresh query,