예제 #1
0
def info(request, base62_id):
    """
    View which shows information on a particular link
    """
    from urlparse import urlparse
    key = base62.to_decimal(base62_id)
    link = get_object_or_404(Link, pk = key)
    values = default_values(request)
    values['link'] = link
    values["stats"] = link.stat_set.all()
    net_locs = dict()
    for stat in values["stats"]:
        if stat.http_referer:
            o = urlparse(stat.http_referer)
            ref = str(o.netloc)
        else:
            ref = "No Referer"
        net_locs[ref] = net_locs.get(ref, 0) + 1
      
    refs = []
    counts = [] 
    domains = []
    for domain in net_locs:
        counts.append(net_locs[domain])
        refs.append(domain)
        domains.append(dict(domain=domain,count=net_locs[domain]))
    values["domains"] = domains 
    values["refs"] = refs
    values["counts"] = counts    
    return render_to_response(
        'shortener/link_info.html',
        values,
        context_instance=RequestContext(request))
예제 #2
0
def follow(request, base62_id):
    """ 
    View which gets the link for the given base62_id value
    and redirects to it.
    """
    key = base62.to_decimal(base62_id)
    link = get_object_or_404(Link, pk = key)
    link.usage_count += 1
    link.save()
    return HttpResponsePermanentRedirect(link.url)
예제 #3
0
def follow(request, base62_id):
    """ 
    View which gets the link for the given base62_id value
    and redirects to it.
    """
    key = base62.to_decimal(base62_id)
    link = get_object_or_404(Link, pk=key)
    link.usage_count += 1
    link.save()
    return HttpResponsePermanentRedirect(link.url)
예제 #4
0
def info(request, base62_id):
    """
    View which shows information on a particular link
    """
    key = base62.to_decimal(base62_id)
    link = get_object_or_404(Link, pk=key)
    values = default_values(request)
    values['link'] = link
    return render_to_response('shortener/link_info.html',
                              values,
                              context_instance=RequestContext(request))
예제 #5
0
def info(request, base62_id):
    """
    View which shows information on a particular link
    """
    key = base62.to_decimal(base62_id)
    link = get_object_or_404(Link, pk = key)
    values = default_values(request)
    values['link'] = link
    return render_to_response(
        'shortener/link_info.html',
        values,
        context_instance=RequestContext(request))
예제 #6
0
def follow(request, base62_id, stat_type = 1):
    """ 
    View which gets the link for the given base62_id value
    and redirects to it.
    """
    import datetime
    
    key = base62.to_decimal(base62_id)
    link = get_object_or_404(Link, pk = key)
    if request.user.is_anonymous():
        user = User.objects.get(username="******")
    else:
        user = request.user
        
    if str(stat_type) == "v":
        stat_type = 2 
    else:
        stat_type = 1
        
    stat = Stat(
        link = link,
        http_host       = request.META.get("HTTP_HOST",""),      
        http_referer    = request.META.get("HTTP_REFERER",""),   
        http_user_agent = request.META.get("HTTP_USER_AGENT",""),
        remote_addr     = request.META.get("REMOTE_ADDR",""),  
        remote_host     = request.META.get("REMOTE_HOST",""),
        stat_type       = stat_type
    )
    stat.user = user
    stat.save()
    if stat_type == 1:
        link.clicks = link.clicks + 1
    else:
        link.views = link.views + 1
    link.save()
    if stat_type == 2:
        return HttpResponse(content="", status=304)
        
    return HttpResponsePermanentRedirect(link.url)