Author: eallen
Date: 2009-04-14 11:44:07 -0400 (Tue, 14 Apr 2009)
New Revision: 3285
Modified:
mgmt/trunk/cumin/python/cumin/formats.py
mgmt/trunk/cumin/python/cumin/widgets.py
Log:
New optional argument to add attributes to a link <a foo="bar">
Modified: mgmt/trunk/cumin/python/cumin/formats.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/formats.py 2009-04-13 17:51:06 UTC (rev 3284)
+++ mgmt/trunk/cumin/python/cumin/formats.py 2009-04-14 15:44:07 UTC (rev 3285)
@@ -119,16 +119,17 @@
return string
-def fmt_link(href, content, class_="", id="",
link_title="", bm="", click=""):
+def fmt_link(href, content, class_="", id="",
link_title="", bm="", click="", attribs={}):
full_id = id and " id=\"%s\"" % id or ""
full_bm = bm and "#%s" % bm or ""
full_class = class_ and " class=\"%s\"" % class_ or ""
full_title = link_title and " title=\"%s\"" % link_title or
""
full_click = click and " onclick=\"%s\"" % click or ""
+ full_attribs = " ".join(("%s=\"%s\"" % (x, attribs[x])
for x in attribs)) or ""
- return "<a%s href=\"%s%s\"%s%s%s>%s</a>" % \
+ return "<a%s href=\"%s%s\"%s%s%s %s>%s</a>" % \
(full_id, href, full_bm, full_class,
- full_title, full_click, content)
+ full_title, full_click, full_attribs, content)
def fmt_olink(session, object, selected=False, name=None, pre=16, post=0):
if name is None:
Modified: mgmt/trunk/cumin/python/cumin/widgets.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/widgets.py 2009-04-13 17:51:06 UTC (rev 3284)
+++ mgmt/trunk/cumin/python/cumin/widgets.py 2009-04-14 15:44:07 UTC (rev 3285)
@@ -562,6 +562,9 @@
def get_click(self, state):
return ""
+
+ def get_attributes(self, state):
+ return dict()
def get_param_id(self):
""" needed because the SubmitSwitch class uses
@@ -578,8 +581,9 @@
class_ = self.get(session) == state and "selected"
bm = self.get_bookmark(state)
click = self.get_click(state)
+ attribs = self.get_attributes(state)
- return fmt_link(branch.marshal(), title, class_, link_title=hover, bm=bm,
click=click)
+ return fmt_link(branch.marshal(), title, class_, link_title=hover, bm=bm,
click=click, attribs=attribs)
class GroupSwitch(StateSwitch):
def __init__(self, app, name):