コード例 #1
0
ファイル: views.py プロジェクト: AssemAbdirashova/izdeme
 def put(self, request, service_id):
     category = self.get_object(service_id)
     serializer = ServiceSerializer(instance=category, data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
     return Response({'error': serializer.errors})
コード例 #2
0
ファイル: views.py プロジェクト: terrestris/mrmap
    def create(self, request):
        """ Creates a new service

        Args:
            request (HttpRequest): The incoming request
        Returns:
             response (Response)
        """
        service_serializer = ServiceSerializer()
        params = request.POST.dict()
        response = APIResponse()
        pending_task = service_serializer.create(validated_data=params,
                                                 request=request)

        if isinstance(pending_task, Form):
            status = 400
            response.data["success"] = "false"
            response.data["message"] = pending_task.errors
        else:
            status = 202
            response.data["success"] = pending_task is not None
            response.data["pending_task_id"] = pending_task.id
            response.data[
                "status_url"] = HTTP_OR_SSL + HOST_NAME + "/api/pending-tasks/?task_id=" + pending_task.id

        response = Response(data=response.data, status=status)
        return response
コード例 #3
0
ファイル: views.py プロジェクト: AssemAbdirashova/izdeme
 def post(
     self,
     request,
 ):
     serializer = ServiceSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     return Response({'error': serializer.errors},
                     status=status.HTTP_500_INTERNAL_SERVER_ERROR)
コード例 #4
0
ファイル: views.py プロジェクト: nadyrbek97/promed
 def get(self, request, *args, **kwargs):
     result = {}
     department_id = kwargs.get('department_id')
     services = Service.objects.filter(department_id=department_id)
     serialized_services = ServiceSerializer(services, many=True)
     result['services'] = serialized_services.data
     return Response(data=result)
コード例 #5
0
    def create(self, request):
        """ Creates a new service

        Args:
            request (HttpRequest): The incoming request
        Returns:
             response (Response)
        """
        service_serializer = ServiceSerializer()
        params = request.POST.dict()
        pending_task = service_serializer.create(validated_data=params,
                                                 request=request)

        response = APIResponse()
        response.data["success"] = pending_task is not None
        response.data["pending_task_id"] = pending_task.id
        if pending_task:
            status = 200
        else:
            status = 500
        response = Response(data=response.data, status=status)
        return response
コード例 #6
0
    def retrieve(self, request, pk=None):
        try:
            tmp = Layer.objects.get(metadata__id=pk)
            if not tmp.metadata.is_active:
                return Response(status=423)
            serializer = LayerSerializer(tmp)
        except ObjectDoesNotExist:
            try:
                tmp = Service.objects.get(metadata__id=pk)
                if not tmp.metadata.is_active:
                    return Response(status=423)
                serializer = ServiceSerializer(tmp)
            except ObjectDoesNotExist:
                return Response(RESOURCE_NOT_FOUND, status=404)

        return Response(serializer.data)
コード例 #7
0
 def retrieve(self, request, pk=None):
     try:
         tmp = MrMapGroup.objects.get(id=pk)
         return Response(ServiceSerializer(tmp).data)
     except ObjectDoesNotExist:
         return Response(RESOURCE_NOT_FOUND, status=404)
コード例 #8
0
 def list(self, request):
     tmp = self.paginate_queryset(self.get_queryset())
     serializer = ServiceSerializer(tmp, many=True)
     return self.get_paginated_response(serializer.data)
コード例 #9
0
ファイル: views.py プロジェクト: AssemAbdirashova/izdeme
 def get(self, request):
     companies = Service.objects.all()
     serializer = ServiceSerializer(companies, many=True)
     return Response(serializer.data)
コード例 #10
0
ファイル: views.py プロジェクト: AssemAbdirashova/izdeme
 def get(self, request, service_id):
     company = self.get_object(service_id)
     serializer = ServiceSerializer(company)
     return Response(serializer.data)