Skip to content

Commit

Permalink
Filter partial channels when fetching page data for selecting more co…
Browse files Browse the repository at this point in the history
…ntent.
  • Loading branch information
rtibbles committed Sep 13, 2023
1 parent 5cb0c55 commit 6ce6b34
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
11 changes: 10 additions & 1 deletion kolibri/plugins/device/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from django.db.models import Case
from django.db.models import When
from django_filters.rest_framework import BooleanFilter
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import viewsets
from rest_framework.exceptions import ParseError
Expand Down Expand Up @@ -87,10 +88,18 @@ def to_representation(self, instance):
return value


class DeviceChannelMetadataFilter(ChannelMetadataFilter):
partial = BooleanFilter(field_name="partial", label="Partial")

class Meta:
model = ChannelMetadata
fields = ("partial", "available", "has_exercise")


class DeviceChannelMetadataViewSet(viewsets.ReadOnlyModelViewSet):
serializer_class = DeviceChannelMetadataSerializer
filter_backends = (DjangoFilterBackend,)
filter_class = ChannelMetadataFilter
filter_class = DeviceChannelMetadataFilter
permission_classes = (CanManageContent,)

def get_queryset(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@ import ChannelResource from '../../apiResources/deviceChannel';

// Gets Metadata for Channels whose DBs have been downloaded onto the server.
// Response includes all of the file/resource sizes.
export function getChannelWithContentSizes(channelId) {
export function getChannelWithContentSizes(channelId, filterPartialChannels = true) {
const getParams = {
include_fields: [
'total_resources',
'total_file_size',
'on_device_resources',
'on_device_file_size',
'new_resource_count',
'new_resource_total_size',
],
};
if (filterPartialChannels) {
getParams.partial = false;
}
return new Promise((resolve, reject) => {
ChannelResource.fetchModel({
id: channelId,
getParams: {
include_fields: [
'total_resources',
'total_file_size',
'on_device_resources',
'on_device_file_size',
'new_resource_count',
'new_resource_total_size',
],
},
getParams,
force: true,
}).then(resolve, reject);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function fetchPageData(channelId) {
});
return Promise.all([
getDeviceInfo(),
getChannelWithContentSizes(this.channelId),
getChannelWithContentSizes(channelId, false),
studioChannelPromise,
]).then(([deviceInfo, channel, studioChannel]) => {
return {
Expand Down

0 comments on commit 6ce6b34

Please sign in to comment.