new generic urlattr view stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 02 Dec 2009 14:38:17 +0100
branchstable
changeset 3971 7cfbc35dce7e
parent 3970 e4ad7663610b
child 3972 ec3d294034bf
new generic urlattr view
web/views/primary.py
--- a/web/views/primary.py	Wed Dec 02 14:37:19 2009 +0100
+++ b/web/views/primary.py	Wed Dec 02 14:38:17 2009 +0100
@@ -13,6 +13,7 @@
 from logilab.mtconverter import xml_escape
 
 from cubicweb import Unauthorized
+from cubicweb.selectors import match_kwargs
 from cubicweb.view import EntityView
 from cubicweb.schema import display_name
 from cubicweb.web import uicfg
@@ -255,6 +256,21 @@
                                                self.req._('see them all')))
             self.w(u'</div>')
 
+
+class URLAttributeView(EntityView):
+    """use this view for attributes whose value is an url and that you want
+    to display as clickable link
+    """
+    id = 'urlattr'
+    __select__ = EntityView.__select__ & match_kwargs('rtype')
+
+    def cell_call(self, row, col, rtype, **kwargs):
+        entity = self.rset.get_entity(row, col)
+        url = entity.printable_value(rtype)
+        if url:
+            self.w(u'<a href="%s">%s</a>' % (url, url))
+
+
 ## default primary ui configuration ###########################################
 
 _pvs = uicfg.primaryview_section