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, 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 list(self, request, group=None): if request.GET.get("group") is not None: group = request.GET.get("group") main_id = re.sub("/", "", group) main_id = re.sub("@", "%40", main_id) path = get_current_site(request).domain if "?" in main_id: page_number = main_id.split("?")[1] page_number = int( re.search('page=(.+?)$', page_number).group(1)) main_id = main_id.split("?")[0] else: page_number = 1 posts = FlickrModel.objects.filter(groupId=main_id, userId=request.user.id).values( 'title', 'img') paginator = Paginator(posts, 10) page = request.GET.get('page') posts = paginator.get_page(page_number) return render(request, "images_per_group.html", { 'images': posts, 'path': path, 'gid': main_id }) else: queryset = FlickrModel.objects.filter( userId=request.user.id).values('photoId') print(queryset) result_page = self.paginator.paginate_queryset(queryset, request) serializer = PhotoSerializer(result_page, many=True) return Response(serializer.data)
def get(self, request, *args, **kwargs): pk = self.get_object() photo = Photo.objects.all().filter(album=pk) album = Album.objects.all().filter(id=pk) serializer = PhotoSerializer(photo, many=True) return Response({ 'serializer': serializer.data, 'image': album, 'pk': pk })
def post(self, request, format=None): data = dict(request.data) print(data) val_hidden = data['hidden'] image_hashes = data['image_hashes'] out = [] for image_hash in image_hashes: photo = Photo.objects.get(image_hash=image_hash) photo.hidden = val_hidden photo.save() out.append(PhotoSerializer(photo).data) return Response({'status':True,'results':out})
def get(self, request, pk): photo = self.get_object(pk) serializer = PhotoSerializer(photo) return Response(serializer.data)
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)