diff --git a/templates/twitch/org_list.html b/templates/twitch/org_list.html
index d48d613..e0bf28c 100644
--- a/templates/twitch/org_list.html
+++ b/templates/twitch/org_list.html
@@ -1,6 +1,6 @@
{% extends "base.html" %}
{% block title %}
- Games
+ Organizations
{% endblock title %}
{% block content %}
Organizations
@@ -13,6 +13,7 @@
{% endfor %}
{% else %}
- No games found.
+ No organizations found.
{% endif %}
+ {{ orgs_data|safe }}
{% endblock content %}
diff --git a/templates/twitch/organization_detail.html b/templates/twitch/organization_detail.html
index 6c2705f..7841bc3 100644
--- a/templates/twitch/organization_detail.html
+++ b/templates/twitch/organization_detail.html
@@ -35,5 +35,5 @@
{% endfor %}
- {{ org_data }}
+ {{ org_data|safe }}
{% endblock content %}
diff --git a/twitch/urls.py b/twitch/urls.py
index 2f6962a..96e6703 100644
--- a/twitch/urls.py
+++ b/twitch/urls.py
@@ -23,7 +23,7 @@ urlpatterns: list[URLPattern] = [
path("games/", views.GamesGridView.as_view(), name="game_list"),
path("games/list/", views.GamesListView.as_view(), name="game_list_simple"),
path("games//", views.GameDetailView.as_view(), name="game_detail"),
- path("organizations/", views.OrgListView.as_view(), name="org_list"),
+ path("organizations/", views.org_list_view, name="org_list"),
path("organizations//", views.organization_detail_view, name="organization_detail"),
path("channels/", views.ChannelListView.as_view(), name="channel_list"),
path("channels//", views.ChannelDetailView.as_view(), name="channel_detail"),
diff --git a/twitch/views.py b/twitch/views.py
index 4af80b2..624fd27 100644
--- a/twitch/views.py
+++ b/twitch/views.py
@@ -97,12 +97,36 @@ def search_view(request: HttpRequest) -> HttpResponse:
# MARK: /organizations/
-class OrgListView(ListView):
- """List view for organization."""
+def org_list_view(request: HttpRequest) -> HttpResponse:
+ """Function-based view for organization list.
- model = Organization
- template_name = "twitch/org_list.html"
- context_object_name = "orgs"
+ Args:
+ request: The HTTP request.
+
+ Returns:
+ HttpResponse: The rendered organization list page.
+ """
+ orgs: QuerySet[Organization] = Organization.objects.all().order_by("name")
+
+ # Serialize all organizations
+ serialized_orgs: str = serialize(
+ "json",
+ orgs,
+ fields=(
+ "twitch_id",
+ "name",
+ "added_at",
+ "updated_at",
+ ),
+ )
+ orgs_data: list[dict] = json.loads(serialized_orgs)
+
+ context: dict[str, Any] = {
+ "orgs": orgs,
+ "orgs_data": format_and_color_json(orgs_data),
+ }
+
+ return render(request, "twitch/org_list.html", context)
# MARK: /organizations//
@@ -156,12 +180,10 @@ def organization_detail_view(request: HttpRequest, twitch_id: str) -> HttpRespon
games_data: list[dict] = json.loads(serialized_games)
org_data[0]["fields"]["games"] = games_data
- pretty_org_data: str = json.dumps(org_data[0], indent=4)
-
context: dict[str, Any] = {
"organization": organization,
"games": games,
- "org_data": pretty_org_data,
+ "org_data": format_and_color_json(org_data[0]),
}
return render(request, "twitch/organization_detail.html", context)
@@ -217,16 +239,16 @@ def drop_campaign_list_view(request: HttpRequest) -> HttpResponse:
return render(request, "twitch/campaign_list.html", context)
-def format_and_color_json(data: dict[str, Any] | str) -> str:
+def format_and_color_json(data: dict[str, Any] | list[dict] | str) -> str:
"""Format and color a JSON string for HTML display.
Args:
- data: Either a dictionary or a JSON string to format.
+ data: Either a dictionary, list of dictionaries, or a JSON string to format.
Returns:
str: The formatted code with HTML styles.
"""
- if isinstance(data, dict):
+ if isinstance(data, (dict, list)):
formatted_code: str = json.dumps(data, indent=4)
else:
formatted_code = data