From 80b4c6a277e9bec22195aac9ef54d664af7624b5 Mon Sep 17 00:00:00 2001 From: Nathan Kim Date: Sun, 14 Jan 2024 20:52:17 -0500 Subject: [PATCH 1/5] Allow tours to have attachments by default --- backend/siarnaq/bracket/challonge.py | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/siarnaq/bracket/challonge.py b/backend/siarnaq/bracket/challonge.py index 2c81b6e74..253a7a6a5 100644 --- a/backend/siarnaq/bracket/challonge.py +++ b/backend/siarnaq/bracket/challonge.py @@ -59,6 +59,7 @@ def create_tournament(tournament: Tournament, *, is_private: bool): "tournament_type": challonge_type, "private": is_private, "url": challonge_id, + "match_options": {"accept_attachments": True}, }, } } From 0f414b2a883695d22c5e40309a5a2887421cd1d6 Mon Sep 17 00:00:00 2001 From: Nathan Kim Date: Sun, 14 Jan 2024 20:58:06 -0500 Subject: [PATCH 2/5] Add game name to Challonge, cuz it's required from the Settings page --- backend/siarnaq/bracket/challonge.py | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/siarnaq/bracket/challonge.py b/backend/siarnaq/bracket/challonge.py index 253a7a6a5..0083e5135 100644 --- a/backend/siarnaq/bracket/challonge.py +++ b/backend/siarnaq/bracket/challonge.py @@ -59,6 +59,7 @@ def create_tournament(tournament: Tournament, *, is_private: bool): "tournament_type": challonge_type, "private": is_private, "url": challonge_id, + "game_name": "Battlecode", "match_options": {"accept_attachments": True}, }, } From 3c4ddca6751bb7e8f9920d45404f18dfb7060d83 Mon Sep 17 00:00:00 2001 From: Nathan Kim Date: Sun, 14 Jan 2024 22:12:32 -0500 Subject: [PATCH 3/5] Use newer version of challonge api --- backend/siarnaq/bracket/challonge.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/siarnaq/bracket/challonge.py b/backend/siarnaq/bracket/challonge.py index 0083e5135..0ded0e9cc 100644 --- a/backend/siarnaq/bracket/challonge.py +++ b/backend/siarnaq/bracket/challonge.py @@ -25,7 +25,7 @@ } AUTH_TYPE = "v1" -URL_BASE = "https://api.challonge.com/v2/" +URL_BASE = "https://api.challonge.com/v2.1/" def create_tournament(tournament: Tournament, *, is_private: bool): From 4474218a3b1296c76fb0af7e6bc4fb560bb7741e Mon Sep 17 00:00:00 2001 From: Nathan Kim Date: Mon, 15 Jan 2024 12:33:17 -0500 Subject: [PATCH 4/5] Extra info for local dev --- backend/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/README.md b/backend/README.md index e0bfa8b91..1ed90a9a4 100644 --- a/backend/README.md +++ b/backend/README.md @@ -11,8 +11,8 @@ is the backend of Siarnaq, written in Django. `db.sqlite3`, which contains a toy database for testing. You should not commit this. 1. Run `./manage.py runserver` to turn on the server! -While developing, you may find the `api/specs/swagger-ui` endpoint userful for viewing -and querying the avaiable API. +While developing, you may find the `api/specs/swagger-ui` endpoint useful for viewing +and querying the available API. To authenticate to use this, log into some page that would use the same environment (such as the frontend homepage or admin page in the same environment), then refresh the page. Get the value of the `access` cookie used in the _header_ of the HTTP request (usually in the dev tools or network tab). Copy it, making sure not to include any spaces or punctuation from the beginning or end. Then on the `swagger-ui` endpoint, click `Authenticate` at the top, and enter the copied value there. If you ever get your database into a really broken state, just delete `db.sqlite3`, and start again. From 1416accdea62f7a81900a17fd190309d298d7cdd Mon Sep 17 00:00:00 2001 From: Nathan Kim Date: Mon, 15 Jan 2024 14:09:40 -0500 Subject: [PATCH 5/5] Update fields for challonge v2.1 api --- backend/siarnaq/bracket/challonge.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/backend/siarnaq/bracket/challonge.py b/backend/siarnaq/bracket/challonge.py index 0ded0e9cc..d8e56b426 100644 --- a/backend/siarnaq/bracket/challonge.py +++ b/backend/siarnaq/bracket/challonge.py @@ -140,7 +140,7 @@ def get_tournament_data(tournament: Tournament, *, is_private: bool): # in case of bracket reset matches = [item for item in data["included"] if item["type"] == "match"] match_last = max( - matches, key=lambda match: match["attributes"]["suggestedPlayOrder"] + matches, key=lambda match: match["attributes"]["suggested_play_order"] ) # Give it its own round match_last["attributes"]["round"] += 1 @@ -158,7 +158,7 @@ def _get_round_indexes(tournament: Tournament, *, is_private: bool): round_indexes = list() matches = [item for item in tournament_data["included"] if item["type"] == "match"] - matches.sort(key=lambda i: i["attributes"]["suggestedPlayOrder"]) + matches.sort(key=lambda i: i["attributes"]["suggested_play_order"]) for match in matches: round_index = match["attributes"]["round"] @@ -324,15 +324,13 @@ def get_match_and_participant_objects_for_round(round: TournamentRound): ) match_objects.append(match_object) - # Note that Challonge 1-indexes its player indexes - # while our internal data model (in Siarnaq) 0-indexes. - for (siarnaq_player_index, challonge_player_index) in enumerate( - ["player1", "player2"] - ): + for player_index in range(2): # This looks ugly but it's how to parse through the Challonge-related data. - challonge_participant_id_private = challonge_match["relationships"][ - challonge_player_index - ]["data"]["id"] + challonge_participant_id_private = str( + challonge_match["attributes"]["points_by_participant"][player_index][ + "participant_id" + ] + ) challonge_participant_id_public = challonge_team_ids_private_to_public[ challonge_participant_id_private ] @@ -348,7 +346,7 @@ def get_match_and_participant_objects_for_round(round: TournamentRound): team_id=team_id, submission_id=submission_id, match=match_object, - player_index=siarnaq_player_index, + player_index=player_index, external_id_private=challonge_participant_id_private, external_id_public=challonge_participant_id_public, )