Ejemplo n.º 1
0
def addphotoform(request):
    
    albumname = request.matchdict['albumname']
    
    if request.method == "POST":
        filename = request.POST['jpg'].filename
        inputfile = request.POST['jpg'].file

        
        #put the photo in the store
        key = request.mystore.genkey(albumname, filename)
        request.mystore[key] = inputfile.read()
        
        
        #create the thumbnail
        inputfile.seek(0)
        size = 300, 300
        im = Image.open(inputfile)
        im.thumbnail(size, Image.ANTIALIAS)
        
        #create a file-like object for storing the thumbnail
        imagefile = BytesIO()
        def fileno():
            raise AttributeError
        imagefile.fileno = fileno #hack to make PIL and BytesIO work together...
                
        im.save(imagefile, 'JPEG')  #save thumbnail in jpeg format into imagefile
        
        imagefile.seek(0)
        
        thumbkey = request.mystore.genkey(albumname, filename, thumbnail = True)
        request.mystore[thumbkey] = imagefile.read()

        #store the new photo in the database
        album = DBSession.query(Album).filter(Album.name==albumname).one()
        
        photo = Photo()
        photo.album = album
        photo.filekey = key
        photo.thumbkey = thumbkey
        photo.filename = filename
        DBSession.add(photo)
                
        return HTTPFound(request.route_path("addphotoform",albumname=albumname))
        
    return {}
Ejemplo n.º 2
0
def import_s3(request):
    if request.method == "POST":
        if 'dirname' in request.POST:
            dirname = request.POST['dirname']
            albumname = request.POST['albumname']
             
            album = Album()
            album.name = albumname
            album.owner = request.user
            visible = False
            if 'visible' in request.POST:
                visible = True
            album.public = visible
            
            DBSession.add(album)
            
            listdir = request.mystore.list(dirname)
            for f in listdir:
                photo = Photo()
                filename = os.path.basename(f.name)
                
                photo.filename = filename
                photo.albumname = albumname
                photo.album = album
                photo.filekey = request.mystore.genkey(dirname, filename)
                log.debug('************* filekey: ' + photo.filekey)
                
                photo.thumbkey="/thumbnail/generate/"+ f.name
                log.debug("thumbnail path: %s"%photo.thumbkey)
                DBSession.add(photo)
            
            
    return Response("not imported yet")