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
|
||||
|
||||
|
|
|
@ -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']
|
||||
|
@ -40,8 +44,8 @@ class LinkForm(ModelForm):
|
|||
def random_id(length):
|
||||
rand = ''
|
||||
for i in range(0, length):
|
||||
rand += int_to_char(random.randint(0,61));
|
||||
return rand;
|
||||
rand += int_to_char(random.randint(0, 61))
|
||||
return rand
|
||||
|
||||
|
||||
def int_to_char(int):
|
||||
|
|
|
@ -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)
|
Loading…
Add table
Add a link
Reference in a new issue