From 0158a679083f030980e5463b2e7af906423cf6b0 Mon Sep 17 00:00:00 2001 From: Ben Firshman Date: Sat, 20 Sep 2014 18:43:26 -0700 Subject: Add support for Django 1.7, remove 1.2 and 1.3 --- src/shorturls/testsettings.py | 3 ++- src/shorturls/urls.py | 4 ++-- src/shorturls/views.py | 10 +++++++--- 3 files changed, 11 insertions(+), 6 deletions(-) (limited to 'src') 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%s)(?P\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)) -- cgit v1.2.3