diff --git a/pod/video/tests/test_views.py b/pod/video/tests/test_views.py index 1998a40382..153f463773 100644 --- a/pod/video/tests/test_views.py +++ b/pod/video/tests/test_views.py @@ -1527,7 +1527,7 @@ def test_get_channels_for_navbar(self): ) self.assertEqual( response.content, - b'{"channels": {"1": {"id": 1, "url": "/first-channel/", "title": "First channel", "description": "", "headband": null, "color": null, "style": null, "owners": ["http://testserver/rest/users/1/"], "users": [], "visible": true, "themes": 0, "site": "http://testserver/rest/sites/1/", "videoCount": 1, "headbandImage": ""}}, "currentPage": 1, "totalPages": 1, "count": 1}', + b'{"channels": {"0": {"id": 1, "url": "/first-channel/", "title": "First channel", "description": "", "headband": null, "color": null, "style": null, "owners": ["http://testserver/rest/users/1/"], "users": [], "visible": true, "themes": 0, "site": "http://testserver/rest/sites/1/", "videoCount": 1, "headbandImage": ""}}, "currentPage": 1, "totalPages": 1, "count": 1}', "[test_get_channels_for_navbar] Test if the response content is correct.", ) print(" ---> test_get_channels_for_navbar : OK!") @@ -1548,7 +1548,7 @@ def test_get_channel_tabs_for_navbar(self): ) self.assertEqual( response.content, - b'{"1": {"id": 1, "name": "Simple addional channel tab"}}', + b'{"0": {"id": 1, "name": "Simple addional channel tab"}}', "[test_get_channel_tabs_for_navbar] Test if the response content is correct.", ) print(" ---> test_get_channel_tabs_for_navbar : OK!") @@ -1571,7 +1571,7 @@ def test_get_channels_for_specific_channel_tab(self): ) self.assertEqual( response.content, - b'{"channels": {"2": {"id": 2, "url": "/second-channel/", "title": "Second channel", "description": "", "headband": null, "color": null, "style": null, "owners": ["http://testserver/rest/users/1/"], "users": [], "visible": true, "themes": 0, "site": "http://testserver/rest/sites/1/", "videoCount": 1, "headbandImage": ""}}, "currentPage": 1, "totalPages": 1, "count": 1}', + b'{"channels": {"0": {"id": 2, "url": "/second-channel/", "title": "Second channel", "description": "", "headband": null, "color": null, "style": null, "owners": ["http://testserver/rest/users/1/"], "users": [], "visible": true, "themes": 0, "site": "http://testserver/rest/sites/1/", "videoCount": 1, "headbandImage": ""}}, "currentPage": 1, "totalPages": 1, "count": 1}', "[test_get_channels_for_specific_channel_tab] Test if the response content is correct.", ) print(" ---> test_get_channels_for_specific_channel_tab : OK!") diff --git a/pod/video/views.py b/pod/video/views.py index eec6af0337..419e87526b 100644 --- a/pod/video/views.py +++ b/pod/video/views.py @@ -2934,18 +2934,18 @@ def get_serialized_channels(request: WSGIRequest, channels: QueryDict) -> dict: dict: The channel list in JSON format. """ channels_json_format = {} - for channel in channels: - channels_json_format[channel.pk] = ChannelSerializer( + for num, channel in enumerate(channels): + channels_json_format[num] = ChannelSerializer( channel, context={"request": request} ).data - channels_json_format[channel.pk]["url"] = reverse( + channels_json_format[num]["url"] = reverse( "channel-video:channel", kwargs={"slug_c": channel.slug} ) - channels_json_format[channel.pk]["videoCount"] = channel.video_count - channels_json_format[channel.pk]["headbandImage"] = ( + channels_json_format[num]["videoCount"] = channel.video_count + channels_json_format[num]["headbandImage"] = ( channel.headband.file.url if channel.headband else "" ) - channels_json_format[channel.pk]["themes"] = channel.themes.count() + channels_json_format[num]["themes"] = channel.themes.count() return channels_json_format @@ -2961,8 +2961,8 @@ def get_channel_tabs_for_navbar(request: WSGIRequest) -> JsonResponse: """ channel_tabs = AdditionalChannelTab.objects.all() channel_tabs_json_format = {} - for channel_tab in channel_tabs: - channel_tabs_json_format[channel_tab.pk] = { + for num, channel_tab in enumerate(channel_tabs): + channel_tabs_json_format[num] = { "id": channel_tab.pk, "name": channel_tab.name, }