Fix remaining time
This commit is contained in:
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@ -17,6 +17,7 @@
|
|||||||
"sitewide",
|
"sitewide",
|
||||||
"socialaccount",
|
"socialaccount",
|
||||||
"Stresss",
|
"Stresss",
|
||||||
|
"templatetags",
|
||||||
"tocs",
|
"tocs",
|
||||||
"ttvdrops",
|
"ttvdrops",
|
||||||
"ulimits",
|
"ulimits",
|
||||||
|
@ -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>
|
||||||
|
@ -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),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
Reference in New Issue
Block a user