API methods

class kolibri.core.content.api.BaseContentNodeMixin[source]

A base mixin for viewsets that need to return the same format of data serialization for ContentNodes.

class kolibri.core.content.api.ChannelMetadataViewSet(**kwargs)[source]
dispatch(request, *args, **kwargs)

.dispatch() is pretty much the same as Django’s regular dispatch, but with extra hooks for startup, finalize, and exception handling.

get_queryset()[source]

Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.

This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.

You may want to override this if you need to provide different querysets depending on the incoming request.

(Eg. return a list of items that is specific to the user)

serializer_class

alias of kolibri.core.content.serializers.ChannelMetadataSerializer

class kolibri.core.content.api.ContentNodeBookmarksViewset(*args, **kwargs)[source]
get_queryset()[source]

Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.

This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.

You may want to override this if you need to provide different querysets depending on the incoming request.

(Eg. return a list of items that is specific to the user)

pagination_class

alias of kolibri.core.utils.pagination.ValuesViewsetLimitOffsetPagination

class kolibri.core.content.api.ContentNodeGranularViewset(**kwargs)[source]
get_queryset()[source]

Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.

This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.

You may want to override this if you need to provide different querysets depending on the incoming request.

(Eg. return a list of items that is specific to the user)

get_serializer_context()[source]

Extra context provided to the serializer class.

serializer_class

alias of kolibri.core.content.serializers.ContentNodeGranularSerializer

class kolibri.core.content.api.ContentNodeProgressViewset(*args, **kwargs)[source]
get_queryset()[source]

Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.

This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.

You may want to override this if you need to provide different querysets depending on the incoming request.

(Eg. return a list of items that is specific to the user)

class kolibri.core.content.api.ContentNodeSearchViewset(*args, **kwargs)[source]
search(value, max_results, filter=True)[source]

Implement various filtering strategies in order to get a wide range of search results. When filter is used, this object must have a request attribute having a ‘query_params’ QueryDict containing the filters to be applied

class kolibri.core.content.api.ContentNodeTreeViewset(*args, **kwargs)[source]
dispatch(request, *args, **kwargs)

.dispatch() is pretty much the same as Django’s regular dispatch, but with extra hooks for startup, finalize, and exception handling.

retrieve(request, **kwargs)[source]

A nested, paginated representation of the children and grandchildren of a specific node

GET parameters on request can be: depth - a value of either 1 or 2 indicating the depth to recurse the tree, either 1 or 2 levels if this parameter is missing it will default to 2. lft__gt - a value to return child nodes with a lft value greater than this, if missing defaults to None

The pagination object returned for “children” will have this form: results - a list of serialized children, that can also have their own nested children attribute. more - a dictionary or None, if a dictionary, will have an id key that is the id of the parent object for these children, and a params key that is a dictionary of the required query parameters to query more children for this parent - at a minimum this will include lft__gt and depth, but may also include other query parameters for filtering content nodes.

The “more” property describes the “id” required to do URL reversal on this endpoint, and the params that should be passed as query parameters to get the next set of results for pagination.

Parameters
  • request – request object

  • pk – id parent node

Returns

an object representing the parent with a pagination object as “children”

class kolibri.core.content.api.ContentNodeViewset(*args, **kwargs)[source]
copies(request, pk=None)[source]

Returns each nodes that has this content id, along with their ancestors.

copies_count(request, **kwargs)[source]

Returns the number of node copies for each content id.

descendants(request)[source]

Returns a slim view all the descendants of a set of content nodes (as designated by the passed in ids). In addition to id, title, kind, and content_id, each node is also annotated with the ancestor_id of one of the ids that are passed into the request. In the case where a node has more than one ancestor in the set of content nodes requested, duplicates of that content node are returned, each annotated with one of the ancestor_ids for a node.

dispatch(request, *args, **kwargs)

.dispatch() is pretty much the same as Django’s regular dispatch, but with extra hooks for startup, finalize, and exception handling.

next_steps(request, **kwargs)[source]

Recommend content that has user completed content as a prerequisite, or leftward sibling. Note that this is a slightly smelly use of a detail route, as the id in question is not for a contentnode, but rather for a user. Recommend we move recommendation endpoints to their own endpoints in future.

Parameters
  • request – request object

  • pk – id of the user whose recommendations they are

Returns

uncompleted content nodes, or empty queryset if user is anonymous

pagination_class

alias of OptionalPageNumberPagination

popular(request, **kwargs)[source]

Recommend content that is popular with all users.

Parameters

request – request object

Returns

10 most popular content nodes

recommendations_for(request, **kwargs)[source]

Recommend items that are similar to this piece of content.

resume(request, **kwargs)[source]

Recommend content that the user has recently engaged with, but not finished. Note that this is a slightly smelly use of a detail route, as the id in question is not for a contentnode, but rather for a user. Recommend we move recommendation endpoints to their own endpoints in future.

Parameters
  • request – request object

  • pk – id of the user whose recommendations they are

Returns

10 most recently viewed content nodes

class kolibri.core.content.api.FileViewset(**kwargs)[source]
get_queryset()[source]

Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.

This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.

You may want to override this if you need to provide different querysets depending on the incoming request.

(Eg. return a list of items that is specific to the user)

pagination_class

alias of OptionalPageNumberPagination

serializer_class

alias of kolibri.core.content.serializers.FileSerializer

class kolibri.core.content.api.OptionalPageNumberPagination[source]

Pagination class that allows for page number-style pagination, when requested. To activate, the page_size argument must be set. For example, to request the first 20 records: ?page_size=20&page=1

class kolibri.core.content.api.RemoteChannelViewSet(**kwargs)[source]
list(request, *args, **kwargs)[source]

Gets metadata about all public channels on kolibri studio.

retrieve(request, pk=None)[source]

Gets metadata about a channel through a token or channel id.

kolibri.core.content.api.cache_forever(some_func)[source]

Decorator for patch_response_headers function