Increment clicks
This commit is contained in:
parent
c1d7b70119
commit
add70a4727
1 changed files with 3 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
||||||
from urlparse import urlparse
|
from urlparse import urlparse
|
||||||
from django.shortcuts import render, redirect
|
from django.shortcuts import render, redirect
|
||||||
from django.http import Http404, HttpResponse
|
from django.http import Http404, HttpResponse
|
||||||
|
from django.db.models import F
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from .models import Link, LinkForm
|
from .models import Link, LinkForm
|
||||||
|
|
||||||
|
@ -18,10 +19,12 @@ def catchall(request, id):
|
||||||
try:
|
try:
|
||||||
link = Link.objects.get(id=id)
|
link = Link.objects.get(id=id)
|
||||||
parsed = urlparse(link.url)
|
parsed = urlparse(link.url)
|
||||||
|
Link.objects.filter(id=id).update(clicks=F('clicks')+1)
|
||||||
if parsed.scheme:
|
if parsed.scheme:
|
||||||
return redirect(link.url)
|
return redirect(link.url)
|
||||||
return redirect("http://" + link.url)
|
return redirect("http://" + link.url)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
return HttpResponse(e)
|
||||||
parsed = urlparse(id)
|
parsed = urlparse(id)
|
||||||
if parsed.netloc:
|
if parsed.netloc:
|
||||||
link = Link(url=id, ip=get_client_ip(request))
|
link = Link(url=id, ip=get_client_ip(request))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue