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
CustomContent: Add withinDescendant parameter to API #8796
Conversation
packages/hashi/src/kolibri.js
Outdated
@@ -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 |
There was a problem hiding this comment.
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"])
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
4385631
to
a505798
Compare
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.
a505798
to
6907d4b
Compare
This change adapts the API to the changes upstream in this PR: learningequality/kolibri#8796 https://phabricator.endlessm.com/T32761
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.