Browse Source

Add last_location method to Player

feature_tests
Burathar 4 years ago
parent
commit
6582fd8466
  1. 11
      app/models.py

11
app/models.py

@ -7,6 +7,8 @@ from secrets import token_hex @@ -7,6 +7,8 @@ from secrets import token_hex
from flask_login import UserMixin
import json
from json import JSONEncoder
from datetime import datetime
import pytz
class Role(Enum):
@ -137,6 +139,15 @@ class Player(UserMixin, db.Model): @@ -137,6 +139,15 @@ class Player(UserMixin, db.Model):
def check_password(self, password):
return check_password_hash(self.password_hash, password)
def last_location(self, game = None):
if not self.locations:
return None
if game is None:
return max(location.timestamp for location in self.locations)
game_start = game.start_time or datetime.min
game_end = game.end_time or datetime.max
return max(location.timestamp for location in self.locations if location.timestamp > game_start and location.timestamp < game_end)
@login.user_loader
def load_user(id):
return Player.query.get(int(id))

Loading…
Cancel
Save