Skip to content

Commit

Permalink
Fix tournament/me to add inscription data
Browse files Browse the repository at this point in the history
  • Loading branch information
KwikKill committed Oct 30, 2023
1 parent 9875a94 commit b0ec36d
Showing 1 changed file with 45 additions and 43 deletions.
88 changes: 45 additions & 43 deletions insalan/tournament/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,49 +204,51 @@ def get(self, request):
if user is None:
raise PermissionDenied()

# retrieve associated tourneys as Player
assoc_player = Player.objects.filter(user=user)
assoc_player_obj = serializers.PlayerSerializer(assoc_player, many=True).data
assoc_player_teams = [
Team.objects.get(id=player["team"]) for player in assoc_player_obj
]
assoc_player_teams_obj = serializers.TeamSerializer(assoc_player_teams,
many=True).data
assoc_player_tourneys = [
Tournament.objects.get(id=team["tournament"]) for team in assoc_player_teams_obj
]
assoc_player_tourneys_obj = serializers.TournamentSerializer(
assoc_player_tourneys, many=True).data
# Dereferencing teams from tourneys
for tourney in assoc_player_tourneys_obj:
tourney["teams"] = [
teams for teams in assoc_player_teams_obj if teams["id"] in tourney["teams"]
]
# Dereferencing ongoign field from events
tourney["event_ongoing"] = Event.objects.get(id=tourney["event"]).ongoing
# retrieve associated tourneys as Manager
assoc_manager = Manager.objects.filter(user=user)
assoc_manager_obj = serializers.ManagerSerializer(assoc_manager, many=True).data
assoc_manager_teams = [
Team.objects.get(id=manager["team"]) for manager in assoc_manager_obj
]
assoc_manager_teams_obj = serializers.TeamSerializer(
assoc_manager_teams, many=True).data
assoc_manager_tourneys = [
Tournament.objects.get(id=team["tournament"]) for team in assoc_manager_teams_obj
]
assoc_manager_tourneys_obj = serializers.TournamentSerializer(
assoc_manager_tourneys, many=True).data
# Dereferencing teams from tourneys
for tourney in assoc_manager_tourneys_obj:
tourney["teams"] = [
teams for teams in assoc_manager_teams_obj if teams["id"] in tourney["teams"]
]
# Dereferencing events
tourney["event_ongoing"] = Event.objects.get(id=tourney["event"]).ongoing
return Response({ "player": assoc_player_tourneys_obj,
"manager": assoc_manager_tourneys_obj },
status=status.HTTP_200_OK)
# retrieve inscription as Player
player_inscriptions = Player.objects.filter(user=user)
# serialize it
player_inscriptions = serializers.PlayerSerializer(
player_inscriptions, context={"request": request}, many=True
).data
for inscription in player_inscriptions:
# dereference team
inscription["team"] = serializers.TeamSerializer(
Team.objects.get(id=inscription["team"]), context={"request": request}
).data
# dereference tournament
inscription["team"]["tournament"] = serializers.TournamentSerializer(
Tournament.objects.get(id=inscription["team"]["tournament"]),
context={"request": request},
).data
# dereference event
inscription["team"]["tournament"]["event"] = serializers.EventSerializer(
Event.objects.get(id=inscription["team"]["tournament"]["event"]),
context={"request": request},
).data

# retrieve inscription as Manager
manager_inscriptions = Manager.objects.filter(user=user)
# serialize it
manager_inscriptions = serializers.ManagerSerializer(
manager_inscriptions, context={"request": request}, many=True
).data
for inscription in manager_inscriptions:
# dereference team
inscription["team"] = serializers.TeamSerializer(
Team.objects.get(id=inscription["team"]), context={"request": request}
).data
# dereference tournament
inscription["team"]["tournament"] = serializers.TournamentSerializer(
Tournament.objects.get(id=inscription["team"]["tournament"]),
context={"request": request},
).data
# dereference event
inscription["team"]["tournament"]["event"] = serializers.EventSerializer(
Event.objects.get(id=inscription["team"]["tournament"]["event"]),
context={"request": request},
).data

return Response({"player": player_inscriptions, "manager": manager_inscriptions}, status=status.HTTP_200_OK)


# Teams
Expand Down

0 comments on commit b0ec36d

Please sign in to comment.