Skip to content

Commit

Permalink
admin: Add brackets and position pool
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe2k committed Sep 25, 2024
1 parent ace8cc1 commit 0cc547c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
22 changes: 22 additions & 0 deletions server/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
from server.season.models import Season
from server.series.models import Series, SeriesRegistration, SeriesRosterInvitation
from server.tournament.models import (
Bracket,
Event,
Match,
Pool,
PositionPool,
Registration,
Tournament,
TournamentField,
Expand Down Expand Up @@ -137,6 +139,26 @@ def get_name(self, obj: Pool) -> str:
return obj.tournament.event.title


@admin.register(Bracket)
class BracketAdmin(admin.ModelAdmin[Bracket]):
search_fields = ["tournament__event__title"]
list_display = ["get_name", "name"]

@admin.display(description="Tournament Name", ordering="tournament__event__title")
def get_name(self, obj: Pool) -> str:
return obj.tournament.event.title


@admin.register(PositionPool)
class PositionPoolAdmin(admin.ModelAdmin[PositionPool]):
search_fields = ["tournament__event__title"]
list_display = ["get_name", "name"]

@admin.display(description="Tournament Name", ordering="tournament__event__title")
def get_name(self, obj: Pool) -> str:
return obj.tournament.event.title


@admin.register(Match)
class MatchAdmin(admin.ModelAdmin[Match]):
search_fields = ["tournament__event__title"]
Expand Down
21 changes: 13 additions & 8 deletions server/management/commands/add_to_event_roster.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from server.core.models import Player, Team, User
from server.tournament.models import Event, Registration, Tournament
from server.series.utils import register_player
from server.tournament.utils import can_register_player_to_series_event


Expand All @@ -27,26 +26,28 @@ def handle(self, *args: Any, **options: Any) -> None:
except (Event.DoesNotExist, Team.DoesNotExist, Tournament.DoesNotExist):
self.stderr.write(self.style.ERROR("Event / Team / Tournament does not exist"))
return

if team not in tournament.teams.all():
self.stderr.write(self.style.ERROR(f"{team.name} is not registered for ${event.title} !"))
self.stderr.write(
self.style.ERROR(f"{team.name} is not registered for ${event.title} !")
)
return

csv_file = options["csv_file"]

with open(csv_file) as file:
csv_reader = csv.DictReader(file)
for row in csv_reader:
# Process each row of the CSV file
email = row["email"].strip().lower()

try:
user = User.objects.get(username=email)
player = Player.objects.get(user=user)
except (User.DoesNotExist, Player.DoesNotExist):
self.stderr.write(self.style.ERROR(f"Player not found: {email}"))
continue

if event.series:
can_register, error = can_register_player_to_series_event(
event=event, team=team, player=player
Expand All @@ -63,5 +64,9 @@ def handle(self, *args: Any, **options: Any) -> None:
try:
registration.save()
except IntegrityError:
self.stderr.write(self.style.ERROR(f"Error: Player already added to another team for this event, player: {email}"))
continue
self.stderr.write(
self.style.ERROR(
f"Error: Player already added to another team for this event, player: {email}"
)
)
continue

0 comments on commit 0cc547c

Please sign in to comment.