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:
parent
001ee4adc7
commit
8bdae565a5
@ -1,8 +1,6 @@
|
|||||||
from django.conf.urls.defaults import *
|
from django.conf.urls.defaults import *
|
||||||
|
|
||||||
urlpatterns = patterns('web.jump.views',
|
urlpatterns = patterns('web.jump.views',
|
||||||
(r'^error/', 'error'),
|
|
||||||
(r'^unknown/', 'unknown'),
|
|
||||||
(r'^([^$/]+)', 'jumper'),
|
(r'^([^$/]+)', 'jumper'),
|
||||||
|
|
||||||
)
|
)
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
from django.shortcuts import redirect
|
|
||||||
from django.shortcuts import render_to_response
|
from django.shortcuts import render_to_response
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.http import HttpResponse
|
|
||||||
|
|
||||||
from web.postkey.models import i2phost
|
from web.postkey.models import i2phost
|
||||||
from web.lib.validation import validate_hostname
|
from web.lib.validation import validate_hostname
|
||||||
@ -14,11 +12,16 @@ def jumper(request, host):
|
|||||||
try:
|
try:
|
||||||
hostname = validate_hostname(host)
|
hostname = validate_hostname(host)
|
||||||
except ValidationError, e:
|
except ValidationError, e:
|
||||||
return redirect('/jump/error/')
|
return render_to_response('jump-error.html', {
|
||||||
|
'title': settings.SITE_NAME,
|
||||||
|
'error': e,
|
||||||
|
})
|
||||||
try:
|
try:
|
||||||
key = i2phost.objects.get(name=hostname, activated=True).b64hash
|
key = i2phost.objects.get(name=hostname, activated=True).b64hash
|
||||||
except i2phost.DoesNotExist:
|
except i2phost.DoesNotExist:
|
||||||
return redirect('/jump/unknown/')
|
return render_to_response('jump-unknown.html', {
|
||||||
|
'title': settings.SITE_NAME,
|
||||||
|
})
|
||||||
url = 'http://' + hostname + '/?i2paddresshelper=' + key
|
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'
|
# 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'/(.+)'
|
pattern = host + r'/(.+)'
|
||||||
@ -30,9 +33,3 @@ def jumper(request, host):
|
|||||||
'title': settings.SITE_NAME,
|
'title': settings.SITE_NAME,
|
||||||
'url': url,
|
'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…
x
Reference in New Issue
Block a user