Example #1
0
    def post(self, request, *args, **kwargs):
        user = request.user

        if user.is_authenticated():
            data = request.FILES["Filedata"]

            photo = Photo.objects.create(image=data, thumb=data, owner=user)
            # Resize the photo so it has a width of 620 pixels
            imaging.resizeWidth(photo.image.path)
            # Resize the thumbnail to 180x180 pixels
            imaging.fit(photo.thumb.path)

            return utils.jsonResponse(
                {"redirect": reverse("imahe_editor", args=[photo.id]), "message": "Photo uploaded", "status": "OK"}
            )
        else:
            return HttpResponseForbidden()
Example #2
0
    def post(self, request, *args, **kwargs):
        if not request.user.is_authenticated():
            return HttpResponseForbidden()

        id = request.POST.get("id")

        x1 = int(float(request.POST.get("x1")))
        y1 = int(float(request.POST.get("y1")))
        x2 = int(float(request.POST.get("x2")))
        y2 = int(float(request.POST.get("y2")))

        img = get_object_or_404(Image, id=id)

        imaging.crop(img.image.path, (x1, y1, x2, y2))
        imaging.crop(img.thumb.path, (x1, y1, x2, y2))

        img.stats = "C"
        img.save()

        return utils.jsonResponse({"status": "OK"})