Esempio n. 1
0
def api_upload(request):
    if request.method == 'POST':
        picture = Picture()
        user = User.objects.get(email=request.POST['email'])
        picture.user = user
        form = UploadFileForm(request.POST, request.FILES, instance=picture)
        if form.is_valid():
            picture.picture = request.FILES['picture']
            if request.POST.has_key('gallery_id'):
                gallery = Gallery.objects.get(id=request.POST['gallery_id'], user=user)
                picture.gallery = gallery

            picture.picture.name = unidecode(picture.picture.name)
            picture.save()
            rotate_picture(picture)
            picture.update_thumb()

            if request.POST.has_key('description'):
                picture_description = PictureDescription(picture=picture)
                picture_description.text = request.POST['description']
                picture_description.save()  

            response = {'status':'OK'}
            response['data'] = serialize_picture(picture)
            return HttpResponse(json.dumps(response))

    return HttpResponse(content_200)
Esempio n. 2
0
def api_upload(request):
    if request.method == 'POST':
        picture = Picture()
        user = User.objects.get(email=request.POST['email'])
        picture.user = user
        form = UploadFileForm(request.POST, request.FILES, instance=picture)
        if form.is_valid():
            picture.picture = request.FILES['picture']
            if request.POST.has_key('gallery_id'):
                gallery = Gallery.objects.get(id=request.POST['gallery_id'],
                                              user=user)
                picture.gallery = gallery

            picture.picture.name = unidecode(picture.picture.name)
            picture.save()
            rotate_picture(picture)
            picture.update_thumb()

            if request.POST.has_key('description'):
                picture_description = PictureDescription(picture=picture)
                picture_description.text = request.POST['description']
                picture_description.save()

            response = {'status': 'OK'}
            response['data'] = serialize_picture(picture)
            return HttpResponse(json.dumps(response))

    return HttpResponse(content_200)
Esempio n. 3
0
def upload_picture(request):
    """Upload picture view.
    """
    if request.method == 'POST':
        picture = Picture()
        picture.user = request.user
        form = UploadFileForm(request.POST, request.FILES, instance=picture)
        response = {}

        if form.is_valid():
            picture.picture = request.FILES['picture']
            picture.picture.name = unidecode(picture.picture.name)
            picture.save()

            ### nasty error at 3:45 AM ;/
            try:
                rotate_picture(picture)
                picture.update_thumb()
                picture.save()
            except:
                import sys, traceback
                traceback.print_exc(file=sys.stdout)
                picture.delete()
                response[
                    'status'] = 'UPLOAD ERROR. PUT HELMET ON AND EVACUATE!!!'
                response = json.dumps(response)
                return HttpResponse(response)
            response['url'] = picture.picture_thumb.url
            response['id'] = picture.id
            response = json.dumps(response)
        else:
            response = "Failed to upload"
    else:
        if request.GET.has_key('gallery_id'):
            preffered_gallery = int(request.GET['gallery_id'])
        else:
            preffered_gallery = None
        galleries = Gallery.objects.filter(user=request.user)
        return render(request, "upload.html", {
            'galleries': galleries,
            'preffered_gallery': preffered_gallery
        })
    return HttpResponse(response)
Esempio n. 4
0
def upload_picture(request):
    """Upload picture view.
    """
    if request.method == "POST":
        picture = Picture()
        picture.user = request.user
        form = UploadFileForm(request.POST, request.FILES, instance=picture)
        response = {}

        if form.is_valid():
            picture.picture = request.FILES["picture"]
            picture.picture.name = unidecode(picture.picture.name)
            picture.save()

            ### nasty error at 3:45 AM ;/
            try:
                rotate_picture(picture)
                picture.update_thumb()
                picture.save()
            except:
                import sys, traceback

                traceback.print_exc(file=sys.stdout)
                picture.delete()
                response["status"] = "UPLOAD ERROR. PUT HELMET ON AND EVACUATE!!!"
                response = json.dumps(response)
                return HttpResponse(response)
            response["url"] = picture.picture_thumb.url
            response["id"] = picture.id
            response = json.dumps(response)
        else:
            response = "Failed to upload"
    else:
        if request.GET.has_key("gallery_id"):
            preffered_gallery = int(request.GET["gallery_id"])
        else:
            preffered_gallery = None
        galleries = Gallery.objects.filter(user=request.user)
        return render(request, "upload.html", {"galleries": galleries, "preffered_gallery": preffered_gallery})
    return HttpResponse(response)