예제 #1
0
 def post(self, request, *args, **kwargs):
     serializer = PhotoSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save()
         return redirect('image_gallery')
     else:
         return Response(serializer.errors, status=400)
예제 #2
0
 def put(self, request, pk):
     photo = self.get_object(pk)
     serializer = PhotoSerializer(instance=photo, data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
     return Response({'error': serializer.errors})
예제 #3
0
 def put(self, request, pk, format=None):
     photo = self.get_object(pk)
     serializer = PhotoSerializer(photo, data=request.DATA)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
예제 #4
0
 def post(self, request):
     serializer = PhotoSerializer(data=request.data,
                                  context={"request": request})
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
예제 #5
0
파일: views.py 프로젝트: nwvaras/hackathon
 def put(self, request, pk, format=None):
     photo = self.get_object(pk)
     serializer = PhotoSerializer(photo, data=request.DATA)
     if serializer.is_valid():
         instance = serializer.save()
         # print(subprocess.run(["python align_images.py ../api/media/photos/ ../api/media/aligned_photos/"]))
         return Response(serializer.data)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
예제 #6
0
파일: views.py 프로젝트: nwvaras/hackathon
 def post(self, request):
     serializer = PhotoSerializer(data=request.data,
                                  context={"request": request})
     if serializer.is_valid():
         image = serializer.save()
         print(image.image.name)
         filenames = align(image.image.name)
         print(filenames)
         for filename in filenames:
             image.latent_filename = filename
         image.save()
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
예제 #7
0
def photo_by_category(request, pk):
    try:
        category = Category.objects.get(id=pk)
    except Category.DoesNotExist as e:
        return Response({'error': str(e)})

    if request.method == 'GET':
        serializer = PhotoSerializer(category.photos.all(), many=True)
        return Response(serializer.data)
    elif request.method == 'POST':
        serializer = PhotoSerializer(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)
예제 #8
0
 def perform_create(self, serializer):
     """Method for handling the actual creation and upload"""
     serializer = PhotoSerializer(data=self.request.data, context={'request': self.request})
     if serializer.is_valid():
         serializer.save(created_by=self.request.user)
         return Response(serializer.data, status=status.HTTP_201_CREATED)