Пример #1
0
def multiuploader(request):
    """
    Main Multiuploader module.
    Parses data from jQuery plugin and makes database changes.
    """
    if request.method == 'POST':
        log.info('received POST to main multiuploader view')
        if request.FILES == None:
            return HttpResponseBadRequest('Must have files attached!')

        #getting file data for farther manipulations
        file = request.FILES[u'files[]']
        wrapped_file = UploadedFile(file)
        filename = wrapped_file.name
        file_size = wrapped_file.file.size
        log.info('Got file: "%s"' % str(filename))

        #writing file manually into model
        #because we don't need form of any type.
        image = MultiuploaderImage()
        image.filename = str(filename)
        image.image = file
        image.key_data = image.key_generate
        image.save()
        log.info('File saving done')

        #getting thumbnail url using sorl-thumbnail
        im = get_thumbnail(image, "80x80", quality=50)
        thumb_url = im.url

        #settings imports
        try:
            file_delete_url = settings.MULTI_FILE_DELETE_URL + '/'
            file_url = settings.MULTI_IMAGE_URL + '/' + image.key_data + '/'
        except AttributeError:
            file_delete_url = 'multi_delete/'
            file_url = 'multi_image/' + image.key_data + '/'

        #generating json response array
        result = []
        result.append({
            "name": filename,
            "size": file_size,
            "url": file_url,
            "thumbnail_url": thumb_url,
            "delete_url": file_delete_url + str(image.pk) + '/',
            "delete_type": "POST",
        })
        response_data = simplejson.dumps(result)

        #checking for json data type
        #big thanks to Guy Shapiro
        if "application/json" in request.META['HTTP_ACCEPT_ENCODING']:
            mimetype = 'application/json'
        else:
            mimetype = 'text/plain'
        return HttpResponse(response_data, mimetype=mimetype)
    else:  #GET
        return HttpResponse('Only POST accepted')
def multiuploader(request):
    """
    Main Multiuploader module.
    Parses data from jQuery plugin and makes database changes.
    """
    if request.method == 'POST':
        log.info('received POST to main multiuploader view')
        if request.FILES == None:
            return HttpResponseBadRequest('Must have files attached!')

        #getting file data for farther manipulations
        file = request.FILES[u'files[]']
        wrapped_file = UploadedFile(file)
        filename = wrapped_file.name
        file_size = wrapped_file.file.size
        log.info ('Got file: "%s"' % str(filename))

        #writing file manually into model
        #because we don't need form of any type.
        image = MultiuploaderImage()
        image.filename=str(filename)
        image.image=file
        image.key_data = image.key_generate
        image.save()
        log.info('File saving done')

        #getting thumbnail url using sorl-thumbnail
        im = get_thumbnail(image, "80x80", quality=50)
        thumb_url = im.url

        #settings imports
        try:
            file_delete_url = settings.MULTI_FILE_DELETE_URL+'/'
            file_url = settings.MULTI_IMAGE_URL+'/'+image.key_data+'/'
        except AttributeError:
            file_delete_url = 'multi_delete/'
            file_url = 'multi_image/'+image.key_data+'/'

        #generating json response array
        result = []
        result.append({"name":filename, 
                       "size":file_size, 
                       "url":file_url, 
                       "thumbnail_url":thumb_url,
                       "delete_url":file_delete_url+str(image.pk)+'/', 
                       "delete_type":"POST",})
        response_data = simplejson.dumps(result)
        
        #checking for json data type
        #big thanks to Guy Shapiro
        if "application/json" in request.META['HTTP_ACCEPT_ENCODING']:
            mimetype = 'application/json'
        else:
            mimetype = 'text/plain'
        return HttpResponse(response_data, mimetype=mimetype)
    else: #GET
        return HttpResponse('Only POST accepted')
