Add all fields when doing serialization
This commit is contained in:
parent
146b3332f4
commit
e3a68ab4d2
1 changed files with 46 additions and 10 deletions
|
|
@ -104,8 +104,6 @@ class OrgListView(ListView):
|
||||||
|
|
||||||
|
|
||||||
# MARK: /organizations/<twitch_id>/
|
# MARK: /organizations/<twitch_id>/
|
||||||
|
|
||||||
|
|
||||||
def organization_detail_view(request: HttpRequest, twitch_id: str) -> HttpResponse:
|
def organization_detail_view(request: HttpRequest, twitch_id: str) -> HttpResponse:
|
||||||
"""Function-based view for organization detail.
|
"""Function-based view for organization detail.
|
||||||
|
|
||||||
|
|
@ -130,7 +128,12 @@ def organization_detail_view(request: HttpRequest, twitch_id: str) -> HttpRespon
|
||||||
serialized_org: str = serialize(
|
serialized_org: str = serialize(
|
||||||
"json",
|
"json",
|
||||||
[organization],
|
[organization],
|
||||||
fields=("name",),
|
fields=(
|
||||||
|
"twitch_id",
|
||||||
|
"name",
|
||||||
|
"added_at",
|
||||||
|
"updated_at",
|
||||||
|
),
|
||||||
)
|
)
|
||||||
org_data: list[dict] = json.loads(serialized_org)
|
org_data: list[dict] = json.loads(serialized_org)
|
||||||
|
|
||||||
|
|
@ -138,7 +141,15 @@ def organization_detail_view(request: HttpRequest, twitch_id: str) -> HttpRespon
|
||||||
serialized_games: str = serialize(
|
serialized_games: str = serialize(
|
||||||
"json",
|
"json",
|
||||||
games,
|
games,
|
||||||
fields=("slug", "name", "display_name", "box_art"),
|
fields=(
|
||||||
|
"twitch_id",
|
||||||
|
"slug",
|
||||||
|
"name",
|
||||||
|
"display_name",
|
||||||
|
"box_art",
|
||||||
|
"added_at",
|
||||||
|
"updated_at",
|
||||||
|
),
|
||||||
)
|
)
|
||||||
games_data: list[dict] = json.loads(serialized_games)
|
games_data: list[dict] = json.loads(serialized_games)
|
||||||
org_data[0]["fields"]["games"] = games_data
|
org_data[0]["fields"]["games"] = games_data
|
||||||
|
|
@ -220,11 +231,6 @@ def format_and_color_json(data: dict[str, Any] | str) -> str:
|
||||||
return highlight(formatted_code, JsonLexer(), HtmlFormatter())
|
return highlight(formatted_code, JsonLexer(), HtmlFormatter())
|
||||||
|
|
||||||
|
|
||||||
# MARK: /campaigns/<twitch_id>/
|
|
||||||
|
|
||||||
# MARK: /campaigns/<twitch_id>/
|
|
||||||
|
|
||||||
|
|
||||||
def _enhance_drops_with_context(drops: QuerySet[TimeBasedDrop], now: datetime.datetime) -> list[dict[str, Any]]:
|
def _enhance_drops_with_context(drops: QuerySet[TimeBasedDrop], now: datetime.datetime) -> list[dict[str, Any]]:
|
||||||
"""Helper to enhance drops with countdown and context.
|
"""Helper to enhance drops with countdown and context.
|
||||||
|
|
||||||
|
|
@ -264,6 +270,7 @@ def _enhance_drops_with_context(drops: QuerySet[TimeBasedDrop], now: datetime.da
|
||||||
return enhanced
|
return enhanced
|
||||||
|
|
||||||
|
|
||||||
|
# MARK: /campaigns/<twitch_id>/
|
||||||
def drop_campaign_detail_view(request: HttpRequest, twitch_id: str) -> HttpResponse:
|
def drop_campaign_detail_view(request: HttpRequest, twitch_id: str) -> HttpResponse:
|
||||||
"""Function-based view for a drop campaign detail.
|
"""Function-based view for a drop campaign detail.
|
||||||
|
|
||||||
|
|
@ -303,6 +310,8 @@ def drop_campaign_detail_view(request: HttpRequest, twitch_id: str) -> HttpRespo
|
||||||
"image_url",
|
"image_url",
|
||||||
"start_at",
|
"start_at",
|
||||||
"end_at",
|
"end_at",
|
||||||
|
"allow_is_enabled",
|
||||||
|
"operation_name",
|
||||||
"game",
|
"game",
|
||||||
"created_at",
|
"created_at",
|
||||||
"updated_at",
|
"updated_at",
|
||||||
|
|
@ -315,11 +324,14 @@ def drop_campaign_detail_view(request: HttpRequest, twitch_id: str) -> HttpRespo
|
||||||
"json",
|
"json",
|
||||||
drops,
|
drops,
|
||||||
fields=(
|
fields=(
|
||||||
|
"twitch_id",
|
||||||
"name",
|
"name",
|
||||||
"required_minutes_watched",
|
"required_minutes_watched",
|
||||||
"required_subs",
|
"required_subs",
|
||||||
"start_at",
|
"start_at",
|
||||||
"end_at",
|
"end_at",
|
||||||
|
"added_at",
|
||||||
|
"updated_at",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
drops_data: list[dict[str, Any]] = json.loads(serialized_drops)
|
drops_data: list[dict[str, Any]] = json.loads(serialized_drops)
|
||||||
|
|
@ -330,7 +342,17 @@ def drop_campaign_detail_view(request: HttpRequest, twitch_id: str) -> HttpRespo
|
||||||
serialized_benefits = serialize(
|
serialized_benefits = serialize(
|
||||||
"json",
|
"json",
|
||||||
drop_benefits,
|
drop_benefits,
|
||||||
fields=("name", "image_asset_url"),
|
fields=(
|
||||||
|
"twitch_id",
|
||||||
|
"name",
|
||||||
|
"image_asset_url",
|
||||||
|
"added_at",
|
||||||
|
"updated_at",
|
||||||
|
"created_at",
|
||||||
|
"entitlement_limit",
|
||||||
|
"is_ios_available",
|
||||||
|
"distribution_type",
|
||||||
|
),
|
||||||
)
|
)
|
||||||
benefits_data = json.loads(serialized_benefits)
|
benefits_data = json.loads(serialized_benefits)
|
||||||
drops_data[i]["fields"]["benefits"] = benefits_data
|
drops_data[i]["fields"]["benefits"] = benefits_data
|
||||||
|
|
@ -541,11 +563,14 @@ class GameDetailView(DetailView):
|
||||||
"json",
|
"json",
|
||||||
[game],
|
[game],
|
||||||
fields=(
|
fields=(
|
||||||
|
"twitch_id",
|
||||||
"slug",
|
"slug",
|
||||||
"name",
|
"name",
|
||||||
"display_name",
|
"display_name",
|
||||||
"box_art",
|
"box_art",
|
||||||
"owner",
|
"owner",
|
||||||
|
"added_at",
|
||||||
|
"updated_at",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
game_data: list[dict[str, Any]] = json.loads(serialized_game)
|
game_data: list[dict[str, Any]] = json.loads(serialized_game)
|
||||||
|
|
@ -563,6 +588,12 @@ class GameDetailView(DetailView):
|
||||||
"image_url",
|
"image_url",
|
||||||
"start_at",
|
"start_at",
|
||||||
"end_at",
|
"end_at",
|
||||||
|
"allow_is_enabled",
|
||||||
|
"allow_channels",
|
||||||
|
"game",
|
||||||
|
"operation_name",
|
||||||
|
"added_at",
|
||||||
|
"updated_at",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
campaigns_data: list[dict[str, Any]] = json.loads(
|
campaigns_data: list[dict[str, Any]] = json.loads(
|
||||||
|
|
@ -922,8 +953,11 @@ class ChannelDetailView(DetailView):
|
||||||
"json",
|
"json",
|
||||||
[channel],
|
[channel],
|
||||||
fields=(
|
fields=(
|
||||||
|
"twitch_id",
|
||||||
"name",
|
"name",
|
||||||
"display_name",
|
"display_name",
|
||||||
|
"added_at",
|
||||||
|
"updated_at",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
channel_data = json.loads(serialized_channel)
|
channel_data = json.loads(serialized_channel)
|
||||||
|
|
@ -941,6 +975,8 @@ class ChannelDetailView(DetailView):
|
||||||
"image_url",
|
"image_url",
|
||||||
"start_at",
|
"start_at",
|
||||||
"end_at",
|
"end_at",
|
||||||
|
"added_at",
|
||||||
|
"updated_at",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
campaigns_data = json.loads(serialized_campaigns)
|
campaigns_data = json.loads(serialized_campaigns)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue