Fix remaining time
This commit is contained in:
@ -15,14 +15,14 @@
|
||||
</div>
|
||||
</h2>
|
||||
{% for campaign in reward_campaigns %}
|
||||
{% render_campaign campaign %}
|
||||
{% render_campaign campaign %} {# Stored in /core/templatetags/campaign_tags.py #}
|
||||
{% endfor %}
|
||||
<h2>
|
||||
Drop campaigns -
|
||||
<div class="d-inline text-muted ">{{ games.count }} game{{ games.count|pluralize }}</div>
|
||||
</h2>
|
||||
{% for game in games %}
|
||||
{% render_game_card game %}
|
||||
{% render_game_card game %} {# Stored in /core/templatetags/game_tags.py #}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -77,7 +77,7 @@ def render_campaigns(campaigns: list[DropCampaign]) -> SafeText:
|
||||
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 ""
|
||||
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
|
||||
@ -94,7 +94,7 @@ def render_campaigns(campaigns: list[DropCampaign]) -> SafeText:
|
||||
link_html,
|
||||
starts_at,
|
||||
ends_at,
|
||||
time_until,
|
||||
remaining_time,
|
||||
render_drops(drops),
|
||||
)
|
||||
|
||||
|
@ -74,10 +74,16 @@ def get_games_with_drops() -> BaseManager[Game]:
|
||||
# Prefetch Benefits for each TimeBasedDrop
|
||||
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
|
||||
time_based_drops_prefetch = Prefetch(
|
||||
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
|
||||
|
Reference in New Issue
Block a user