network_tags.py 675 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 14 15 16 17 18 19 20
@register.simple_tag(name="display_portforward4")
def display_pf4(ports):
    return display_pf(ports, 'ipv4')


@register.simple_tag(name="display_portforward6")
def display_pf6(ports):
    return display_pf(ports, 'ipv6')


def display_pf(ports, proto):
    data = ports[proto]
21

22
    if ports['private'] in LINKABLE_PORTS.keys():
23
        href = "%s:%d" % (data['host'], data['port'])
24 25
        return '<a href="%s://%s">%s</a>' % (
            LINKABLE_PORTS.get(ports['private']), href, href)
26
    return "%s:%d" % (data['host'], data['port'])