1a951bdb5253670f0f30af9f898b6c55f61fdfd6
[monitor.git] / web / MonitorWeb / monitorweb / templates / links.py
1 from monitor import config 
2 import turbogears as tg
3 import urllib
4
5 def plc_myops_uri():
6         return "http://" + config.MONITOR_HOSTNAME 
7 def plc_mail_uri(ticketid):
8         return config.RT_WEB_SERVER + "/Ticket/Display.html?id=" + str(ticketid)
9 def plc_node_uri(hostname):
10         return "https://" + config.PLC_WWW_HOSTNAME + "/db/nodes/index.php?pattern=" + str(hostname)
11 def plc_node_uri_id(node_id):
12         return "https://" + config.PLC_WWW_HOSTNAME + "/db/nodes/index.php?id=" + str(node_id)
13 def plc_site_uri(loginbase):
14         return "https://" + config.PLC_WWW_HOSTNAME + "/db/sites/index.php?pattern=" + str(loginbase)
15 def plc_site_uri_id(site_id):
16         return "https://" + config.PLC_WWW_HOSTNAME + "/db/sites/index.php?id=" + str(site_id)
17 def plc_pcu_uri_id(pcu_id):
18         return "https://" + config.PLC_WWW_HOSTNAME + "/db/sites/pcu.php?id=" + str(pcu_id)
19
20
21 def query_to_path(**kwargs):
22         args = []
23         tgpath = ""
24         tgparams = kwargs
25         if tgparams:
26                 for key, value in tgparams.iteritems():
27                         if value is None:
28                                 continue
29                         if isinstance(value, (list, tuple)):
30                                 pairs = [(key, v) for v in value]
31                         else:
32                                 pairs = [(key, value)]
33                         for k, v in pairs:
34                                 if v is None:
35                                         continue
36                                 if isinstance(v, unicode):
37                                         v = v.encode('utf8')
38                                 args.append((k, str(v)))
39         if args:
40                 query_string = urllib.urlencode(args, True)
41                 if '?' in tgpath:
42                         tgpath += '&' + query_string
43                 else:
44                         tgpath += '?' + query_string
45         return tgpath
46
47 def link(base, **kwargs):
48         if config.embedded:
49                 str = "?query=" + base + query_to_path(**kwargs)
50         else:
51                 str = tg.url(base, **kwargs)
52         #print "CREATED %s" % str
53         return str