Skip to content
Merged
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
7 changes: 2 additions & 5 deletions src/chigame/games/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from django.conf import settings
from django.conf.urls.static import static
from django.urls import path

from . import views
Expand Down Expand Up @@ -50,6 +48,8 @@
path("tournaments/<int:pk>/update/", views.TournamentUpdateView.as_view(), name="tournament-update"),
path("tournaments/<int:pk>/delete/", views.TournamentDeleteView.as_view(), name="tournament-delete"),
path("tournaments/archived/", views.TournamentArchivedListView.as_view(), name="tournament-archived"),
# addedum
path("tournaments/<int:pk>/match-stats/", views.MatchStatsView.as_view(), name="tournament-match-stats"),
# placeholder game
path("lobby/<int:pk>/coinflip", views.coin_flip_game, name="placeholder-game"),
path("<int:pk>/", views.GameDetailView.as_view(), name="game-detail"),
Expand All @@ -72,6 +72,3 @@
path("checkers/<int:board_id>/update/", views.checkers_game_update_board_state, name="update_board_state"),
path("checkers/<int:board_id>/state/", views.checkers_game_get_board_state, name="checkers-get-state"),
]
# for an uploaded twine file this makes the files accessible at a url
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
19 changes: 15 additions & 4 deletions src/chigame/games/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,13 @@ def get_queryset(self):
if self.request.user.is_staff:
return Tournament.objects.prefetch_related("matches").all()

# If the user is authenticated but not staff, show only tournaments they are part of
if self.request.user.is_authenticated:
return Tournament.objects.prefetch_related("matches").filter(players=self.request.user)

# For unauthenticated users, show all non-archived tournaments
return Tournament.objects.prefetch_related("matches").filter(archived=False)

# For non-staff users, show only tournaments they are part of
return (
Tournament.objects.prefetch_related("matches")
Expand Down Expand Up @@ -1244,11 +1251,15 @@ def post(self, request, *args, **kwargs):
elif success == 1:
messages.error(request, "You have not joined this tournament")
return redirect(reverse_lazy("tournament-detail", kwargs={"pk": tournament.pk}))
elif success == 3:
messages.error(request, "The registration period for this tournament has ended")
elif request.POST.get("action") == "archive":
tournament.set_archive(True)
messages.success(request, "You have successfully archived this tournament")
return redirect(reverse_lazy("tournament-detail", kwargs={"pk": tournament.pk}))

elif request.POST.get("action") == "unarchive":
tournament.set_archive(False)
messages.success(request, "You have successfully unarchived this tournament")
return redirect(reverse_lazy("tournament-detail", kwargs={"pk": tournament.pk}))
else:
raise Exception("Invalid return value")

elif request.POST.get("action") == "join_match":
# Get the user's current match in the tournament
Expand Down
9 changes: 5 additions & 4 deletions src/templates/tournaments/tournament_create.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h1 class="mb-4">Create Tournament</h1>
</div>
<!-- Registration dates with calendar dropdowns -->
<div class="col-md-6 mb-3">
<label for="id_registration_start_date" class="form-label">Registration start date</label>
<label for="id_registration_start_date" class="form-label">Registration start date and time</label>
<input type="datetime-local"
name="{{ form.registration_start_date.html_name }}"
id="id_registration_start_date"
Expand All @@ -33,7 +33,8 @@ <h1 class="mb-4">Create Tournament</h1>
{% endif %}
</div>
<div class="col-md-6 mb-3">
<label for="id_registration_end_date" class="form-label">Registration end date</label>
<!-- addedum -->
<label for="id_registration_end_date" class="form-label">Registration end date and time</label>
<input type="datetime-local"
name="{{ form.registration_end_date.html_name }}"
id="id_registration_end_date"
Expand All @@ -46,7 +47,7 @@ <h1 class="mb-4">Create Tournament</h1>
</div>
<!-- Tournament dates with calendar dropdowns -->
<div class="col-md-6 mb-3">
<label for="id_tournament_start_date" class="form-label">Tournament start date</label>
<label for="id_tournament_start_date" class="form-label">Tournament start date and time</label>
<input type="datetime-local"
name="{{ form.tournament_start_date.html_name }}"
id="id_tournament_start_date"
Expand All @@ -58,7 +59,7 @@ <h1 class="mb-4">Create Tournament</h1>
{% endif %}
</div>
<div class="col-md-6 mb-3">
<label for="id_tournament_end_date" class="form-label">Tournament end date</label>
<label for="id_tournament_end_date" class="form-label">Tournament end date and time</label>
<input type="datetime-local"
name="{{ form.tournament_end_date.html_name }}"
id="id_tournament_end_date"
Expand Down
Loading