kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

Add modality filter to ContentNode API endpoint

Open rtibbles opened this issue 1 month ago • 0 comments

This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.

Overview

Add a modality query parameter filter to the ContentNode API endpoint in kolibri/core/content/api.py to enable filtering content by modality values (COURSE, QUIZ, SURVEY, etc.).

Implementation

Since the modality field on the ContentNode model will have choices=modalities.choices, Django Rest Framework's FilterBackend should automatically infer the appropriate filter type.

Simply add "modality" to the contentnode_filter_fields list (around line 433 in kolibri/core/content/api.py):

contentnode_filter_fields = [
    "parent",
    "parent__isnull",
    # ... existing fields ...
    "modality",  # Add this
]

Usage

This will allow API calls like:

  • /api/content/contentnode/?modality=COURSE - Filter to only course content
  • /api/content/contentnode/?modality=QUIZ - Filter to only quiz content
  • /api/content/contentnode/?modality=SURVEY - Filter to only survey content

Benefits

  • Enables efficient filtering by modality without JSON field queries
  • Leverages the database index on the modality field for performance
  • Consistent with other simple field filters in the API

Available Modality Values

From le_utils.constants.modalities:

  • COURSE
  • CUSTOM_NAVIGATION
  • LESSON
  • QUIZ
  • SURVEY
  • UNIT

🤖 This issue was written by Claude Code, under supervision, review and final edits by @rtibbles 🤖

rtibbles avatar Dec 04 '25 22:12 rtibbles