Skip to content

Commit

Permalink
site: team: Add redirect for RGL teamids
Browse files Browse the repository at this point in the history
Now that our internal teamid is a subset (at least for league='rgl') of
rgl_teamid, we can make all rgl_teamids redirect to their associated
teamid. This should make it easy to go directly from an RGL teamid to their
page (such as by copy-paste).

Signed-off-by: Sean Anderson <[email protected]>
  • Loading branch information
Forty-Bot committed Nov 24, 2023
1 parent 130c912 commit e576215
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
6 changes: 5 additions & 1 deletion test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,11 @@ def compids(connection):
@pytest.fixture(scope='session')
def teamids(connection):
cur = connection.cursor()
cur.execute("SELECT league, teamid FROM league_team LIMIT 1000;")
cur.execute("""
SELECT league, coalesce(rgl_teamid, teamid)
FROM team_comp_backing
GROUP BY 1, 2
LIMIT 1000;""")
return cur.fetchall()

@pytest.fixture(scope='session')
Expand Down
18 changes: 15 additions & 3 deletions trends/site/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,29 @@ def get_comp():
cur = db.cursor()
cur.execute(
"""SELECT
teamid,
(array_agg(team_name ORDER BY compid DESC))[1] AS name,
(array_agg(avatarhash ORDER BY compid DESC))[1] AS avatarhash,
(array_agg(rgl_teamid ORDER BY compid DESC))[1] AS rgl_teamid,
max(fetched) AS fetched
FROM team_comp
WHERE league = %s AND teamid = %s
GROUP BY league, teamid;""", (flask.g.league, flask.g.teamid))
WHERE league = %(league)s AND teamid = %(teamid)s
GROUP BY league, teamid
UNION ALL
SELECT teamid, NULL, NULL, NULL, NULL
FROM team_comp_backing
WHERE league = %(league)s AND rgl_teamid = %(teamid)s
UNION ALL
SELECT NULL, NULL, NULL, NULL, NULL;""",
{ 'league': flask.g.league, 'teamid': flask.g.teamid })

flask.g.team = cur.fetchone()
if flask.g.team is None:
if flask.g.team['teamid'] is None:
flask.abort(404)
elif flask.g.team['teamid'] != flask.g.teamid:
args = flask.request.args | flask.request.view_args
args['teamid'] = flask.g.team['teamid']
return flask.redirect(flask.url_for(flask.request.endpoint, **args), 301)

if resp := last_modified(flask.g.team['fetched']):
return resp
Expand Down

0 comments on commit e576215

Please sign in to comment.