예제 #1
0
 def get(self, request, lib_key_str):
     """
     Get the list of bundles that this library links to, if any
     """
     key = LibraryLocatorV2.from_string(lib_key_str)
     api.require_permission_for_library_key(key, request.user, permissions.CAN_VIEW_THIS_CONTENT_LIBRARY)
     result = api.get_bundle_links(key)
     return Response(LibraryBundleLinkSerializer(result, many=True).data)
예제 #2
0
 def post(self, request, lib_key_str):
     """
     Create a new link in this library.
     """
     key = LibraryLocatorV2.from_string(lib_key_str)
     api.require_permission_for_library_key(key, request.user, permissions.CAN_EDIT_THIS_CONTENT_LIBRARY)
     serializer = LibraryBundleLinkSerializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     target_key = LibraryLocatorV2.from_string(serializer.validated_data['opaque_key'])
     api.create_bundle_link(
         library_key=key,
         link_id=serializer.validated_data['id'],
         target_opaque_key=target_key,
         version=serializer.validated_data['version'],  # a number, or None for "use latest version"
     )
     return Response({})