aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/shorturls/testsettings.py3
-rw-r--r--src/shorturls/urls.py4
-rw-r--r--src/shorturls/views.py10
3 files changed, 11 insertions, 6 deletions
diff --git a/src/shorturls/testsettings.py b/src/shorturls/testsettings.py
index 408ea8b..1f66f84 100644
--- a/src/shorturls/testsettings.py
+++ b/src/shorturls/testsettings.py
@@ -1,6 +1,7 @@
import os
DEBUG = TEMPLATE_DEBUG = True
+SECRET_KEY = '123'
# For Pre-Django 1.3
DATABASE_ENGINE = 'sqlite3'
@@ -15,4 +16,4 @@ DATABASES = {
INSTALLED_APPS = ['shorturls']
ROOT_URLCONF = ['shorturls.urls']
-TEMPLATE_DIRS = os.path.join(os.path.dirname(__file__), 'tests', 'templates')
+TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), 'tests', 'templates'),)
diff --git a/src/shorturls/urls.py b/src/shorturls/urls.py
index b81e24d..bc28d6b 100644
--- a/src/shorturls/urls.py
+++ b/src/shorturls/urls.py
@@ -1,9 +1,9 @@
from django.conf import settings
-from django.conf.urls.defaults import *
+from django.conf.urls import *
urlpatterns = patterns('',
url(
regex = '^(?P<prefix>%s)(?P<tiny>\w+)$' % '|'.join(settings.SHORTEN_MODELS.keys()),
view = 'shorturls.views.redirect',
),
-) \ No newline at end of file
+)
diff --git a/src/shorturls/views.py b/src/shorturls/views.py
index 1737472..d811fde 100644
--- a/src/shorturls/views.py
+++ b/src/shorturls/views.py
@@ -16,8 +16,12 @@ def redirect(request, prefix, tiny):
# any of that stuff goes wrong.
try:
app_label, model_name = settings.SHORTEN_MODELS[prefix].split('.')
- model = models.get_model(app_label, model_name)
- if not model: raise ValueError
+ try:
+ model = models.get_model(app_label, model_name)
+ except LookupError:
+ raise Http404('Bad model.')
+ if not model:
+ raise ValueError
id = base62.to_decimal(tiny)
except (AttributeError, ValueError, KeyError):
raise Http404('Bad prefix, model, SHORTEN_MODELS, or encoded ID.')
@@ -50,4 +54,4 @@ def redirect(request, prefix, tiny):
else:
base = 'http://%s/' % RequestSite(request).domain
- return HttpResponsePermanentRedirect(urlparse.urljoin(base, url)) \ No newline at end of file
+ return HttpResponsePermanentRedirect(urlparse.urljoin(base, url))