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 sets(request):
    flickr_token = request.user.get_profile().flickr_token
    if not flickr_token:
        return flickr_redirect(request.path)
    client = Flickr(token = flickr_token)
    sets = client.photosets_getList()['photosets']['photoset']
    return render(request, 'flickr/sets.html', {
        'sets': sets,
        'show_photos': len(sets) <= 30,
    })
Ejemplo n.º 4
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.º 5
0
def update_flickr_tags_for_photo(photo):
    profile = photo.created_by.get_profile()
    if not profile.flickr_token:
        return
    client = Flickr(token = profile.flickr_token)
    client.cache = None
    
    try:
        info = client.photos_getInfo(photo_id = photo.flickr_id)
        existing_tags = [t['raw'] for t in info['photo']['tags']['tag']]
        
        machine_tags = ['wlny:photo=%s' % short(photo)]
        desired_tags = []
        for sighting in photo.sightings.all():
            if sighting.species:
                machine_tags.append(
                    'wlny:species=%s' % short(sighting.species)
                )
                if profile.flickr_tag_common_names:
                    desired_tags.append(sighting.species.common_name)
                if profile.flickr_tag_scientific_names and \
                        sighting.species.latin_name:
                    desired_tags.append(sighting.species.latin_name)
            elif sighting.species_inexact:
                desired_tags.append(sighting.species_inexact)
        
        regular_tags_to_add = [
            t for t in desired_tags if t not in existing_tags
        ]
        
        if photo.trip:
            machine_tags.append('wlny:trip=%s' % short(photo.trip))
            machine_tags.append('wlny:place=%s' % short(photo.trip.place))
        
        new_tags = u' '.join([
            u'"%s"' % t for t in (regular_tags_to_add + machine_tags)
        ])
        
        client.photos_addTags(photo_id = photo.flickr_id, tags = new_tags)
        
        regular_tags_added = u' '.join([
            u'"%s"' % t for t in regular_tags_to_add
        ])
        if regular_tags_added:
            photo.flickr_tags_applied.create(
                tags_added = regular_tags_added
            )
        photo.flickr_needs_tagging = False
        photo.save()
    except FlickrError, e:
        # We assume it's a token problem, so clear their token
        profile.flickr_token = ''
        profile.save()
Ejemplo n.º 6
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.º 7
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.º 8
0
def update_flickr_location_for_photo(photo):
    profile = photo.created_by.get_profile()
    if not profile.flickr_token:
        return
    client = Flickr(token = profile.flickr_token)
    client.cache = None
    
    try:
        info = client.photos_getInfo(photo_id = photo.flickr_id)
        if 'location' in info:
            photo.flickr_needs_geotagging = False
            photo.save()
            return
        
        client.photos_geo_setLocation(
            photo_id = photo.flickr_id,
            lat = photo.trip.place.latitude,
            lon = photo.trip.place.longitude,
            accuracy = 15 # one above 16, which is street-level
            # TODO: use zoom level for place map, once we start saving that
        )
        client.photos_addTags(
            photo_id = photo.flickr_id,
            tags = 'wlny:geotagged=1'
        )
        photo.flickr_tags_applied.create(
            latitude_added = photo.trip.place.latitude,
            longitude_added = photo.trip.place.longitude,
        )
        photo.flickr_needs_geotagging = False
        photo.save()
    except FlickrError, e:
        # We assume it's a token problem, so clear their token
        profile.flickr_token = ''
        profile.save()
Ejemplo n.º 9
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.º 10
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
    )