def upsert_player(self, player_id: int, player: Player) -> None: with session_scope(self.get_session) as session: if player_id: player.id = player_id player.update(session) else: player.add(session)
def on_ok(self): player = Player(height=self.wgHeight.value, is_injured=bool(self.wgIsInjured.value[0]), first_name=self.wgFirstName.value, last_name=self.wgLastName.value, date_of_birth=self.wgDateOfBirth.value) if isinstance(self.wgClub.value[0], int): player.club_id = self.wgClub.values[self.wgClub.value[0]][1] if isinstance(self.wgPosition.value[0], int): player.position_id = self.wgPosition.values[ self.wgPosition.value[0]][1] if self.player_id: player.id = self.player_id self.parentApp.database.update_player(player) else: self.parentApp.database.add_player(player) self.parentApp.switchFormPrevious()