Sort of works now

This commit is contained in:
Jonathan Cremin 2015-01-17 23:54:26 +00:00
parent 593f3e6d1c
commit 5972323cc1
15 changed files with 453 additions and 6 deletions

26
links/views.py Normal file
View file

@ -0,0 +1,26 @@
from django.shortcuts import render, redirect
from django.http import Http404
from .models import Link, LinkForm
from urlparse import urlparse
def catchall(request, id):
try:
link = Link.objects.get(id=id)
return redirect(link.url)
except:
parsed = urlparse(id)
if parsed.netloc:
link = Link(url=id)
link.save();
context = {'form': LinkForm}
context['short_url'] = "http://" + str(request.get_host()) + "/" + str(link.id)
return render(request, 'index.html', context)
raise Http404("Link does not exist")
def home(request):
context = {'form': LinkForm}
if 'link' in request.POST:
link = Link(link=request.POST['url'])
link.save();
context['short_url'] = "http://" + str(request.get_host()) + "/" + str(link.id)
return render(request, 'index.html', context)