def add_spectator(self, user): """Add a spectator to the game. :param user: User -- The spectator's `User` object. :raise: ValueError if `Game` does not allow spectators, or spectator slots have been filled. """ if self.options.spec_mode is Game.SpecMode.NOSPEC: raise ValueError("This game does not allow spectators.") if len(self.spectators) >= self.options.spec_max: raise ValueError("This game has reached the max allowed " "spectators.") self.spectators.append(Spectator(user)) self._update_model_collection('spectators', {'action': 'append'})