Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CustomContent: Add withinDescendant parameter to API #8796

Merged

Conversation

danigm
Copy link
Contributor

@danigm danigm commented Dec 2, 2021

Summary

This patch adds a new optional parameter to the getContentByFilter API call to be able to retrieve all descendant nodes using the MPTT model fields.

With this new parameter it's possible to filter all the nodes below a specific topic node, useful when combining with other filters like kind or tags.

@@ -123,6 +130,7 @@ export default class Kolibri extends BaseShim {
* @param {boolean} options.onlyContent - set to true to query only content nodes
* @param {boolean} [options.limitToChannel=true] - true to limit the
* results to the topic channel
* @param {MPTTNode} options.withinDescendant - Object to filter nodes descendant of this one
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This requires that the HTML5 apps are aware of the implementation details of MPTT - perhaps it would be better for this to just be the id of the node to fetch descendants of?

We can add a descendant_of filter to the backend: https://github.com/learningequality/kolibri/blob/release-v0.15.x/kolibri/core/content/api.py#L250 that does the lookup for the node - something like:

def filter_descendant_of(self, queryset, name, value):
    try:
        node = ContentNode.objects.values("lft", "rght", "tree_id").get(pk=value)
    except (ContentNode.DoesNotExist, ValueError):
        return queryset.none()
    return queryset.filter(lft__gt=node["lft"], rght__lt=node["rght"], tree_id=node["tree_id"])

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, that's a better API and moving the logic to the backend simplifies the frontend logic. I'll update the PR to follow that implementation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just updated the PR with the new filter and the parameter descendantOf that should be a node id.

This patch adds a new optional parameter to the getContentByFilter API
call to be able to retrieve all descendant nodes using the MPTT model
fields.

With this new parameter it's possible to filter all the nodes below a
specific topic node, useful when combining with other filters like kind
or tags.
danigm added a commit to endlessm/kolibri-explore-plugin that referenced this pull request Dec 3, 2021
@rtibbles rtibbles merged commit 89c0299 into learningequality:release-v0.15.x Dec 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants