Ejemplo n.º 1
0
def index(request):
    profile = request.user.get_profile()
    if not profile.flickr_prefs_set_at:
        return HttpResponseRedirect('/flickr/prefs/')
    flickr_token = profile.flickr_token
    if not flickr_token:
        return flickr_redirect(request.path)
    page = request.GET.get('page', '1')
    try:
        page = max(int(page), 1)
    except ValueError:
        page = 1
    client = Flickr(token = flickr_token)
    token_info = client.auth_checkToken()
    user_id = token_info['auth']['user']['nsid']
    result = client.photos_search(
        user_id = 'me', per_page = 24, page = page,
        extras = 'date_taken,url_m'
    )
    photos = result['photos']['photo']
    num_pages = result['photos']['pages']
    return photo_picker(
        request, photos, 'Your recent photos', {
            'paginated': num_pages > 1,
            'num_pages': num_pages,
            'page': page,
            'has_next': page < num_pages,
            'next_page': page + 1,
            'has_prev': page > 1,
            'prev_page': page - 1,
        }
    )
Ejemplo n.º 2
0
def groups(request):
    flickr_token = request.user.get_profile().flickr_token
    if not flickr_token:
        return flickr_redirect(request.path)
    client = Flickr(token = flickr_token)
    token_info = client.auth_checkToken()
    user_id = token_info['auth']['user']['nsid']
    return render(request, 'flickr/groups.html', {
        'groups': client.people_getPublicGroups(user_id = user_id),
    })
Ejemplo n.º 3
0
def places(request):
    flickr_token = request.user.get_profile().flickr_token
    if not flickr_token:
        return flickr_redirect(request.path)
    client = Flickr(token = flickr_token)
    token_info = client.auth_checkToken()
    user_id = token_info['auth']['user']['nsid']
    return render(request, 'flickr/places.html', {
        'places': client.places_placesForUser(
            place_type = 'locality',
        ),
    })
Ejemplo n.º 4
0
def group(request, group_nsid):
    flickr_token = request.user.get_profile().flickr_token
    if not flickr_token:
        return flickr_redirect(request.path)
    client = Flickr(token = flickr_token)
    token_info = client.auth_checkToken()
    group_info = client.groups_getInfo(group_id = group_nsid)
    user_id = token_info['auth']['user']['nsid']
    photos = client.groups_pools_getPhotos(
        group_id = group_nsid, user_id = user_id, extras = 'date_taken,url_m'
    )['photos']['photo']
    return photo_picker(
        request, photos, 'Your photos in %s' % group_info['group']['name']
    )
Ejemplo n.º 5
0
def place(request, woe_id):
    flickr_token = request.user.get_profile().flickr_token
    if not flickr_token:
        return flickr_redirect(request.path)
    client = Flickr(token = flickr_token)
    token_info = client.auth_checkToken()
    user_id = token_info['auth']['user']['nsid']
    place_info = client.places_getInfo(woe_id = woe_id)
    photos = client.photos_search(
        woe_id = woe_id, user_id = user_id, extras = 'date_taken,url_m'
    )['photos']['photo']
    return photo_picker(
        request, photos, 'Your photos in %s' % place_info['place']['name']
    )
Ejemplo n.º 6
0
def search(request):
    "Search your own photos"
    q = request.GET.get('q', '')
    if not q:
        return render(request, 'flickr/search.html')
    
    flickr_token = request.user.get_profile().flickr_token
    if not flickr_token:
        return flickr_redirect(request.path)
    client = Flickr(token = flickr_token)
    token_info = client.auth_checkToken()
    user_id = token_info['auth']['user']['nsid']
    photos = client.photos_search(
        user_id = user_id,
        text = q,
        extras = 'date_taken,url_m'
    )['photos']['photo']
    return photo_picker(request, photos, 'Search for "%s"' % q)
Ejemplo n.º 7
0
def single_set(request, set_id):
    flickr_token = request.user.get_profile().flickr_token
    if not flickr_token:
        return flickr_redirect(request.path)
    client = Flickr(token = flickr_token)
    token_info = client.auth_checkToken()
    user_id = token_info['auth']['user']['nsid']
    photos = client.photosets_getPhotos(
        photoset_id = set_id, media = 'photos', extras = 'date_taken,url_m'
    )['photoset']['photo']
    set_info = client.photosets_getInfo(
        photoset_id = set_id
    )['photoset']
    set_details = {
        'set_title': set_info['title'],
        'set_id': set_info['id'],
        'set_description': set_info['description'],
    }
    return photo_picker(
        request, photos, 'Your set: %s' % set_details['set_title'],
        set_details = set_details
    )