def on_ok(self): team = Team(name=self.wgName.value, team_description=self.wgDescription.value) country_id = None if isinstance(self.wgAvaliableCountries.value[0], int): country_id = self.wgAvaliableCountries.values[ self.wgAvaliableCountries.value[0]][1] else: country_id = self.country_id if self.team_id: team.id = self.team_id self.parentApp.database.update_team(team) else: team.id = self.parentApp.database.add_team(team) self.parentApp.database.add_country_to_team(team.id, country_id) self.parentApp.switchFormPrevious()
def upsert_team(self, team_id: int, team: Team, countries: list) -> None: with session_scope(self.get_session) as session: if team_id: team.id = team_id team.update(session) else: team.add(session) for country_id in countries: statement = countries_teams.insert().values( country_id=country_id, team_id=team.id) session.execute(statement)