Пример #3
0
def multiuploader(request):
    """
    Main Multiuploader module.
    Parses data from jQuery plugin and makes database changes.
    """

    result = []

    if request.method == "POST":
        log.info("received POST to main multiuploader view")
        if request.FILES == None:
            return HttpResponseBadRequest("Must have files attached!")

        # getting file data for farther manipulations
        file = request.FILES[u"files[]"]
        wrapped_file = UploadedFile(file)
        filename = wrapped_file.name
        file_size = wrapped_file.file.size
        log.info('Got file: "%s"' % str(filename))
        log.info('Content type: "$s" % file.content_type')

        # writing file manually into model
        # because we don't need form of any type.
        image = MultiuploaderImage()
        image.filename = str(filename)
        image.image = file
        image.key_data = image.key_generate
        image.save()
        log.info("File saving done")

        # getting thumbnail url using sorl-thumbnail
        if "image" in file.content_type.lower():
            """
            #im = get_thumbnail(image, "80x80", quality=50)
            opt = dict(size=(80, 80), crop=True, bw=False, quality=80)
            im = get_thumbnailer(image).get_thumbnail(opt)
            thumb_url = im.url
            """
            thumb_url = ""
        else:
            thumb_url = ""

        # settings imports
        try:
            file_delete_url = settings.MULTI_FILE_DELETE_URL + "/"
            file_url = settings.MULTI_IMAGE_URL + "/" + image.key_data + "/"
        except AttributeError:
            file_delete_url = "multi_delete/"
            file_url = "multi_image/" + image.key_data + "/"

        # generating json response array

        result.append(
            {
                "name": filename,
                "size": file_size,
                "url": file_url,
                "thumbnail_url": thumb_url,
                "delete_url": file_delete_url + str(image.pk) + "/",
                "delete_type": "POST",
            }
        )
        response_data = simplejson.dumps(result)
        if "application/json" in request.META["HTTP_ACCEPT_ENCODING"]:
            mimetype = "application/json"
        else:
            mimetype = "text/plain"
        return HttpResponse(response_data, mimetype=mimetype)
    else:  # GET
        return HttpResponse("Only POST accepted")
Пример #4
0
def multiuploader(request):
    """
    Main Multiuploader module.
    Parses data from jQuery plugin and makes database changes.
    """
    if request.method == 'POST':
        log.info('received POST to main multiuploader view')

        if request.FILES == None:
            return HttpResponseBadRequest('Must have files attached!')

        description = request.POST.get('description', '')
        currentTime = request.POST.get('current-time', '')
        latitude = request.POST.get('latitude', '')
        longitude = request.POST.get('longitude', '')

        print 'Description is ' + description
        print 'Submit timestamp is ' + currentTime

        # Submit timestamp is 6/10/2013 @ 10:42:27

        submissionTime = datetime.datetime.strptime(currentTime, "%d/%m/%Y @ %H:%M:%S")

        try:
            folderItem = get_or_create_image_folder(currentTime, description, latitude, longitude, request,
                                                    submissionTime)
        except Exception, e:
            print str(e)
            folderItem = get_or_create_image_folder(currentTime, description, latitude, longitude, request,
                                                    submissionTime)


        #getting file data for further manipulations
        file = request.FILES[u'files[]']
        wrapped_file = UploadedFile(file)
        filename = wrapped_file.name
        file_size = wrapped_file.file.size
        log.info('Got file: "%s"' % str(filename))

        print 'File name is ' + str(filename)

        # TODO - pull out additional metadata for image.
        #writing file manually into model
        #because we don't need form of any type.
        image = MultiuploaderImage()
        image.filename = str(filename)
        image.image = file
        image.size = sizeof_fmt(file_size)
        image.key_data = image.key_generate
        image.save()
        log.info('File saving done')

        folderItem.files.add(image)

        #getting thumbnail url using sorl-thumbnail
        im = get_thumbnail(image, "80x80", quality=50)
        thumb_url = im.url

        #settings imports
        try:
            file_delete_url = settings.MULTI_FILE_DELETE_URL + '/'
            file_url = settings.MULTI_IMAGE_URL + '/' + image.key_data + '/'
        except AttributeError:
            file_delete_url = 'multi_delete/'
            file_url = 'multi_image/' + image.key_data + '/'

        #generating json response array
        result = []
        result.append({"folderitem": folderItem.uniqueIdentifier, "name": filename,
                       "size": file_size,
                       "url": file_url,
                       "thumbnail_url": thumb_url,
                       "delete_url": file_delete_url + str(image.pk) + '/',
                       "delete_type": "POST", })
        response_data = simplejson.dumps(result)

        #checking for json data type
        #big thanks to Guy Shapiro
        if "application/json" in request.META['HTTP_ACCEPT_ENCODING']:
            mimetype = 'application/json'
        else:
            mimetype = 'text/plain'
        return HttpResponse(response_data, mimetype=mimetype)
