Exemplo n.º 1
0
def user_species(request, username):
    try:
        user = User.objects.get(username = username)
    except User.DoesNotExist:
        return api_response(request, 404, {
            'username': username
        }, ok = False)
    species_seen = Species.objects.filter(
        sightings__created_by = user
    ).annotate(
        times_seen = Count('sightings')
    ).values('common_name', 'latin_name', 'slug', 'times_seen', 'pk')
    return api_response(request, 200, {
        'username': username,
        'species': [{
            'api_url': 'http://www.wildlifenearyou.com/api/species/%s/' % (
                species['slug']
            ),
            'common_name': species['common_name'],
            'latin_name': species['latin_name'],
            'code': 's' + converter.from_int(species['pk']),
            'short_url': 'http://wlny.eu/s'+converter.from_int(species['pk']),
            'times_seen': species['times_seen'],
        } for species in species_seen]
    })
Exemplo n.º 2
0
def user_trips(request, username):
    try:
        user = User.objects.get(username = username)
    except User.DoesNotExist:
        return api_response(request, 404, {
            'username': username
        }, ok = False)
    return api_response(request, 200, {
        'username': username,
        'trips': [{
            'api_url': 'http://www.wildlifenearyou.com/api/%s/trips/%s/' % (
                username, trip['pk']
            ),
            'url': 'http://www.wildlifenearyou.com/%s/trips/%s/' % (
                username, trip['pk']
            ),
            'name': trip['name'],
            'code': 't' + converter.from_int(trip['pk']),
            'short_url': 'http://wlny.eu/t' + converter.from_int(trip['pk']),
            'date': api_date(trip['start']),
            'date_accuracy': trip['start_accuracy'],    
            'created': api_datetime(trip['created_at']),
            'num_sightings': trip['num_sightings'],
            'place': {
                'known_as': trip['place__known_as'],
                'api_url': 'http://www.wildlifenearyou.com/api/%s/%s/' % (
                    trip['place__country__country_code'], trip['place__slug']
                ),
                'code': 'p' + converter.from_int(trip['place__pk']),
                'short_url': 'http://wlny.eu/p' + \
                    converter.from_int(trip['place__pk']),
                'url': 'http://www.wildlifenearyou.com/%s/%s/' % (
                     trip['place__country__country_code'], trip['place__slug']
                )
            },
        } for trip in trip_qs.filter(created_by = user)]
    })
Exemplo n.º 3
0
 def short_code(self):
     return 't%s' % converter.from_int(self.pk)
Exemplo n.º 4
0
 def short_url(self):
     return 'http://wlny.eu/i%s' % converter.from_int(self.pk)