def add_user_to_team(self, user_row): """ Creates a CourseTeamMembership entry - i.e: a relationship between a user and a team. user_row is a dictionary where key is column name and value is the row value. {'mode': ' masters','topic_0': '','topic_1': 'team 2','topic_2': None,'user': <user_obj>} andrew,masters,team1,,team3 joe,masters,,team2,team3 """ user = user_row['user'] for teamset_id in self.teamset_ids: team_name = user_row[teamset_id] if not team_name: continue if (team_name, teamset_id) not in self.existing_course_teams: team = CourseTeam.create(name=team_name, course_id=self.course.id, description='Import from csv', topic_id=teamset_id) team.save() team.add_user(user) emit_team_event( 'edx.team.learner_added', team.course_id, { 'team_id': team.team_id, 'user_id': user.id, 'add_method': 'team_csv_import' }) self.number_of_records_added += 1
def create(self, validated_data): team = CourseTeam.create( name=validated_data.get("name", ''), course_id=validated_data.get("course_id"), description=validated_data.get("description", ''), topic_id=validated_data.get("topic_id", ''), country=validated_data.get("country", ''), language=validated_data.get("language", ''), ) team.save() return team