Пример #5
0
def multiuploader(request, patient_id=None):
    """
    Main Multiuploader module.
    Parses data from jQuery plugin and makes database changes.
    """
    if request.method == 'POST':
        log.info('received POST to main multiuploader view')
        if request.FILES == None:
            return HttpResponseBadRequest('Must have files attached!')

        #getting file data for farther manipulations
        file = request.FILES[u'files[]']

        wrapped_file = UploadedFile(file)
        filename = wrapped_file.name
        file_size = wrapped_file.file.size
        log.info ('Got file: "%s"' % str(filename))
        log.info('Content type: "$s" % file.content_type')

        #writing file manually into model
        #because we don't need form of any type.
        print request.POST
        if patient_id=='new':
            print wrapped_file.read()
            return HttpResponse(status=204)
        
        image = MultiuploaderImage()
        patient=Patient.objects.get(pk=patient_id)
        image.filename=str(filename)
        image.image=file
        image.key_data = image.key_generate
        patient.multiuploaderimage_set.add(image)
        log.info('File saving done')

        #getting thumbnail url using sorl-thumbnail
        if 'image' in file.content_type.lower():
            im = get_thumbnail(image, "80x80", quality=50)
            thumb_url = im.url
        else:
            thumb_url = ''

        #settings imports
        try:
            file_delete_url = settings.MULTI_FILE_DELETE_URL+'/'
            file_url = settings.MULTI_IMAGE_URL+'/'+image.key_data+'/'
        except AttributeError:
            file_delete_url = 'multi_delete/'
            file_url = 'multi_image/'+image.key_data+'/'

        """
        is actually: [{"name": "Screenshot from 2012-11-14 16:17:46.png", "url": "multi_image/95925526541943247735000327303075602114185579370918344597903504067450818566531/", "thumbnail_url": "/media/cache/f8/bd/f8bd83aadeba651ff9c040bb394ce117.jpg", "delete_type": "POST", "delete_url": "multi_delete/7/", "size": 38520}]
        should be:   {"files":[{"url":"http://jquerey-file-upload.appspot.com/AMIfv9734HSTDGd3tIybbnKVru--IjhjULKvNcIGUL2lvfqA93RNCAizDbvP-RQJNbh-N9m8UXsk-90jFFYSp8TlbZYhEcNN6Vb9HzQVQtdmF83H6sE_XkdnlI2V8lHX5V3Y4AamdX6VMbAt9sNWNx2BVGzhTfAYkRLYmRE1VzzWSe9C8c8Fu8g/Screenshot%20from%202012-11-14%2016%3A17%3A46.png","thumbnail_url":"http://lh5.ggpht.com/fcjVNT6qUGoMDtqqaNDNtU4mghy34qlzfj2GujikLgC7Nj5Bs4LUT_DWG_Q8OWujqvYHsKbeQ9pkvoAW4WiaubmqQxobIPyt=s80","name":"Screenshot from 2012-11-14 16:17:46.png","type":"image/png","size":38520,"delete_url":"http://jquery-file-upload.appspot.com/AMIfv9734HSTDGd3tIybbnKVru--IjhjULKvNcIGUL2lvfqA93RNCAizDbvP-RQJNbh-N9m8UXsk-90jFFYSp8TlbZYhEcNN6Vb9HzQVQtdmF83H6sE_XkdnlI2V8lHX5V3Y4AamdX6VMbAt9sNWNx2BVGzhTfAYkRLYmRE1VzzWSe9C8c8Fu8g/Screenshot%20from%202012-11-14%2016%3A17%3A46.png?delete=true","delete_type":"DELETE"}]}
        """

        #generating json response array
        result = {
            'files': [ {"name":filename, 
                       "size":file_size, 
                       "url":file_url, 
                       "thumbnail_url":thumb_url,
                       "delete_url":file_delete_url+str(image.pk)+'/', 
                       "delete_type":"POST",}
                    ]
        }
        response_data = simplejson.dumps(result)
        
        #checking for json data type
        #big thanks to Guy Shapiro
        if "application/json" in request.META['HTTP_ACCEPT_ENCODING']:
            mimetype = 'application/json'
        else:
            mimetype = 'text/plain'
        return HttpResponse(status=204)
            #response_data, mimetype=mimetype)
    else: #GETim
        return HttpResponse('Only POST accepted')
