-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #766 from openedx/asheehan-edx/ENT-8377
feat: new content metadata readonly viewset
- Loading branch information
Showing
4 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from edx_rest_framework_extensions.auth.jwt.authentication import ( | ||
JwtAuthentication, | ||
) | ||
from rest_framework import permissions, viewsets | ||
from rest_framework.authentication import SessionAuthentication | ||
from rest_framework.renderers import JSONRenderer | ||
from rest_framework_xml.renderers import XMLRenderer | ||
|
||
from enterprise_catalog.apps.api.v1.pagination import ( | ||
PageNumberWithSizePagination, | ||
) | ||
from enterprise_catalog.apps.api.v1.serializers import ContentMetadataSerializer | ||
from enterprise_catalog.apps.catalog.models import ContentMetadata | ||
|
||
|
||
class ContentMetadataView(viewsets.ReadOnlyModelViewSet): | ||
""" | ||
View for retrieving and listing base content metadata. | ||
""" | ||
serializer_class = ContentMetadataSerializer | ||
authentication_classes = [JwtAuthentication, SessionAuthentication] | ||
permission_classes = [permissions.IsAuthenticated] | ||
renderer_classes = [JSONRenderer, XMLRenderer] | ||
queryset = ContentMetadata.objects.all() | ||
pagination_class = PageNumberWithSizePagination | ||
|
||
def get_queryset(self, **kwargs): | ||
""" | ||
Returns all content metadata objects filtered by an optional request query param ``content_keys`` (LIST). | ||
""" | ||
content_filter = kwargs.get('content_keys') | ||
queryset = self.queryset | ||
if content_filter: | ||
return queryset.filter(content_key__in=content_filter) | ||
return queryset |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters