95f192eb856236171ad5c5a378a46c6a2a1640b5
[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_mail_uri(ticketid):
6         return config.RT_WEB_SERVER + "/Ticket/Display.html?id=" + str(ticketid)
7 def plc_node_uri(hostname):
8         return "https://" + config.PLC_WWW_HOSTNAME + "/db/nodes/index.php?pattern=" + str(hostname)
9 def plc_node_uri_id(node_id):
10         return "https://" + config.PLC_WWW_HOSTNAME + "/db/nodes/index.php?id=" + str(node_id)
11 def plc_site_uri(loginbase):
12         return "https://" + config.PLC_WWW_HOSTNAME + "/db/sites/index.php?pattern=" + str(loginbase)
13 def plc_site_uri_id(site_id):
14         return "https://" + config.PLC_WWW_HOSTNAME + "/db/sites/index.php?id=" + str(site_id)
15 def plc_pcu_uri_id(pcu_id):
16         return "https://" + config.PLC_WWW_HOSTNAME + "/db/sites/pcu.php?id=" + str(pcu_id)
17
18
19 def query_to_path(**kwargs):
20         args = []
21         tgpath = ""
22         tgparams = kwargs
23         if tgparams:
24                 for key, value in tgparams.iteritems():
25                         if value is None:
26                                 continue
27                         if isinstance(value, (list, tuple)):
28                                 pairs = [(key, v) for v in value]
29                         else:
30                                 pairs = [(key, value)]
31                         for k, v in pairs:
32                                 if v is None:
33                                         continue
34                                 if isinstance(v, unicode):
35                                         v = v.encode('utf8')
36                                 args.append((k, str(v)))
37         if args:
38                 query_string = urllib.urlencode(args, True)
39                 if '?' in tgpath:
40                         tgpath += '&' + query_string
41                 else:
42                         tgpath += '?' + query_string
43         return tgpath
44
45 def link(base, **kwargs):
46         if config.embedded:
47                 str = "?query=" + base + query_to_path(**kwargs)
48         else:
49                 str = tg.url(base, **kwargs)
50         #print "CREATED %s" % str
51         return str