phase5: add saved searches, watchlist, and authenticated htmx flows

This commit is contained in:
Alfredo Di Stasio
2026-03-10 10:58:39 +01:00
parent c83bc96b6c
commit f207ffbad8
18 changed files with 543 additions and 6 deletions

View File

@ -3,6 +3,7 @@ from datetime import date
from django.db.models import Prefetch
from django.views.generic import DetailView, ListView
from apps.scouting.models import FavoritePlayer
from apps.stats.models import PlayerSeason
from .forms import PlayerSearchForm
@ -56,6 +57,15 @@ class PlayerSearchView(ListView):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["search_form"] = self.get_form()
context["favorite_player_ids"] = set()
if self.request.user.is_authenticated:
player_ids = [player.id for player in context["players"]]
context["favorite_player_ids"] = set(
FavoritePlayer.objects.filter(
user=self.request.user,
player_id__in=player_ids,
).values_list("player_id", flat=True)
)
return context
@ -122,4 +132,10 @@ class PlayerDetailView(DetailView):
context["current_assignment"] = current_assignment
context["career_entries"] = player.career_entries.all().order_by("-start_date", "-id")
context["season_rows"] = season_rows
context["is_favorite"] = False
if self.request.user.is_authenticated:
context["is_favorite"] = FavoritePlayer.objects.filter(
user=self.request.user,
player=player,
).exists()
return context