Browse Source

fix offset None error

testing
Burathar 4 years ago
parent
commit
62dcb62dfe
  1. 2
      app/models/game.py
  2. 8
      app/models/user.py

2
app/models/game.py

@ -29,7 +29,7 @@ class Game(db.Model): @@ -29,7 +29,7 @@ class Game(db.Model):
backref=db.backref('game', lazy='joined'),
cascade="save-update, merge, delete, delete-orphan")
def last_player_locations(self, offset):
def last_player_locations(self, offset=None):
# pylint: disable=not-an-iterable
return [player.last_location(offset=offset) for player in self.players if player.user.locations]

8
app/models/user.py

@ -42,7 +42,7 @@ class User(UserMixin, db.Model): @@ -42,7 +42,7 @@ class User(UserMixin, db.Model):
return False
return check_password_hash(self.password_hash, password)
def locations_during_game(self, game, offset=0):
def locations_during_game(self, game, offset=None):
'''
Returns users locations during game.
@ -51,6 +51,8 @@ class User(UserMixin, db.Model): @@ -51,6 +51,8 @@ class User(UserMixin, db.Model):
offset (int): Offset in minutes. Only locations older than this amount of minutes will be returned.
'''
# pylint: disable=not-an-iterable
if offset is None:
offset = 0
if not self.locations:
return None
if game is None:
@ -67,7 +69,7 @@ class User(UserMixin, db.Model): @@ -67,7 +69,7 @@ class User(UserMixin, db.Model):
if location.timestamp > game_start and location.timestamp < game_end
and datetime.utcnow() - location.timestamp > timedelta(minutes=offset)]
def last_location(self, game=None, offset=0):
def last_location(self, game=None, offset=None):
'''
Returns users last recorded location.
@ -76,6 +78,8 @@ class User(UserMixin, db.Model): @@ -76,6 +78,8 @@ class User(UserMixin, db.Model):
offset (int): Offset in minutes. Only locations older than this amount of minutes will be returned.
'''
# pylint: disable=[not-an-iterable, unsubscriptable-object]
if offset is None:
offset = 0
if not self.locations:
return None
if game is None:

Loading…
Cancel
Save