pep8
This commit is contained in:
parent
df10c67999
commit
b397561cce
5 changed files with 83 additions and 80 deletions
|
@ -1,2 +1 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,11 @@ class Link(models.Model):
|
||||||
|
|
||||||
|
|
||||||
class LinkForm(ModelForm):
|
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:
|
class Meta:
|
||||||
model = Link
|
model = Link
|
||||||
fields = ['url']
|
fields = ['url']
|
||||||
|
@ -39,9 +43,9 @@ class LinkForm(ModelForm):
|
||||||
|
|
||||||
def random_id(length):
|
def random_id(length):
|
||||||
rand = ''
|
rand = ''
|
||||||
for i in range(0,length):
|
for i in range(0, length):
|
||||||
rand += int_to_char(random.randint(0,61));
|
rand += int_to_char(random.randint(0, 61))
|
||||||
return rand;
|
return rand
|
||||||
|
|
||||||
|
|
||||||
def int_to_char(int):
|
def int_to_char(int):
|
||||||
|
|
|
@ -25,7 +25,7 @@ def catchall(request, id):
|
||||||
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))
|
||||||
link.save();
|
link.save()
|
||||||
request.session['short_url'] = "http://" + str(request.get_host()) + "/" + str(link.id)
|
request.session['short_url'] = "http://" + str(request.get_host()) + "/" + str(link.id)
|
||||||
return redirect('/')
|
return redirect('/')
|
||||||
raise Http404("Link does not exist")
|
raise Http404("Link does not exist")
|
||||||
|
@ -38,7 +38,7 @@ def home(request):
|
||||||
request.session['short_url'] = None
|
request.session['short_url'] = None
|
||||||
if 'url' in request.POST:
|
if 'url' in request.POST:
|
||||||
link = Link(url=request.POST['url'], ip=get_client_ip(request))
|
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
|
request.session['short_url'] = "http://" + request.get_host() + "/" + link.id
|
||||||
return redirect('/')
|
return redirect('/')
|
||||||
return render(request, 'index.html', context)
|
return render(request, 'index.html', context)
|
Loading…
Add table
Add a link
Reference in a new issue