Sort drops within campaigns by required minutes watched
All checks were successful
Ruff / ruff (push) Successful in 10s
All checks were successful
Ruff / ruff (push) Successful in 10s
This commit is contained in:
@ -45,21 +45,18 @@
|
|||||||
{% for campaign, drops_list in campaigns.items %}
|
{% for campaign, drops_list in campaigns.items %}
|
||||||
<div class="card mb-3">
|
<div class="card mb-3">
|
||||||
<div class="card-header bg-secondary bg-opacity-25">
|
<div class="card-header bg-secondary bg-opacity-25">
|
||||||
<h4 class="h6 mb-0">{{ campaign.name|default:"Unknown Campaign" }}</h4>
|
<h4 class="h6 mb-0"><a
|
||||||
|
href="{{ campaign.details_url|default:'#' }}">{{ campaign.name|default:"Unknown Campaign" }}</a>
|
||||||
|
</h4>
|
||||||
<div class="mt-1">
|
<div class="mt-1">
|
||||||
<a href="{{ campaign.details_url|default:'#' }}"
|
|
||||||
class="text-decoration-none">Details</a>
|
|
||||||
{% if campaign.details_url != campaign.account_link_url and campaign.account_link_url %}
|
{% if campaign.details_url != campaign.account_link_url and campaign.account_link_url %}
|
||||||
| <a href="{{ campaign.account_link_url }}" class="text-decoration-none">Link
|
<a href="{{ campaign.account_link_url }}" class="text-decoration-none">Link
|
||||||
Account</a>
|
Account</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<p class="mb-0 mt-1 text-muted small">
|
<p class="mb-0 mt-1 text-muted small">
|
||||||
Ends in:
|
{{ campaign.start_at|date:'l d F H:i' }} -
|
||||||
<abbr
|
{{ campaign.end_at|date:'l d F H:i' }} | {{ campaign.end_at|timeuntil }}
|
||||||
title="{{ campaign.start_at|date:'l d F H:i' }} - {{ campaign.end_at|date:'l d F H:i' }}">
|
|
||||||
{{ campaign.end_at|timeuntil }}
|
|
||||||
</abbr>
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body p-0">
|
<div class="card-body p-0">
|
||||||
@ -86,11 +83,11 @@
|
|||||||
</td>
|
</td>
|
||||||
<td>{{ drop.name|default:'Unknown Drop' }}</td>
|
<td>{{ drop.name|default:'Unknown Drop' }}</td>
|
||||||
<td>
|
<td>
|
||||||
<abbr title="{{ drop.name|default:'Unknown Drop' }}">
|
{{ benefit.name|default:'Unknown Benefit' }}
|
||||||
{{ benefit.name|default:'Unknown Benefit' }}
|
</td>
|
||||||
</abbr>
|
<td>
|
||||||
|
{{ drop.required_minutes_watched|minutes_to_hours }}
|
||||||
</td>
|
</td>
|
||||||
<td>{{ drop.required_minutes_watched|minutes_to_hours }}</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% else %}
|
{% else %}
|
||||||
|
@ -24,7 +24,8 @@ def get_home(request: HttpRequest) -> HttpResponse:
|
|||||||
"""Render the index page with drops grouped hierarchically by game and campaign.
|
"""Render the index page with drops grouped hierarchically by game and campaign.
|
||||||
|
|
||||||
This view fetches all currently active drops (where current time is between start_at and end_at),
|
This view fetches all currently active drops (where current time is between start_at and end_at),
|
||||||
and organizes them by game and campaign for display.
|
and organizes them by game and campaign for display. Drops within each campaign are sorted by
|
||||||
|
required minutes watched.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
request (HttpRequest): The request object.
|
request (HttpRequest): The request object.
|
||||||
@ -43,7 +44,7 @@ def get_home(request: HttpRequest) -> HttpResponse:
|
|||||||
TimeBasedDrop.objects.filter(start_at__lte=now, end_at__gte=now)
|
TimeBasedDrop.objects.filter(start_at__lte=now, end_at__gte=now)
|
||||||
.select_related("campaign", "campaign__game", "campaign__owner")
|
.select_related("campaign", "campaign__game", "campaign__owner")
|
||||||
.prefetch_related("benefits")
|
.prefetch_related("benefits")
|
||||||
.order_by("campaign__game__display_name", "campaign__name", "name")
|
.order_by("campaign__game__display_name", "campaign__name", "required_minutes_watched")
|
||||||
)
|
)
|
||||||
|
|
||||||
# Drops without associated games or campaigns
|
# Drops without associated games or campaigns
|
||||||
@ -70,6 +71,15 @@ def get_home(request: HttpRequest) -> HttpResponse:
|
|||||||
orphaned_drops.append(drop)
|
orphaned_drops.append(drop)
|
||||||
logger.warning("Drop %s does not have an associated game or campaign.", drop.name or drop.drop_id)
|
logger.warning("Drop %s does not have an associated game or campaign.", drop.name or drop.drop_id)
|
||||||
|
|
||||||
|
# Make sure drops within each campaign are sorted by required_minutes_watched
|
||||||
|
for campaigns in grouped_drops.values():
|
||||||
|
for drops in campaigns.values():
|
||||||
|
drops.sort(key=lambda drop: drop.required_minutes_watched or 0)
|
||||||
|
|
||||||
|
# Also sort orphaned drops if any
|
||||||
|
if orphaned_drops:
|
||||||
|
orphaned_drops.sort(key=lambda drop: drop.required_minutes_watched or 0)
|
||||||
|
|
||||||
context: dict[str, Any] = {
|
context: dict[str, Any] = {
|
||||||
"grouped_drops": grouped_drops,
|
"grouped_drops": grouped_drops,
|
||||||
"orphaned_drops": orphaned_drops,
|
"orphaned_drops": orphaned_drops,
|
||||||
|
Reference in New Issue
Block a user