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)
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)
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)
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