From 8adcd58a573f9b3bf14d5a28828b815c8b633ced Mon Sep 17 00:00:00 2001 From: Bryan Wilson Date: Fri, 7 Jul 2023 17:01:36 -0700 Subject: [PATCH] fix filterset_kwargs and model lookup --- .../djangoapps/appsembler/openedx_api/filters.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/openedx/core/djangoapps/appsembler/openedx_api/filters.py b/openedx/core/djangoapps/appsembler/openedx_api/filters.py index 7b4d31bec8dc..5852f144069d 100644 --- a/openedx/core/djangoapps/appsembler/openedx_api/filters.py +++ b/openedx/core/djangoapps/appsembler/openedx_api/filters.py @@ -86,19 +86,14 @@ class AllowedCourseOrgFilterSet(filters.FilterSet): def filter_allowed_org(self, queryset, name, value): import pdb; pdb.set_trace() - try: - user_allowed_org = self.request.user.organizations.first() - except Organization.DoesNotExist: - raise # TODO: do something else - try: lookup = self.MODEL_COURSE_ORG_LOOKUPS[self.queryset.model] except KeyError: raise # TODO: do something else - if model in self.OPAQUE_KEY_FIELD_LOOKUP_MODELS: + if self.queryset.model in self.OPAQUE_KEY_FIELD_LOOKUP_MODELS: return queryset.filter(**{lookup: "{}{}+".format(COURSE_PREFIX, user_allowed_org)}) - elif model in self.STRING_ORG_NAME_LOOKUP_MODELS: + elif self.queryset.model in self.STRING_ORG_NAME_LOOKUP_MODELS: return queryset.filter(**{lookup: user_allowed_org.short_name}) else: return queryset.filter(**{lookup: user_allowed_org}) @@ -140,8 +135,9 @@ def get_filterset_kwargs(self, request, queryset, view): except Organization.DoesNotExist: raise # TODO: do something else q_params = copy.deepcopy(request.query_params) + q_params.update({"allowed_org": user_allowed_org}) return { - "data": q_params.update({"allowed_org": user_allowed_org}), + "data": q_params, "queryset": queryset, "request": request, }