1
0
mirror of https://github.com/r4sas/py-i2phosts synced 2025-01-25 05:54:27 +00:00
py-i2phosts/web/jump/views.py
Hidden Z 8bdae565a5 web/jump: use templates for "hostname unknown/error" errors
Drop associated separate views and render templates right in jumper()
2010-10-25 18:27:45 +00:00

36 lines
1014 B
Python

import re
from django.shortcuts import render_to_response
from django.core.exceptions import ValidationError
from web.postkey.models import i2phost
from web.lib.validation import validate_hostname
from web import settings
def jumper(request, host):
"""Actually do jumps."""
try:
hostname = validate_hostname(host)
except ValidationError, e:
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 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'/(.+)'
m = re.search(pattern, request.get_full_path())
if m:
params = m.group(1)
url += '/' + params
return render_to_response('jump.html', {
'title': settings.SITE_NAME,
'url': url,
})