示例#1
0
def multiupload_photo_ajax(request):
    """
    View for Uploading many photos with AJAX plugin.
    made from api on:
    https://github.com/blueimp/jQuery-File-Upload
    """

    if request.method == 'POST':
        log.info ('Post received')
        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: "'+str(filename)+'"')
        #writing file directly into model
        #because we don't need form of any type.
        image = Image()
        image.user=request.user
        image.title=str(filename)
        image.image=file
        image.save()
        log.info('Uploading done')
        
        """
        generating Json response for plugin purposes
        """
        file_delete_url = 'multi_delete/'
        file_url = image.get_absolute_url()
        file_fs_name = image.image.name
        #getting thumbnail url
        im = get_thumbnail(image, "80x80", quality=50)
        thumb_url = im.url
        #generating json response
        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 render_to_response('multiuploader/multiuploader_main.html', {'static_url':settings.MEDIA_URL,
                                                                            'open_tv':u'{{',
                                                                            'close_tv':u'}}'}, 
                                                                context_instance=RequestContext(request))
示例#2
0
def flickr_synchronize3(request):
    
    flickr_photos = Photo.objects.all()
    list = '' #list to log photos to      feature request in future versions!
    for photo in flickr_photos:
        log.info('Adding photo "'+str(photo.flickr_id)+'" to main Photoblog database table')
        
        photo_url = photo.get_large_url()
        log.info('Trying to download photo from url: "'+str(photo_url)+'"')
        name = urlparse(photo_url).path.split('/')[-1]
        content = ContentFile(urllib2.urlopen(photo_url).read())
        image=Image()
        image.image.save(name=name, content=content, save=True)
        image.title=photo.title
        image.user=request.user
        image.save()
        photo.delete()
        list = list+str(photo.flickr_id)+','
    return HttpResponse('Flickr sync completed! <a href="/">Go home<a>')
示例#3
0
文件: views.py 项目: TonyL888/gphblog
def flickr_synchronize3(request):

    flickr_photos = Photo.objects.all()
    list = ''  #list to log photos to      feature request in future versions!
    for photo in flickr_photos:
        log.info('Adding photo "' + str(photo.flickr_id) +
                 '" to main Photoblog database table')

        photo_url = photo.get_large_url()
        log.info('Trying to download photo from url: "' + str(photo_url) + '"')
        name = urlparse(photo_url).path.split('/')[-1]
        content = ContentFile(urllib2.urlopen(photo_url).read())
        image = Image()
        image.image.save(name=name, content=content, save=True)
        image.title = photo.title
        image.user = request.user
        image.save()
        photo.delete()
        list = list + str(photo.flickr_id) + ','
    return HttpResponse('Flickr sync completed! <a href="/">Go home<a>')
示例#4
0
文件: views.py 项目: rjor2/legophoto
def upload_image(request):
    if request.method == 'POST':
        logger.debug('post')
        form = UploadImageForm(request.POST, request.FILES)
        if form.is_valid():
            logger.debug('valid')

            image = Image(docfile=request.FILES['file'])
            image.save()
            # return HttpResponseRedirect('/success/url/')
            render_to_response('photo/upload.html', {'form': form, 'msg': "File Uploaded"})

        else:
            logger.debug('invalid')

    else:
        logger.debug('get')
        form = UploadImageForm()
    return render_to_response(
        'photo/upload.html',
        {'form': form, 'msg': "File Uploaded"},
        context_instance=RequestContext(request))
示例#5
0
def multiupload_photo_ajax(request):
    """
    View for Uploading many photos with AJAX plugin.
    made from api on:
    https://github.com/blueimp/jQuery-File-Upload
    """

    if request.method == "POST":
        log.info("Post received")
        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: "' + str(filename) + '"')
        # writing file directly into model
        # because we don't need form of any type.
        image = Image()
        image.user = request.user
        image.title = str(filename)
        image.image = file
        image.save()
        log.info("Uploading done")

        """
        generating Json response for plugin purposes
        """
        file_delete_url = "multi_delete/"
        file_url = image.get_absolute_url()
        file_fs_name = image.image.name
        # getting thumbnail url
        im = get_thumbnail(image, "80x80", quality=50)
        thumb_url = im.url
        # generating json response
        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)

        # adding photo to default album to be displayed in albums automaticly
        try:
            default_album = get_object_or_404(Album, title="User's Posted")
            image.albums.add(default_album)
        except:
            log.info("Error adding photo pk=" + str(image.pk) + " to default album.")
            pass

        # 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 render_to_response(
            "multiuploader/multiuploader_main.html",
            {"static_url": settings.MEDIA_URL, "open_tv": u"{{", "close_tv": u"}}"},
            context_instance=RequestContext(request),
        )
示例#6
0
文件: views.py 项目: TonyL888/gphblog
def multiupload_photo_ajax(request):
    """
    View for Uploading many photos with AJAX plugin.
    made from api on:
    https://github.com/blueimp/jQuery-File-Upload
    """

    if request.method == 'POST':
        log.info('Post received')
        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: "' + str(filename) + '"')
        #writing file directly into model
        #because we don't need form of any type.
        image = Image()
        image.user = request.user
        image.title = str(filename)
        image.image = file
        image.save()
        log.info('Uploading done')
        """
        generating Json response for plugin purposes
        """
        file_delete_url = 'multi_delete/'
        file_url = image.get_absolute_url()
        file_fs_name = image.image.name
        #getting thumbnail url
        im = get_thumbnail(image, "80x80", quality=50)
        thumb_url = im.url
        #generating json response
        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)

        #adding photo to default album to be displayed in albums automaticly
        try:
            default_album = get_object_or_404(Album, title="User's Posted")
            image.albums.add(default_album)
        except:
            log.info('Error adding photo pk=' + str(image.pk) +
                     ' to default album.')
            pass

        #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 render_to_response('multiuploader/multiuploader_main.html', {
            'static_url': settings.MEDIA_URL,
            'open_tv': u'{{',
            'close_tv': u'}}'
        },
                                  context_instance=RequestContext(request))