This commit is contained in:
Jonathan Cremin 2015-01-18 14:55:53 +00:00
parent df10c67999
commit b397561cce
5 changed files with 83 additions and 80 deletions

View file

@ -1,2 +1 @@
from django.contrib import admin

View file

@ -31,7 +31,11 @@ class Link(models.Model):
class LinkForm(ModelForm):
url = CharField(widget=TextInput(attrs={'class':'u-full-width', 'placeholder': 'Paste the link you want to shorten'}), label='')
url = CharField(widget=TextInput(attrs={
'class': 'u-full-width',
'placeholder': 'Paste the link you want to shorten'}),
label='')
class Meta:
model = Link
fields = ['url']
@ -39,9 +43,9 @@ class LinkForm(ModelForm):
def random_id(length):
rand = ''
for i in range(0,length):
rand += int_to_char(random.randint(0,61));
return rand;
for i in range(0, length):
rand += int_to_char(random.randint(0, 61))
return rand
def int_to_char(int):

View file

@ -25,7 +25,7 @@ def catchall(request, id):
parsed = urlparse(id)
if parsed.netloc:
link = Link(url=id, ip=get_client_ip(request))
link.save();
link.save()
request.session['short_url'] = "http://" + str(request.get_host()) + "/" + str(link.id)
return redirect('/')
raise Http404("Link does not exist")
@ -38,7 +38,7 @@ def home(request):
request.session['short_url'] = None
if 'url' in request.POST:
link = Link(url=request.POST['url'], ip=get_client_ip(request))
link.save();
link.save()
request.session['short_url'] = "http://" + request.get_host() + "/" + link.id
return redirect('/')
return render(request, 'index.html', context)