Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow tournaments to have attachments by default; allow tournaments to easily take edits from settings #722

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
24 changes: 12 additions & 12 deletions backend/siarnaq/bracket/challonge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -59,6 +59,8 @@ 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},
},
}
}
Expand Down Expand Up @@ -138,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
Expand All @@ -156,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"]
Expand Down Expand Up @@ -322,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
]
Expand All @@ -346,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,
)
Expand Down