Update dashboard

This commit is contained in:
Joakim Hellsén 2026-01-08 19:41:05 +01:00
commit 0060f4d8f6
No known key found for this signature in database
2 changed files with 113 additions and 126 deletions

View file

@ -7,7 +7,7 @@
<main> <main>
<h1 id="page-title">Twitch Drops</h1> <h1 id="page-title">Twitch Drops</h1>
<pre> <pre>
Drops are sorted alphabetically by organization and game. Click on a campaign or game title to see more details. Latest drops are shown first within each game. Click on a campaign or game title to see more details.
Hover over the end time to see the exact date and time. Hover over the end time to see the exact date and time.
</pre> </pre>
<!-- RSS Feeds --> <!-- RSS Feeds -->
@ -18,20 +18,12 @@ Hover over the end time to see the exact date and time.
</div> </div>
{% if campaigns_by_org_game %} {% if campaigns_by_org_game %}
{% for org_id, org_data in campaigns_by_org_game.items %} {% for org_id, org_data in campaigns_by_org_game.items %}
<section id="org-section-{{ org_id }}">
<h2>
{% if org_data.name %}
{{ org_data.name }}
{% else %}
Organization {{ org_id }}
{% endif %}
</h2>
{% for game_id, game_data in org_data.games.items %} {% for game_id, game_data in org_data.games.items %}
<article id="game-article-{{ game_id }}"> <article id="game-article-{{ game_id }}" style="margin-bottom: 2rem;">
<header style="margin-bottom: 1rem;"> <header style="margin-bottom: 1rem;">
<h3 style="margin: 0 0 0.5rem 0;"> <h2 style="margin: 0 0 0.5rem 0;">
<a href="{% url 'twitch:game_detail' game_id %}">{{ game_data.name }}</a> <a href="{% url 'twitch:game_detail' game_id %}">{{ game_data.name }}</a>
</h3> </h2>
</header> </header>
<div style="display: flex; gap: 1rem;"> <div style="display: flex; gap: 1rem;">
<div style="flex-shrink: 0;"> <div style="flex-shrink: 0;">
@ -111,6 +103,19 @@ Hover over the end time to see the exact date and time.
... and {{ campaign.allow_channels.all|length|add:"-5" }} more ... and {{ campaign.allow_channels.all|length|add:"-5" }} more
</li> </li>
{% endif %} {% endif %}
{% else %}
{% if campaign.game.twitch_directory_url %}
<li>
<a href="{{ campaign.game.twitch_directory_url }}"
target="_blank"
rel="noopener noreferrer"
title="Open Twitch category page for {{ campaign.game.display_name }} with Drops filter">
Browse {{ campaign.game.display_name }} category
</a>
</li>
{% else %}
<li>Failed to get Twitch category URL :(</li>
{% endif %}
{% endif %} {% endif %}
{% else %} {% else %}
{% if campaign.game.twitch_directory_url %} {% if campaign.game.twitch_directory_url %}
@ -136,7 +141,6 @@ Hover over the end time to see the exact date and time.
</div> </div>
</article> </article>
{% endfor %} {% endfor %}
</section>
{% endfor %} {% endfor %}
{% else %} {% else %}
<p>No active campaigns at the moment.</p> <p>No active campaigns at the moment.</p>

View file

@ -641,9 +641,11 @@ def dashboard(request: HttpRequest) -> HttpResponse:
.prefetch_related( .prefetch_related(
"allow_channels", "allow_channels",
) )
.order_by("-start_at")
) )
campaigns_by_org_game: dict[str, Any] = {} # Use OrderedDict to preserve insertion order (newest campaigns first)
campaigns_by_org_game: OrderedDict[str, Any] = OrderedDict()
for campaign in active_campaigns: for campaign in active_campaigns:
owner: Organization | None = campaign.game.owner owner: Organization | None = campaign.game.owner
@ -654,7 +656,7 @@ def dashboard(request: HttpRequest) -> HttpResponse:
game_name: str = campaign.game.display_name game_name: str = campaign.game.display_name
if org_id not in campaigns_by_org_game: if org_id not in campaigns_by_org_game:
campaigns_by_org_game[org_id] = {"name": org_name, "games": {}} campaigns_by_org_game[org_id] = {"name": org_name, "games": OrderedDict()}
if game_id not in campaigns_by_org_game[org_id]["games"]: if game_id not in campaigns_by_org_game[org_id]["games"]:
campaigns_by_org_game[org_id]["games"][game_id] = { campaigns_by_org_game[org_id]["games"][game_id] = {
@ -663,33 +665,14 @@ def dashboard(request: HttpRequest) -> HttpResponse:
"campaigns": [], "campaigns": [],
} }
campaigns_by_org_game[org_id]["games"][game_id]["campaigns"].append( campaigns_by_org_game[org_id]["games"][game_id]["campaigns"].append(campaign)
campaign,
)
sorted_campaigns_by_org_game: dict[str, Any] = {
org_id: campaigns_by_org_game[org_id]
for org_id in sorted(
campaigns_by_org_game.keys(),
key=lambda k: campaigns_by_org_game[k]["name"],
)
}
for org_data in sorted_campaigns_by_org_game.values():
org_data["games"] = {
game_id: org_data["games"][game_id]
for game_id in sorted(
org_data["games"].keys(),
key=lambda k: org_data["games"][k]["name"],
)
}
return render( return render(
request, request,
"twitch/dashboard.html", "twitch/dashboard.html",
{ {
"active_campaigns": active_campaigns, "active_campaigns": active_campaigns,
"campaigns_by_org_game": sorted_campaigns_by_org_game, "campaigns_by_org_game": campaigns_by_org_game,
"now": now, "now": now,
}, },
) )