Пример #1
0
    def post(self, request, issuer_slug, **kwargs):
        """
        Define a new pathway to be owned by an issuer
        ---
        parameters:
            - name: name
              description: The name of the new Pathway
              required: true
              type: string
              paramType: form
            - name: description
              description: A short description of the new Pathway
              required: true
              type: string
              paramType: form
            - name: alignmentUrl
              description: An optional URL that points to an external standard
              required: false
              type: string
              paramType: form
        """
        if not self.get_object(issuer_slug, queryset=Issuer.objects.all()):
            return Response(status=status.HTTP_404_NOT_FOUND)

        serializer = PathwaySerializer(data=request.data, context={
            'request': request,
            'issuer_slug': issuer_slug,
            'include_structure': True
        })
        serializer.is_valid(raise_exception=True)
        serializer.save(created_by=request.user)
        pathway = serializer.data

        # logger.event(badgrlog.PathwayCreatedEvent(pathway))
        return Response(pathway, status=HTTP_201_CREATED)
Пример #2
0
    def put(self, request, issuer_slug, pathway_slug, **kwargs):
        """
        PUT updates to pathway details and group memberships
        ---
        serializer: PathwaySerializer
        parameters:
            - name: groups
              description: the list of groups subscribed to this pathway, as a list of ids or a list of LinkedDataReferences
              type: array
              items: {
                type: string
              }
              required: false
              paramType: form
        """
        issuer, pathway = self._get_issuer_and_pathway(issuer_slug,
                                                       pathway_slug)
        if issuer is None or pathway is None or pathway.issuer != issuer:
            return Response(status=status.HTTP_404_NOT_FOUND)

        serializer = PathwaySerializer(pathway, data=request.data)
        serializer.is_valid(raise_exception=True)
        serializer.save()

        return Response(serializer.data)
Пример #3
0
    def post(self, request, issuer_slug, **kwargs):
        """
        Define a new pathway to be owned by an issuer
        ---
        parameters:
            - name: name
              description: The name of the new Pathway
              required: true
              type: string
              paramType: form
            - name: description
              description: A short description of the new Pathway
              required: true
              type: string
              paramType: form
            - name: alignmentUrl
              description: An optional URL that points to an external standard
              required: false
              type: string
              paramType: form
        """
        serializer = PathwaySerializer(data=request.data,
                                       context={
                                           'request': request,
                                           'issuer_slug': issuer_slug,
                                           'include_structure': True
                                       })
        serializer.is_valid(raise_exception=True)
        serializer.save(created_by=request.user)
        pathway = serializer.data

        # logger.event(badgrlog.PathwayCreatedEvent(pathway))
        return Response(pathway, status=HTTP_201_CREATED)
Пример #4
0
    def put(self, request, issuer_slug, pathway_slug, **kwargs):
        """
        PUT updates to pathway details and group memberships
        ---
        serializer: PathwaySerializer
        parameters:
            - name: groups
              description: the list of groups subscribed to this pathway, as a list of ids or a list of LinkedDataReferences
              type: array
              items: {
                type: string
              }
              required: false
              paramType: form
        """
        issuer, pathway = self._get_issuer_and_pathway(issuer_slug, pathway_slug)
        if issuer is None or pathway is None or pathway.issuer != issuer:
            return Response(status=status.HTTP_404_NOT_FOUND)

        serializer = PathwaySerializer(pathway, data=request.data)
        serializer.is_valid(raise_exception=True)
        serializer.save()

        return Response(serializer.data)
Пример #5
0
    def get(self, request, issuer_slug, pathway_slug, **kwargs):
        """
        GET a flat list of Pathway Elements defined on a pathway
        ---
        """
        issuer, pathway = self._get_issuer_and_pathway(issuer_slug,
                                                       pathway_slug)
        if issuer is None or pathway is None:
            return Response(status=status.HTTP_404_NOT_FOUND)
        if pathway.issuer != issuer:
            return Response(status=status.HTTP_404_NOT_FOUND)

        serializer = PathwaySerializer(pathway,
                                       context={
                                           'request': request,
                                           'issuer_slug': issuer_slug,
                                           'pathway_slug': pathway_slug,
                                           'include_structure': True,
                                       })
        return Response(serializer.data)
Пример #6
0
    def create_pathway(self, creator):
        pathway_info = {
            'name': 'New Path',
            'description': 'A new path through learning'
        }
        serializer = PathwaySerializer(
            data=pathway_info,
            context={'issuer_slug': self.test_issuer.entity_id})
        serializer.is_valid(raise_exception=True)
        serializer.save(created_by=creator)
        pathway = serializer.instance

        self.assertEqual(pathway.name_hint, 'New Path')
        self.assertEqual(pathway.root_element.name, 'New Path')

        return pathway