FacetItem now takes req as first parameter of __init__, THIS IS BACKWARD INCOMPATIBLE
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Wed, 10 Dec 2008 10:37:54 +0100
changeset 203 60cd67acf7fd
parent 202 74f319aff847
child 204 4b01608c5397
FacetItem now takes req as first parameter of __init__, THIS IS BACKWARD INCOMPATIBLE
web/facet.py
web/htmlwidgets.py
--- a/web/facet.py	Wed Dec 10 10:36:38 2008 +0100
+++ b/web/facet.py	Wed Dec 10 10:37:54 2008 +0100
@@ -307,7 +307,7 @@
             if value is None:
                 wdg.append(FacetSeparator(label))
             else:
-                wdg.append(FacetItem(label, value, value in selected))
+                wdg.append(FacetItem(self.req, label, value, value in selected))
         return wdg
     
     def vocabulary(self):
@@ -532,10 +532,11 @@
 
 class FacetItem(HTMLWidget):
 
-    selected_img = "http://static.simile.mit.edu/exhibit/api-2.0/images/black-check.png"
-    unselected_img = "http://static.simile.mit.edu/exhibit/api-2.0/images/no-check-no-border.png"
+    selected_img = "black-check.png"
+    unselected_img = "no-check-no-border.png"
 
-    def __init__(self, label, value, selected=False):
+    def __init__(self, req, label, value, selected=False):
+        self.req = req
         self.label = label
         self.value = value
         self.selected = selected
@@ -543,10 +544,10 @@
     def _render(self):
         if self.selected:
             cssclass = ' facetValueSelected'
-            imgsrc = self.selected_img
+            imgsrc = self.req.datadir_url + self.selected_img
         else:
             cssclass = ''
-            imgsrc = self.unselected_img            
+            imgsrc = self.req.datadir_url + self.unselected_img            
         self.w(u'<div class="facetValue facetCheckBox%s" cubicweb:value="%s">\n'
                % (cssclass, html_escape(unicode(self.value))))
         self.w(u'<img src="%s" />&nbsp;' % imgsrc)
--- a/web/htmlwidgets.py	Wed Dec 10 10:36:38 2008 +0100
+++ b/web/htmlwidgets.py	Wed Dec 10 10:37:54 2008 +0100
@@ -13,6 +13,8 @@
 from cubicweb.common.utils import UStringIO
 from cubicweb.common.uilib import toggle_action
 
+# XXX HTMLWidgets should have access to req (for datadir / static urls,
+#     i18n strings, etc.)
 class HTMLWidget(object):
 
     def _initialize_stream(self, w=None):