diff options
| author | Ben Firshman | 2014-09-21 04:10:58 +0200 |
|---|---|---|
| committer | Ben Firshman | 2014-09-21 04:10:58 +0200 |
| commit | 576af8b1060d8a8881ef54b3b8bd7cdb6ecb0a47 (patch) | |
| tree | e3f413536a1ebdb870509282e5a31168c905b043 | |
| parent | 61f4de67ed9cfdf09df4cee83d3c3c88775a6bf4 (diff) | |
| parent | 0158a679083f030980e5463b2e7af906423cf6b0 (diff) | |
| download | django-shorturls-576af8b1060d8a8881ef54b3b8bd7cdb6ecb0a47.tar.bz2 | |
Merge pull request #9 from bfirsh/django-1.7
Django 1.7
| -rw-r--r-- | .travis.yml | 17 | ||||
| -rw-r--r-- | src/shorturls/testsettings.py | 3 | ||||
| -rw-r--r-- | src/shorturls/urls.py | 4 | ||||
| -rw-r--r-- | src/shorturls/views.py | 10 |
4 files changed, 22 insertions, 12 deletions
diff --git a/.travis.yml b/.travis.yml index fa25cb8..f533d4f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,12 +4,17 @@ python: - "2.7" env: - - DJANGO="Django==1.2" - - DJANGO="Django==1.3" - - DJANGO="Django==1.4.15" + - DJANGO="Django>=1.4,<1.5" + - DJANGO="Django>=1.5,<1.6" + - DJANGO="Django>=1.6,<1.7" + - DJANGO="Django>=1.7,<1.8" -# command to install dependencies install: pip install $DJANGO --use-mirrors -# command to run tests -script: django-admin.py test --pythonpath=src/ --settings=shorturls.testsettings +script: cd src/shorturls; django-admin.py test --pythonpath=.. --settings=shorturls.testsettings + +matrix: + exclude: + - python: "2.6" + env: DJANGO="Django>=1.7,<1.8" + 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)) |
