-
-
Notifications
You must be signed in to change notification settings - Fork 938
Exclude Courses in Search, Resume, Library & plugin_data flag for courses #14132
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
Changes from all commits
69ad13f
e9fc46b
4bb8522
be5d0b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,6 +58,7 @@ | |
| from kolibri.core.content import models | ||
| from kolibri.core.content import serializers | ||
| from kolibri.core.content.models import ContentDownloadRequest | ||
| from kolibri.core.content.models import ContentNode | ||
| from kolibri.core.content.models import ContentRemovalRequest | ||
| from kolibri.core.content.models import ContentRequestReason | ||
| from kolibri.core.content.models import ContentRequestStatus | ||
|
|
@@ -111,6 +112,20 @@ def get_cache_key(*args, **kwargs): | |
| return str(ContentCacheKey.get_cache_key()) | ||
|
|
||
|
|
||
| def get_course_ids(): | ||
| cache_key = "COURSE_IDS_{}".format(get_cache_key()) | ||
| cached_data = cache.get(cache_key) | ||
| if cached_data is not None: | ||
| return cached_data | ||
| updated_data = list( | ||
| ContentNode.objects.filter( | ||
| available=True, modality=modalities.COURSE | ||
| ).values_list("id", flat=True) | ||
| ) | ||
| cache.set(cache_key, updated_data, 3600) | ||
| return updated_data | ||
|
|
||
|
|
||
| def metadata_cache(view_func, cache_key_func=get_cache_key): | ||
| """ | ||
| Decorator to apply an Etag sensitive page cache | ||
|
|
@@ -465,6 +480,7 @@ class ChoiceInFilter(BaseInFilter, ChoiceFilter): | |
| "tree_id", | ||
| "lft__gt", | ||
| "rght__lt", | ||
| "exclude_course_ancestry", | ||
| ] | ||
|
|
||
|
|
||
|
|
@@ -498,11 +514,30 @@ class ContentNodeFilter(FilterSet): | |
| exclude_modalities = ChoiceInFilter( | ||
| field_name="modality", choices=modalities.choices, exclude=True | ||
| ) | ||
| exclude_course_ancestry = BooleanFilter(method="filter_exclude_course_ancestry") | ||
|
|
||
| class Meta: | ||
| model = models.ContentNode | ||
| fields = contentnode_filter_fields | ||
|
|
||
| def filter_exclude_course_ancestry(self, queryset, name, value): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. blocking: The def filter_exclude_course_ancestry(self, queryset, name, value):
if not value:
return queryset
...Currently the filter is always called with |
||
| """ | ||
| Exclude any resources that are descended from a Course. | ||
| :param queryset: ContentNode queryset to filter | ||
| :param name: filter field name | ||
| :param value: boolean indicating whether to apply the exclusion | ||
| :return: filtered queryset excluding course descendants if value is True | ||
| """ | ||
| if not value: | ||
| return queryset | ||
| has_course_ancestor = ContentNode.objects.filter( | ||
| id__in=get_course_ids(), | ||
| lft__lt=OuterRef("lft"), | ||
| rght__gt=OuterRef("rght"), | ||
| tree_id=OuterRef("tree_id"), | ||
| ) | ||
| return queryset.exclude(Exists(has_course_ancestor)) | ||
nucleogenesis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def filter_ids(self, queryset, name, value): | ||
| return queryset.filter_by_uuids(value) | ||
|
|
||
|
|
@@ -570,7 +605,10 @@ def filter_kind_in(self, queryset, name, value): | |
| return queryset.filter(kind__in=kinds).order_by("lft") | ||
|
|
||
| def filter_exclude_content_ids(self, queryset, name, value): | ||
| return queryset.exclude_by_content_ids(value.split(",")) | ||
| if not value: | ||
| return queryset | ||
| else: | ||
nucleogenesis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return queryset.exclude_by_content_ids(value.split(",")) | ||
|
|
||
| def filter_include_coach_content(self, queryset, name, value): | ||
| if value: | ||
|
|
@@ -1278,7 +1316,6 @@ def search(self, value, max_results, filter=True): | |
|
|
||
| # iterate over each query type, and build up search results | ||
| for query in all_queries: | ||
|
|
||
| # in each pass, don't take any items already in the result set | ||
| matches = ( | ||
| queryset.exclude_by_content_ids(list(content_ids), validate=False) | ||
|
|
@@ -1700,7 +1737,10 @@ def filter_by_popular(self, queryset, name, value): | |
|
|
||
| class Meta: | ||
| model = models.ContentNode | ||
| fields = contentnode_filter_fields + ["resume", "lesson"] | ||
| fields = contentnode_filter_fields + [ | ||
| "resume", | ||
| "lesson", | ||
| ] | ||
|
|
||
|
|
||
| class UserContentNodeViewset( | ||
|
|
@@ -1868,7 +1908,6 @@ def _make_channel_endpoint_request( | |
| identifier=identifier, baseurl=baseurl, keyword=keyword, language=language | ||
| ) | ||
| try: | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did this line offend thee? |
||
| resp = client.get(url) | ||
| # map the channel list into the format the Kolibri client-side expects | ||
| channels = list(map(self._studio_response_to_kolibri_response, resp.json())) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ import { | |
| } from 'kolibri/constants'; | ||
| import useUser from 'kolibri/composables/useUser'; | ||
|
|
||
| import Modalities from 'kolibri-constants/Modalities'; | ||
| import { deduplicateResources } from '../utils/contentNode'; | ||
|
|
||
| export const logging = logger.getLogger(__filename); | ||
|
|
@@ -242,6 +243,9 @@ export default function useBaseSearch({ | |
|
|
||
| function createBaseSearchGetParams() { | ||
| const getParams = { | ||
| exclude_modalities: | ||
| get(isAdmin) || get(isCoach) || get(isSuperuser) ? null : Modalities.COURSE, | ||
| exclude_course_ancestry: !(get(isAdmin) || get(isCoach) || get(isSuperuser)), | ||
| include_coach_content: get(isAdmin) || get(isCoach) || get(isSuperuser), | ||
| baseurl: get(baseurl), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this changed?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Claude noticed that the previous implementation would result in there being I think Claude noticed the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, but undefined params don't get sent, so this is fine. |
||
| }; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.