Enhance profile view to display game subscriptions with inheritance details for improved clarity.
This commit is contained in:
parent
9840a2c133
commit
f879dc76ca
2 changed files with 44 additions and 5 deletions
|
|
@ -11,7 +11,7 @@ from django.views.generic import CreateView
|
|||
|
||||
from accounts.forms import CustomUserCreationForm
|
||||
from accounts.models import User
|
||||
from twitch.models import NotificationSubscription
|
||||
from twitch.models import Game, NotificationSubscription
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from django.forms import BaseModelForm
|
||||
|
|
@ -86,14 +86,50 @@ def profile_view(request: HttpRequest) -> HttpResponse:
|
|||
HttpResponse: Rendered profile template.
|
||||
"""
|
||||
subscriptions = NotificationSubscription.objects.filter(user=request.user) # type: ignore[misc]
|
||||
game_subscriptions = subscriptions.filter(game_id__isnull=False)
|
||||
|
||||
# Direct game subscriptions
|
||||
direct_game_subscriptions = subscriptions.filter(game_id__isnull=False)
|
||||
|
||||
# Organization subscriptions
|
||||
org_subscriptions = subscriptions.filter(organization_id__isnull=False)
|
||||
|
||||
# Get games from organization subscriptions (inherited games)
|
||||
inherited_games = Game.objects.filter(owner__in=org_subscriptions.values("organization"))
|
||||
|
||||
# Create mapping of inherited game IDs to their organization names
|
||||
inherited_game_org_map = {}
|
||||
for game in inherited_games:
|
||||
if game.owner:
|
||||
inherited_game_org_map[game.id] = game.owner.name
|
||||
|
||||
# Combine direct and inherited game IDs
|
||||
direct_game_ids = direct_game_subscriptions.values_list("game_id", flat=True)
|
||||
inherited_game_ids = inherited_games.values_list("id", flat=True)
|
||||
all_game_ids = set(direct_game_ids) | set(inherited_game_ids)
|
||||
|
||||
# Get all games (direct + inherited)
|
||||
game_subscriptions_combined = Game.objects.filter(id__in=all_game_ids)
|
||||
|
||||
# Get direct game IDs for template indication
|
||||
direct_game_ids = list(direct_game_subscriptions.values_list("game_id", flat=True))
|
||||
|
||||
# Get all games (direct + inherited) with inheritance info
|
||||
games_with_inheritance = []
|
||||
for game in game_subscriptions_combined:
|
||||
is_inherited = game.id not in direct_game_ids
|
||||
inherited_from = inherited_game_org_map.get(game.id) if is_inherited else None
|
||||
games_with_inheritance.append({
|
||||
"game": game,
|
||||
"is_inherited": is_inherited,
|
||||
"inherited_from": inherited_from,
|
||||
})
|
||||
|
||||
return render(
|
||||
request,
|
||||
"accounts/profile.html",
|
||||
{
|
||||
"user": request.user,
|
||||
"game_subscriptions": game_subscriptions,
|
||||
"games_with_inheritance": games_with_inheritance,
|
||||
"org_subscriptions": org_subscriptions,
|
||||
},
|
||||
)
|
||||
|
|
|
|||
|
|
@ -29,9 +29,12 @@
|
|||
<h2>Will get notifications for these subscriptions:</h2>
|
||||
<h3>Games</h3>
|
||||
<ul>
|
||||
{% for subscription in game_subscriptions %}
|
||||
{% for item in games_with_inheritance %}
|
||||
<li>
|
||||
<a href="{% url 'twitch:game_detail' subscription.game_id %}">{{ subscription.game.display_name }}</a>
|
||||
<a href="{% url 'twitch:game_detail' item.game.id %}">{{ item.game.display_name }}</a>
|
||||
{% if item.is_inherited %}
|
||||
<span style="font-size: 0.85em; color: #666; font-style: italic;">(inherited from {{ item.inherited_from }})</span>
|
||||
{% endif %}
|
||||
</li>
|
||||
{% empty %}
|
||||
<li>You have no game subscriptions yet.</li>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue