Browse Source

web/jump: use templates for "hostname unknown/error" errors

Drop associated separate views and render templates right in jumper()
pull/1/head
Hidden Z 14 years ago
parent
commit
8bdae565a5
  1. 2
      web/jump/urls.py
  2. 17
      web/jump/views.py

2
web/jump/urls.py

@ -1,8 +1,6 @@ @@ -1,8 +1,6 @@
from django.conf.urls.defaults import *
urlpatterns = patterns('web.jump.views',
(r'^error/', 'error'),
(r'^unknown/', 'unknown'),
(r'^([^$/]+)', 'jumper'),
)

17
web/jump/views.py

@ -1,9 +1,7 @@ @@ -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): @@ -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): @@ -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.')

Loading…
Cancel
Save