Filter out old events when fetching them (#23)
* Update events.py Update events.py to only display events less than an hour past their start time. * Update events.py * Update backend-flask/events.py Co-authored-by: HumanoidSandvichDispenser <25856867+HumanoidSandvichDispenser@users.noreply.github.com> * Update backend-flask/events.py Co-authored-by: HumanoidSandvichDispenser <25856867+HumanoidSandvichDispenser@users.noreply.github.com> --------- Co-authored-by: HumanoidSandvichDispenser <25856867+HumanoidSandvichDispenser@users.noreply.github.com>master
parent
f70a5d69e3
commit
aefb9c30f1
|
@ -6,7 +6,7 @@
|
||||||
# Distributed under terms of the MIT license.
|
# Distributed under terms of the MIT license.
|
||||||
|
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime, timedelta, timezone
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from flask import Blueprint, abort, make_response
|
from flask import Blueprint, abort, make_response
|
||||||
|
@ -52,13 +52,16 @@ def get_event(event_id: int):
|
||||||
@requires_authentication
|
@requires_authentication
|
||||||
@requires_team_membership()
|
@requires_team_membership()
|
||||||
def get_team_events(player_team: PlayerTeam, team_id: int, **_):
|
def get_team_events(player_team: PlayerTeam, team_id: int, **_):
|
||||||
|
time_now = datetime.now(timezone.utc)
|
||||||
|
|
||||||
rows = db.session.query(
|
rows = db.session.query(
|
||||||
Event, PlayerEvent
|
Event, PlayerEvent
|
||||||
).outerjoin(
|
).outerjoin(
|
||||||
PlayerEvent,
|
PlayerEvent,
|
||||||
(PlayerEvent.event_id == Event.id) & (PlayerEvent.player_id == player_team.player_id)
|
(PlayerEvent.event_id == Event.id) & (PlayerEvent.player_id == player_team.player_id)
|
||||||
).where(
|
).where(
|
||||||
Event.team_id == team_id
|
Event.team_id == team_id,
|
||||||
|
Event.start_time >= (time_now - timedelta(hours=1))
|
||||||
).order_by(
|
).order_by(
|
||||||
Event.start_time
|
Event.start_time
|
||||||
).all()
|
).all()
|
||||||
|
|
Loading…
Reference in New Issue