Пример #6
0
def multiuploader(request):
    """
    Main Multiuploader module.
    Parses data from jQuery plugin and makes database changes.
    """
    if request.method == 'POST':
        log.info('received POST to main multiuploader view')
        if request.FILES == None:
            return HttpResponseBadRequest('Must have files attached!')

        #getting file data for farther manipulations
        file = request.FILES[u'files[]']
        wrapped_file = UploadedFile(file)
        filename = wrapped_file.name
        file_size = wrapped_file.file.size
        log.info ('Got file: "%s"' % str(filename))
        log.info('Content type: "$s" % file.content_type')

        #writing file manually into model
        #because we don't need form of any type.
        image = MultiuploaderImage()
        image.filename=str(filename)
        image.image=file
        image.key_data = image.key_generate
        image.save()
        log.info('File saving done')

        #getting thumbnail url using sorl-thumbnail
        if 'image' in file.content_type.lower():
            im = get_thumbnail(image, "80x80", quality=50)
            thumb_url = im.url
        else:
            thumb_url = ''

        #settings imports
        try:
            file_delete_url = settings.MULTI_FILE_DELETE_URL+'/'
            file_url = settings.MULTI_IMAGE_URL+'/'+image.key_data+'/'
        except AttributeError:
            file_delete_url = 'multi_delete/'
            file_url = 'multi_image/'+image.key_data+'/'

        """
        is actually: [{"name": "Screenshot from 2012-11-14 16:17:46.png", "url": "multi_image/95925526541943247735000327303075602114185579370918344597903504067450818566531/", "thumbnail_url": "/media/cache/f8/bd/f8bd83aadeba651ff9c040bb394ce117.jpg", "delete_type": "POST", "delete_url": "multi_delete/7/", "size": 38520}]
        should be:   {"files":[{"url":"http://jquery-file-upload.appspot.com/AMIfv9734HSTDGd3tIybbnKVru--IjhjULKvNcIGUL2lvfqA93RNCAizDbvP-RQJNbh-N9m8UXsk-90jFFYSp8TlbZYhEcNN6Vb9HzQVQtdmF83H6sE_XkdnlI2V8lHX5V3Y4AamdX6VMbAt9sNWNx2BVGzhTfAYkRLYmRE1VzzWSe9C8c8Fu8g/Screenshot%20from%202012-11-14%2016%3A17%3A46.png","thumbnail_url":"http://lh5.ggpht.com/fcjVNT6qUGoMDtqqaNDNtU4mghy34qlzfj2GujikLgC7Nj5Bs4LUT_DWG_Q8OWujqvYHsKbeQ9pkvoAW4WiaubmqQxobIPyt=s80","name":"Screenshot from 2012-11-14 16:17:46.png","type":"image/png","size":38520,"delete_url":"http://jquery-file-upload.appspot.com/AMIfv9734HSTDGd3tIybbnKVru--IjhjULKvNcIGUL2lvfqA93RNCAizDbvP-RQJNbh-N9m8UXsk-90jFFYSp8TlbZYhEcNN6Vb9HzQVQtdmF83H6sE_XkdnlI2V8lHX5V3Y4AamdX6VMbAt9sNWNx2BVGzhTfAYkRLYmRE1VzzWSe9C8c8Fu8g/Screenshot%20from%202012-11-14%2016%3A17%3A46.png?delete=true","delete_type":"DELETE"}]}
        """

        #generating json response array
        result = {
            'files': [ {"name":filename, 
                       "size":file_size, 
                       "url":file_url, 
                       "thumbnail_url":thumb_url,
                       "delete_url":file_delete_url+str(image.pk)+'/', 
                       "delete_type":"POST",}
                    ]
        }
        response_data = simplejson.dumps(result)
        
        #checking for json data type
        #big thanks to Guy Shapiro
        if "application/json" in request.META['HTTP_ACCEPT_ENCODING']:
            mimetype = 'application/json'
        else:
            mimetype = 'text/plain'
        return HttpResponse(response_data, mimetype=mimetype)
    else: #GET
        return HttpResponse('Only POST accepted')