示例#1
0
def list_albums():
    user = users.get_current_user()
    if 'refresh' in request.args:
        AlbumList.delete_for_user(user)
        return redirect(url_for('list_albums'))
    album_list = AlbumList.get_for_user(user)
    
    album_mappings = dict() # key=albumid, value=mapping
    for mapping in AlbumEmailMapping.all().filter('owner =', user):
        # this is a mapping.  
        album_id = mapping.album['gphoto$id']['$t']
        logging.info('adding album with id %s to map.' % album_id)
        album_mappings[album_id] = mapping
    return render_template('albums.html', user=user, album_list=album_list, 
                           album_mappings=album_mappings)
示例#2
0
def select_album(album_id):
    user = users.get_current_user()
    album_list = AlbumList.get_for_user(user)
    the_album = None
    for album in album_list:
        if album['gphoto$id']['$t'] == album_id:
            the_album = album
            break
                    
    if not album:
        return 'album not found'
        
    email_address = md5.new(os.urandom(25)).hexdigest()
    # if it's taken, generate new
    while AlbumEmailMapping.all().filter('email_address = ', email_address) \
                           .count() > 0:
        email_address = md5.new(os.urandom(25)).hexdigest()
        
    mapping = AlbumEmailMapping(
        owner=user,
        email_address=email_address,
        album=album)
        
    mapping.put()
    return redirect(url_for('list_albums'))