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