|
7 | 7 | from django.db.models import Q, Sum |
8 | 8 | from django.db.models.aggregates import Count |
9 | 9 | from kolibri.content import models, serializers |
10 | | -from kolibri.content.content_db_router import get_active_content_database |
| 10 | +from kolibri.content.content_db_router import get_active_content_database, using_content_database |
11 | 11 | from kolibri.logger.models import ContentSessionLog, ContentSummaryLog |
12 | 12 | from le_utils.constants import content_kinds |
13 | 13 | from rest_framework import filters, pagination, viewsets |
@@ -359,10 +359,11 @@ def get_queryset(self): |
359 | 359 |
|
360 | 360 | class ChannelFileSummaryViewSet(viewsets.ViewSet): |
361 | 361 | def list(self, request, **kwargs): |
362 | | - file_summary = models.File.objects.aggregate( |
363 | | - total_files=Count('pk'), |
364 | | - total_file_size=Sum('file_size') |
365 | | - ) |
366 | | - file_summary['channel_id'] = get_active_content_database() |
367 | | - # Need to wrap in an array to be fetchable as a Collection on client |
368 | | - return Response([file_summary]) |
| 362 | + with using_content_database(kwargs['channel_id']): |
| 363 | + file_summary = models.File.objects.aggregate( |
| 364 | + total_files=Count('pk'), |
| 365 | + total_file_size=Sum('file_size') |
| 366 | + ) |
| 367 | + file_summary['channel_id'] = get_active_content_database() |
| 368 | + # Need to wrap in an array to be fetchable as a Collection on client |
| 369 | + return Response([file_summary]) |
0 commit comments