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. Also used for public ContentNode endpoints!

class kolibri.core.content.api.BaseContentNodeTreeViewset(*args, **kwargs)[source]
retrieve(request, pk=None)[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. next__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 next__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.ChannelMetadataViewSet(*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.

class kolibri.core.content.api.CharInFilter(*args, **kwargs)[source]
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 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 ContentNodeGranularSerializer

class kolibri.core.content.api.ContentNodeProgressViewset(**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 OptionalPagination

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

Runs anything that needs to occur prior to calling the method handler.

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, pk=None)[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. next__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 next__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]
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.

pagination_class

alias of OptionalContentNodePagination

recommendations_for(request, **kwargs)[source]

Recommend items that are similar to this piece of content.

class kolibri.core.content.api.ContentRequestViewset(*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 OptionalPageNumberPagination

serializer_class

alias of ContentDownloadRequestSerializer

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 FileSerializer

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

A mixin for all content node viewsets for internal use, whereas BaseContentNodeMixin is reused for public API endpoints also.

class kolibri.core.content.api.OptionalContentNodePagination[source]
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.OptionalPagination[source]
class kolibri.core.content.api.RemoteChannelViewSet(**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.

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.

class kolibri.core.content.api.RemoteViewSet(*args, **kwargs)[source]
class kolibri.core.content.api.UUIDInFilter(*args, **kwargs)[source]
class kolibri.core.content.api.UserContentNodeViewset(*args, **kwargs)[source]

A content node viewset for filtering on user specific fields.

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 OptionalPagination

kolibri.core.content.api.metadata_cache(view_func, cache_key_func=<function get_cache_key>)[source]

Decorator to apply an Etag sensitive page cache

kolibri.core.content.api.no_cache_on_method(view_func)[source]

Decorator to disable caching for a particular method