Skip to content

Commit

Permalink
refactor: explicitly modify teams configuration object by returning
Browse files Browse the repository at this point in the history
  • Loading branch information
mariajgrimaldi committed Apr 23, 2024
1 parent 0d240e3 commit 740fa7d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
20 changes: 13 additions & 7 deletions cms/djangoapps/models/settings/course_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,10 @@ def validate_and_update_from_json(cls, block, jsondict, user, filter_tabs=True):
did_validate = False
errors.append({'key': key, 'message': err_message, 'model': model})

cls.fill_teams_user_partitions_ids(block, filtered_dict)
teams_config = key_values.get('teams_configuration')
if teams_config:
key_values['teams_configuration'] = cls.fill_teams_user_partitions_ids(block, teams_config)

team_setting_errors = cls.validate_team_settings(filtered_dict)
if team_setting_errors:
errors = errors + team_setting_errors
Expand Down Expand Up @@ -299,26 +302,29 @@ def get_user_partition_id(block, min_partition_id, max_partition_id):
)

@classmethod
def fill_teams_user_partitions_ids(cls, block, settings_dict):
def fill_teams_user_partitions_ids(cls, block, teams_config):
"""
Fill the `user_partition_id` in the team settings if it is not set.
This is used by the Dynamic Team Partition Generator to create the dynamic user partitions
based on the team-sets defined in the course.
"""
if not CONTENT_GROUPS_FOR_TEAMS.is_enabled(block.id):
return
return teams_config

teams_config = TeamsConfig(settings_dict.get('teams_configuration', {}).get('value'))
team_sets = teams_config.teamsets
for team_set in team_sets:
for team_set in teams_config.teamsets:
if not team_set.user_partition_id:
team_set.user_partition_id = cls.get_user_partition_id(
block,
MINIMUM_STATIC_PARTITION_ID,
MYSQL_MAX_INT,
)
teams_config.update_teamsets(team_sets)
return TeamsConfig(
{
**teams_config.cleaned_data,
"team_sets": [team_set.cleaned_data for team_set in teams_config.teamsets],
}
)

@classmethod
def update_from_dict(cls, key_values, block, user, save=True):
Expand Down
13 changes: 0 additions & 13 deletions openedx/core/lib/teams_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,6 @@ def teamsets(self):
seen_ids.add(teamset.teamset_id)
return good_teamsets

def update_teamsets(self, teamsets):
"""
Update the current team-sets configuration with a list of new team-sets.
Args:
teamsets (list of TeamsetConfig): New team-sets to set.
"""
teamsets_key = 'team_sets'
if self._data.get('topics'):
# For backwards compatibility, also check "topics" key.
teamsets_key = 'topics'
self._data[teamsets_key] = [teamset.cleaned_data for teamset in teamsets]

@cached_property
def teamsets_by_id(self):
return {teamset.teamset_id: teamset for teamset in self.teamsets}
Expand Down

0 comments on commit 740fa7d

Please sign in to comment.