Skip to content

Commit 6d9e6c4

Browse files
committed
docs: improve function docstring
1 parent 21a248e commit 6d9e6c4

2 files changed

Lines changed: 27 additions & 8 deletions

File tree

openedx/core/djangoapps/user_api/accounts/api.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,9 @@ def _notify_language_proficiencies_update_if_needed(data, user, user_profile, ol
486486
)
487487

488488

489-
def _update_extended_profile_if_needed(data: dict, user_profile: UserProfile, custom_form: forms.Form) -> None:
489+
def _update_extended_profile_if_needed(
490+
data: dict, user_profile: UserProfile, custom_form: Optional[forms.Form]
491+
) -> None:
490492
"""
491493
Update the extended profile information if present in the data.
492494
@@ -495,12 +497,10 @@ def _update_extended_profile_if_needed(data: dict, user_profile: UserProfile, cu
495497
2. Saves the custom form data to the extended profile model if valid
496498
497499
Args:
498-
data: Dictionary containing the update data, may include 'extended_profile' key
499-
user_profile: The UserProfile instance to update
500-
custom_form: The validated custom form containing extended profile data
501-
502-
Returns:
503-
None
500+
data (dict): Dictionary containing the update data, may include 'extended_profile' key
501+
user_profile (UserProfile): The UserProfile instance to update
502+
custom_form (Optional[forms.Form]): The validated custom form containing extended profile data,
503+
or None if no custom form is provided
504504
505505
Raises:
506506
None: All exceptions are handled internally with appropriate logging

openedx/core/djangoapps/user_api/accounts/serializers.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,26 @@ def validate_new_name(self, new_name):
578578

579579
def get_extended_profile(user_profile: UserProfile) -> list[dict[str, str]]:
580580
"""
581-
Returns the extended user profile fields stored in user_profile.meta
581+
Retrieve extended user profile fields for API serialization.
582+
583+
This function extracts custom profile fields that extend beyond the standard
584+
UserProfile model. It first attempts to get data from a custom extended profile
585+
model (if configured), then falls back to the user_profile.meta JSON field.
586+
The returned data is filtered to include only fields specified in the
587+
'extended_profile_fields' site configuration.
588+
589+
The function supports two data sources:
590+
1. Custom model: If REGISTRATION_EXTENSION_FORM setting points to a form with
591+
a Meta.model, data is retrieved from that model using model_to_dict()
592+
2. Fallback: JSON data stored in UserProfile.meta field
593+
594+
Args:
595+
user_profile (UserProfile): The user profile instance to get extended fields from.
596+
597+
Returns:
598+
list[dict[str, str]]: A list of dictionaries, each containing:
599+
- 'field_name': The name of the extended profile field
600+
- 'field_value': The value of the field (converted to string)
582601
"""
583602
def get_extended_profile_data():
584603
extended_profile_model = get_extended_profile_model()

0 commit comments

Comments
 (0)