network_tags.py 545 Bytes
Newer Older
1 2 3 4 5
from django import template

register = template.Library()


6
LINKABLE_PORTS = {80: "http", 8080: "http", 443: "https", 21: "ftp"}
7 8 9 10 11 12 13


@register.simple_tag(name="display_portforward")
def display_pf(ports):
    is_ipv6 = "ipv6" in ports
    data = ports["ipv6" if is_ipv6 else "ipv4"]

14
    if ports['private'] in LINKABLE_PORTS.keys():
15
        href = "%s:%d" % (data['host'], data['port'])
16 17
        return '<a href="%s://%s">%s</a>' % (
            LINKABLE_PORTS.get(ports['private']), href, href)
18
    return "%s:%d" % (data['host'], data['port'])