Fix remaining time

This commit is contained in:
2024-08-21 05:48:54 +02:00
parent 2c70897647
commit 426a499300
4 changed files with 12 additions and 5 deletions

View File

@ -17,6 +17,7 @@
"sitewide", "sitewide",
"socialaccount", "socialaccount",
"Stresss", "Stresss",
"templatetags",
"tocs", "tocs",
"ttvdrops", "ttvdrops",
"ulimits", "ulimits",

View File

@ -15,14 +15,14 @@
</div> </div>
</h2> </h2>
{% for campaign in reward_campaigns %} {% for campaign in reward_campaigns %}
{% render_campaign campaign %} {% render_campaign campaign %} {# Stored in /core/templatetags/campaign_tags.py #}
{% endfor %} {% endfor %}
<h2> <h2>
Drop campaigns - Drop campaigns -
<div class="d-inline text-muted ">{{ games.count }} game{{ games.count|pluralize }}</div> <div class="d-inline text-muted ">{{ games.count }} game{{ games.count|pluralize }}</div>
</h2> </h2>
{% for game in games %} {% for game in games %}
{% render_game_card game %} {% render_game_card game %} {# Stored in /core/templatetags/game_tags.py #}
{% endfor %} {% endfor %}
</div> </div>
</div> </div>

View File

@ -77,7 +77,7 @@ def render_campaigns(campaigns: list[DropCampaign]) -> SafeText:
campaign.account_link_url, campaign.account_link_url,
) )
time_until: str = timesince(campaign.ends_at, now()) if campaign.ends_at else "" remaining_time: str = timesince(now(), campaign.ends_at) if campaign.ends_at else "Failed to calculate time"
starts_at: str = campaign.starts_at.strftime("%A %d %B %H:%M") if campaign.starts_at else "" starts_at: str = campaign.starts_at.strftime("%A %d %B %H:%M") if campaign.starts_at else ""
ends_at: str = campaign.ends_at.strftime("%A %d %B %H:%M") if campaign.ends_at else "" ends_at: str = campaign.ends_at.strftime("%A %d %B %H:%M") if campaign.ends_at else ""
drops: list[TimeBasedDrop] = campaign.drops.all() # type: ignore # noqa: PGH003 drops: list[TimeBasedDrop] = campaign.drops.all() # type: ignore # noqa: PGH003
@ -94,7 +94,7 @@ def render_campaigns(campaigns: list[DropCampaign]) -> SafeText:
link_html, link_html,
starts_at, starts_at,
ends_at, ends_at,
time_until, remaining_time,
render_drops(drops), render_drops(drops),
) )

View File

@ -74,10 +74,16 @@ def get_games_with_drops() -> BaseManager[Game]:
# Prefetch Benefits for each TimeBasedDrop # Prefetch Benefits for each TimeBasedDrop
benefits_prefetch = Prefetch(lookup="benefits", queryset=Benefit.objects.all()) benefits_prefetch = Prefetch(lookup="benefits", queryset=Benefit.objects.all())
# Filter active time-based drops
active_time_based_drops: BaseManager[TimeBasedDrop] = TimeBasedDrop.objects.filter(ends_at__gte=timezone.now())
# Prefetch Benefits for each active TimeBasedDrop
benefits_prefetch = Prefetch(lookup="benefits", queryset=Benefit.objects.all())
# Prefetch TimeBasedDrops for each DropCampaign and include the prefetch of Benefits # Prefetch TimeBasedDrops for each DropCampaign and include the prefetch of Benefits
time_based_drops_prefetch = Prefetch( time_based_drops_prefetch = Prefetch(
lookup="drops", lookup="drops",
queryset=TimeBasedDrop.objects.prefetch_related(benefits_prefetch), queryset=active_time_based_drops.prefetch_related(benefits_prefetch),
) )
# Prefetch DropCampaigns for each Game and include the prefetch of TimeBasedDrops # Prefetch DropCampaigns for each Game and include the prefetch of TimeBasedDrops