From 8bdae565a55577e39fe4345c3a6f1754be8502b2 Mon Sep 17 00:00:00 2001 From: Hidden Z Date: Mon, 25 Oct 2010 18:27:45 +0000 Subject: [PATCH] web/jump: use templates for "hostname unknown/error" errors Drop associated separate views and render templates right in jumper() --- web/jump/urls.py | 2 -- web/jump/views.py | 17 +++++++---------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/web/jump/urls.py b/web/jump/urls.py index b7546ab..b2c33e6 100644 --- a/web/jump/urls.py +++ b/web/jump/urls.py @@ -1,8 +1,6 @@ from django.conf.urls.defaults import * urlpatterns = patterns('web.jump.views', - (r'^error/', 'error'), - (r'^unknown/', 'unknown'), (r'^([^$/]+)', 'jumper'), ) diff --git a/web/jump/views.py b/web/jump/views.py index cd2f7f8..6ea06f4 100644 --- a/web/jump/views.py +++ b/web/jump/views.py @@ -1,9 +1,7 @@ import re -from django.shortcuts import redirect from django.shortcuts import render_to_response from django.core.exceptions import ValidationError -from django.http import HttpResponse from web.postkey.models import i2phost from web.lib.validation import validate_hostname @@ -14,11 +12,16 @@ def jumper(request, host): try: hostname = validate_hostname(host) except ValidationError, e: - return redirect('/jump/error/') + return render_to_response('jump-error.html', { + 'title': settings.SITE_NAME, + 'error': e, + }) try: key = i2phost.objects.get(name=hostname, activated=True).b64hash except i2phost.DoesNotExist: - return redirect('/jump/unknown/') + return render_to_response('jump-unknown.html', { + 'title': settings.SITE_NAME, + }) url = 'http://' + hostname + '/?i2paddresshelper=' + key # get params from requst string, e.g. from 'example.i2p/smth/1?a=b&c=d' get 'smth/1?a=b&c=d' pattern = host + r'/(.+)' @@ -30,9 +33,3 @@ def jumper(request, host): 'title': settings.SITE_NAME, 'url': url, }) - -def error(request): - return HttpResponse('You are trying to access an invalid hostname.') - -def unknown(request): - return HttpResponse('You are trying to access an unknown hostname.')