Add drops data serialization to DropCampaignDetailView context
This commit is contained in:
parent
f0b5bb1e1b
commit
1154a57de3
2 changed files with 31 additions and 4 deletions
|
|
@ -41,7 +41,6 @@
|
||||||
<a href="{{ campaign.account_link_url }}" target="_blank">Connect Account</a>
|
<a href="{{ campaign.account_link_url }}" target="_blank">Connect Account</a>
|
||||||
</p>
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<pre><code>{{ campaign_data }}</code></pre>
|
|
||||||
<h5>Campaign Info</h5>
|
<h5>Campaign Info</h5>
|
||||||
{% if user.is_staff %}
|
{% if user.is_staff %}
|
||||||
<p>
|
<p>
|
||||||
|
|
@ -96,4 +95,5 @@
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>No drops available for this campaign.</p>
|
<p>No drops available for this campaign.</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
<pre><code>{{ campaign_data }}</code></pre>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
|
|
||||||
|
|
@ -168,6 +168,7 @@ class DropCampaignDetailView(DetailView):
|
||||||
"""
|
"""
|
||||||
context: dict[str, Any] = super().get_context_data(**kwargs)
|
context: dict[str, Any] = super().get_context_data(**kwargs)
|
||||||
campaign = context["campaign"]
|
campaign = context["campaign"]
|
||||||
|
drops = TimeBasedDrop.objects.filter(campaign=campaign).select_related("campaign").prefetch_related("benefits").order_by("required_minutes_watched")
|
||||||
|
|
||||||
serialized_campaign = serialize(
|
serialized_campaign = serialize(
|
||||||
"json",
|
"json",
|
||||||
|
|
@ -187,12 +188,38 @@ class DropCampaignDetailView(DetailView):
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
campaign_data = json.loads(serialized_campaign)
|
campaign_data = json.loads(serialized_campaign)
|
||||||
|
|
||||||
|
if drops.exists():
|
||||||
|
serialized_drops = serialize(
|
||||||
|
"json",
|
||||||
|
drops,
|
||||||
|
fields=(
|
||||||
|
"name",
|
||||||
|
"required_minutes_watched",
|
||||||
|
"required_subs",
|
||||||
|
"start_at",
|
||||||
|
"end_at",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
drops_data = json.loads(serialized_drops)
|
||||||
|
|
||||||
|
for i, drop in enumerate(drops):
|
||||||
|
benefits = drop.benefits.all()
|
||||||
|
if benefits.exists():
|
||||||
|
serialized_benefits = serialize(
|
||||||
|
"json",
|
||||||
|
benefits,
|
||||||
|
fields=("name", "image_asset_url"),
|
||||||
|
)
|
||||||
|
benefits_data = json.loads(serialized_benefits)
|
||||||
|
drops_data[i]["fields"]["benefits"] = benefits_data
|
||||||
|
|
||||||
|
campaign_data[0]["fields"]["drops"] = drops_data
|
||||||
|
|
||||||
pretty_campaign_data = json.dumps(campaign_data[0], indent=4)
|
pretty_campaign_data = json.dumps(campaign_data[0], indent=4)
|
||||||
|
|
||||||
context["now"] = timezone.now()
|
context["now"] = timezone.now()
|
||||||
context["drops"] = (
|
context["drops"] = drops
|
||||||
TimeBasedDrop.objects.filter(campaign=campaign).select_related("campaign").prefetch_related("benefits").order_by("required_minutes_watched")
|
|
||||||
)
|
|
||||||
context["campaign_data"] = pretty_campaign_data
|
context["campaign_data"] = pretty_campaign_data
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue