Prevent double submissions
This commit is contained in:
parent
099892e56f
commit
d52fea9afa
3 changed files with 8 additions and 9 deletions
|
@ -1,7 +1,8 @@
|
|||
from urlparse import urlparse
|
||||
from django.shortcuts import render, redirect
|
||||
from django.http import Http404
|
||||
from django.contrib import messages
|
||||
from .models import Link, LinkForm
|
||||
from urlparse import urlparse
|
||||
|
||||
def catchall(request, id):
|
||||
try:
|
||||
|
@ -13,14 +14,17 @@ def catchall(request, id):
|
|||
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)
|
||||
request.session['short_url'] = "http://" + str(request.get_host()) + "/" + str(link.id)
|
||||
return redirect('/')
|
||||
raise Http404("Link does not exist")
|
||||
|
||||
def home(request):
|
||||
context = {'form': LinkForm}
|
||||
if 'short_url' in request.session:
|
||||
context['short_url'] = request.session['short_url']
|
||||
if 'url' in request.POST:
|
||||
link = Link(url=request.POST['url'])
|
||||
link.save();
|
||||
context['short_url'] = "http://" + str(request.get_host()) + "/" + str(link.id)
|
||||
request.session['short_url'] = "http://" + request.get_host() + "/" + link.id
|
||||
return redirect('/')
|
||||
return render(request, 'index.html', context)
|
Loading…
Add table
Add a link
Reference in a new issue