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