def setScore(self, score): try: score = int(score) except ValueError: raise DomainException("Score must be an integer") if score > 99999 or score < -99999: raise DomainException("Score must be between -99999 and +99999") self._score = score
def setId(self, value): try: value = int(value) except ValueError: raise DomainException("The id must be an integer") if value < 0: raise DomainException("The id must be greater than one") self._id = value
def setVerified(self, value): try: value = bool(value) # converts it to boolean type (1 = True and 0 = False) except NameError: raise DomainException("You can only set verified to true or false") self._verified = value
def setTime(self, time): if type(time) is not datetime: raise DomainException( "Time attribute must be a datetime object not a %s" % str(type(time))) self._time = time
def setEndTime(self, time): if type(time) is not datetime and time is not None: raise DomainException( "The end time must be either empty or a datetime object not %s" % str(type(time))) self._endTime = time
def setToken(self, token): if token is not None: if not isinstance(token, Apitoken): raise DomainException( "Token must be an API Token Model Object") self._token = token
def setCreator(self, creator): from Model.user import User if not isinstance(creator, User): raise DomainException( "Creator must be an instance of the User object") self._creator = creator
def setGameType(self, gameType): from Model.gametype import GameType if not isinstance(gameType, GameType): raise DomainException( "gametype must be an instance of the GameType object") self._gameType = gameType
def setGame(self, game_): if game_ is not None: if not isinstance(game_, Game): raise DomainException( "Game attribute must be a reference to another Game object" ) self._game = game_
def setUser(self, user_): from Model.user import User if not isinstance(user_, User): raise DomainException("Must reference a User object not a %s" % str(type(user_))) user_.setToken(self) self._user = user_
def setEmail(self, email): if email is not None: email = str(email) pattern = r"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?" if not re.match(pattern, email): raise DomainException("'%s' is not a valid email address" % email) # email checking needs to be added to user self._email = email
def setVictim(self, victim): if victim is not None: if not isinstance(victim, Player): raise DomainException("Victim must be a Player object") self._victim = victim
def setKiller(self, killer): if killer is not None: if not isinstance(killer, Player): raise DomainException("Killer must be a Player object") self._killer = killer
def setToken(self, token): if len(token) != 64: raise DomainException( "That is not a valid API Token, should be a 64 character hash") self._token = token
def setName(self, name): if len(name) > 255: raise DomainException( "The name of a game cannot be more than 255 characters") self._name = name
def setUser(self, user_): if not isinstance(user_, User): raise DomainException( "User attribute must be a reference to another User object") self._user = user_
def setTime(self, time_): if time_ is not None: if type(time_) is not datetime: raise DomainException("Time must a datetime object") self._time = time_
def setName(self, name): if len(name) > 60: raise DomainException( "User's name must be less than 60 characters") self._name = name
def setPhoto(self, photo): if photo is not None: if len(photo) is not 32: raise DomainException("That is not a photo") self._photo = photo
def setTime(self, time): if type(time) is not datetime: raise DomainException("Time must be a datetime object, not a %s" % type(time)) self._time = time
def setTime(self, time_): if type(time_) is "<type 'datetime.datetime'>": raise DomainException("Time must a datetime object") self._time = time_
def setPhoto(self, photo): if photo is not None: if len(photo) != 32: raise DomainException("Photo must be a 32 character string") self._photo = photo