(request, code)
Get stats about short code.
Get stats about short code.
Get stats about short code .
def short_link_stats(request, code):
    """Get stats about short code."""
    pygmy_client = pygmy_client_object(settings, request)
    if request.method == 'GET':
        try:
            clickmeta = pygmy_client.link_stats(code)
            clickmeta['country_stats'] = sorted(
                clickmeta['country_stats'].items(),
                key=operator.itemgetter(1),
                reverse=True)

            country_stats = [(country, iso2full.get(country, "unknown"), hits)
                             for (country, hits) in clickmeta['country_stats']]
            clickmeta['country_stats'] = country_stats

            clickmeta['referrer'] = sorted(
                clickmeta['referrer'].items(),
                key=operator.itemgetter(1),
                reverse=True)

            context = dict(clickmeta=clickmeta)
        except (ObjectNotFound, LinkExpired) as e:
            return render(request, '404.html',
                          context=API_ERROR(e.args[0]), status=404)
        return render(request, 'pygmy/link_stats.html', context=context)
def short_link_stats ( request , code ) : pygmy_client = pygmy_client_object ( settings , request ) if request . method == 'GET' : try : clickmeta = pygmy_client . link_stats ( code ) clickmeta [ 'country_stats' ] = sorted ( clickmeta [ 'country_stats' ] . items ( ) , key = operator . itemgetter ( 1 ) , reverse = True ) country_stats = [ ( country , iso2full . get ( country , "unknown" ) , hits ) for ( country , hits ) in clickmeta [ 'country_stats' ] ] clickmeta [ 'country_stats' ] = country_stats clickmeta [ 'referrer' ] = sorted ( clickmeta [ 'referrer' ] . items ( ) , key = operator . itemgetter ( 1 ) , reverse = True ) context = dict ( clickmeta = clickmeta ) except ( ObjectNotFound , LinkExpired ) as e : return render ( request , '404.html' , context = API_ERROR ( e . args [ 0 ] ) , status = 404 ) return render ( request , 'pygmy/link_stats.html' , context = context )