From: Stephen Soltesz Date: Thu, 11 Dec 2008 21:16:13 +0000 (+0000) Subject: format uris from site, node, pcu details X-Git-Tag: Monitor-2.0-0~9 X-Git-Url: http://git.onelab.eu/?p=monitor.git;a=commitdiff_plain;h=571590440149a835fa35721f201f1265d690b15f format uris from site, node, pcu details --- diff --git a/web/MonitorWeb/monitorweb/templates/links.py b/web/MonitorWeb/monitorweb/templates/links.py new file mode 100644 index 0000000..0c9203d --- /dev/null +++ b/web/MonitorWeb/monitorweb/templates/links.py @@ -0,0 +1,46 @@ +from monitor import config +import urllib + +def plc_node_uri(hostname): + return "https://" + config.PLC_WWW_HOSTNAME + "/db/nodes/index.php?nodepattern=" + str(hostname) +def plc_site_uri(loginbase): + return "https://" + config.PLC_WWW_HOSTNAME + "/db/sites/index.php?site_pattern=" + str(loginbase) +def plc_site_uri_id(site_id): + return "https://" + config.PLC_WWW_HOSTNAME + "/db/sites/index.php?id=" + str(site_id) +def plc_pcu_uri_id(pcu_id): + return "https://" + config.PLC_WWW_HOSTNAME + "/db/sites/pcu.php?id=" + str(pcu_id) + + +def query_to_path(**kwargs): + args = [] + tgpath = "" + tgparams = kwargs + if tgparams: + for key, value in tgparams.iteritems(): + if value is None: + continue + if isinstance(value, (list, tuple)): + pairs = [(key, v) for v in value] + else: + pairs = [(key, value)] + for k, v in pairs: + if v is None: + continue + if isinstance(v, unicode): + v = v.encode('utf8') + args.append((k, str(v))) + if args: + query_string = urllib.urlencode(args, True) + if '?' in tgpath: + tgpath += '&' + query_string + else: + tgpath += '?' + query_string + return tgpath + +def link(base, ext=True, **kwargs): + if ext: + str = "?query=" + base + query_to_path(**kwargs) + else: + str = tg.url(base, **kwargs) + #print "CREATED %s" % str + return str