1
0
mirror of https://github.com/r4sas/py-i2phosts synced 2025-01-22 12:34:17 +00:00

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

Drop associated separate views and render templates right in jumper()
This commit is contained in:
Hidden Z 2010-10-25 18:27:45 +00:00
parent 001ee4adc7
commit 8bdae565a5
2 changed files with 7 additions and 12 deletions

View File

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

View File

@ -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.')