clear label handling tls-sprint
authorsylvain.thenault@logilab.fr
Fri, 17 Apr 2009 09:37:29 +0200
branchtls-sprint
changeset 1389 ae58c2e7e1f7
parent 1388 6d5f0ccf31b8
child 1390 78bab2d35637
clear label handling
web/formwidgets.py
--- a/web/formwidgets.py	Fri Apr 17 09:32:57 2009 +0200
+++ b/web/formwidgets.py	Fri Apr 17 09:37:29 2009 +0200
@@ -346,7 +346,11 @@
 # buttons ######################################################################
 
 class Button(Input):
-    """<input type='button'>, base class for global form buttons"""
+    """<input type='button'>, base class for global form buttons
+
+    note label is a msgid which will be translated at form generation time, you
+    should not give an already translated string.
+    """
     type = 'button'
     def __init__(self, label=stdmsgs.BUTTON_OK, attrs=None,
                  setdomid=None, settabindex=None,
@@ -392,6 +396,9 @@
 class ImgButton(object):
     """<img> wrapped into a <a> tag with href triggering something (usually a
     javascript call)
+
+    note label is a msgid which will be translated at form generation time, you
+    should not give an already translated string.
     """
     def __init__(self, domid, href, label, imgressource):
         self.domid = domid
@@ -400,8 +407,13 @@
         self.label = label
         
     def render(self, form, field=None):
-        self.imgsrc = form.req.external_resource(self.imgressource)
-        return '<a id="%(domid)s" href="%(href)s"><img src="%(imgsrc)s" alt="%(label)s"/>%(label)s</a>' % self.__dict__
+        label = form.req._(self.label)
+        imgsrc = form.req.external_resource(self.imgressource)
+        return '<a id="%(domid)s" href="%(href)s">'\
+               '<img src="%(imgsrc)s" alt="%(label)s"/>%(label)s</a>' % {
+            'label': label, 'imgsrc': imgsrc,
+            'domid': self.domid, 'href': self.href}
+            
 
     
 # XXX EntityLinkComboBoxWidget, [Raw]DynamicComboBoxWidget