Add JSON serialization for game data in game detail view

This commit is contained in:
Joakim Hellsén 2025-09-03 17:14:41 +02:00
commit 4b1329befb
2 changed files with 16 additions and 0 deletions

View file

@ -84,4 +84,5 @@
{% if not active_campaigns and not upcoming_campaigns and not expired_campaigns %}
No campaigns found for this game.
{% endif %}
<pre><code>{{ game_data }}</code></pre>
{% endblock content %}

View file

@ -291,6 +291,20 @@ class GameDetailView(DetailView):
expired_campaigns: list[DropCampaign] = [campaign for campaign in all_campaigns if campaign.end_at is not None and campaign.end_at < now]
serialized_game = serialize(
"json",
[game],
fields=(
"slug",
"name",
"display_name",
"box_art",
"owner",
),
)
game_data = json.loads(serialized_game)
pretty_game_data = json.dumps(game_data[0], indent=4)
context.update({
"active_campaigns": active_campaigns,
"upcoming_campaigns": upcoming_campaigns,
@ -298,6 +312,7 @@ class GameDetailView(DetailView):
"subscription": subscription,
"owner": game.owner,
"now": now,
"game_data": pretty_game_data,
})
return context