forked from nileshk/url-shortener
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upgrade to django 1.3; add ability to have custom URLs; add tests
- Loading branch information
Showing
18 changed files
with
337 additions
and
419 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
#!/usr/bin/env python | ||
from django.core.management import execute_manager | ||
import imp | ||
try: | ||
import settings # Assumed to be in the same directory. | ||
imp.find_module('settings') # Assumed to be in the same directory. | ||
except ImportError: | ||
import sys | ||
sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__) | ||
sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n" % __file__) | ||
sys.exit(1) | ||
|
||
import settings | ||
|
||
if __name__ == "__main__": | ||
execute_manager(settings) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
from django.contrib import admin | ||
|
||
from urlweb.shortener.models import Link | ||
from shortener.models import Link | ||
|
||
class LinkAdmin(admin.ModelAdmin): | ||
model = Link | ||
extra = 3 | ||
pass | ||
|
||
admin.site.register(Link, LinkAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from django import forms | ||
|
||
from shortener.baseconv import base62 | ||
from shortener.models import Link | ||
|
||
class LinkSubmitForm(forms.Form): | ||
url = forms.URLField( | ||
label='URL to be shortened',) | ||
custom = forms.CharField( | ||
label='Custom shortened name', | ||
required=False,) | ||
|
||
def clean_custom(self): | ||
custom = self.cleaned_data['custom'] | ||
if not custom: | ||
return | ||
|
||
# test for characters in the requested custom alias that are not | ||
# available in our base62 enconding | ||
for char in custom: | ||
if char not in base62.digits: | ||
raise forms.ValidationError('Invalid character: "%s"' % char) | ||
# make sure this custom alias is not alrady taken | ||
id = base62.to_decimal(custom) | ||
try: | ||
if Link.objects.filter(id=id).exists(): | ||
raise forms.ValidationError('"%s" is already taken' % custom) | ||
except OverflowError: | ||
raise forms.ValidationError( | ||
"Your custom name is too long. Are you sure you wanted a " | ||
"shortening service? :)") | ||
return custom |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.