[web ui] PrimaryView.render_attributes now uses a table stable
authorNicolas Chauvat <nicolas.chauvat@logilab.fr>
Sun, 08 Nov 2009 19:53:28 +0100
branchstable
changeset 3809 1b9b51ee543e
parent 3808 60e78e93a0e5
child 3811 3726e921f537
[web ui] PrimaryView.render_attributes now uses a table
view.py
web/data/cubicweb.css
web/views/primary.py
--- a/view.py	Sun Nov 08 19:37:44 2009 +0100
+++ b/view.py	Sun Nov 08 19:53:28 2009 +0100
@@ -293,22 +293,28 @@
         self.w('}\n-->\n</script>\n')
 
     def create_url(self, etype, **kwargs):
-        """ return the url of the entity creation form for a given entity type"""
-        return self.req.build_url('add/%s'%etype, **kwargs)
+        """return the url of the entity creation form for a given entity type"""
+        return self.req.build_url('add/%s' % etype, **kwargs)
 
-    def field(self, label, value, row=True, show_label=True, w=None, tr=True):
-        """ read-only field """
+    def field(self, label, value, row=True, show_label=True, w=None, tr=True, table=False):
+        """read-only field"""
         if w is None:
             w = self.w
-        if row:
-            w(u'<div class="row">')
+        if table:
+            w(u'<tr class="entityfield">')
+        else:
+            w(u'<div class="entityfield">')
         if show_label and label:
             if tr:
                 label = display_name(self.req, label)
-            w(u'<span class="label">%s</span>' % label)
-        w(u'<div class="field">%s</div>' % value)
-        if row:
-            w(u'</div>')
+            if table:
+                w(u'<th>%s</th>' % label)
+            else:
+                w(u'<span>%s</span>' % label)
+        if table:
+            w(u'<td>%s</td></tr>' % value)
+        else:
+            w(u'<span>%s</span></div>' % value)
 
 
 
--- a/web/data/cubicweb.css	Sun Nov 08 19:37:44 2009 +0100
+++ b/web/data/cubicweb.css	Sun Nov 08 19:53:28 2009 +0100
@@ -595,21 +595,15 @@
 
 /* basic entity view */
 
-div.row {
- clear: both;
- padding-bottom:0.4px
-}
-
-div.row span.label{
- padding-right:1em
+tr.entityfield th {
+  text-align: left;
+  padding-right: 0.5em;
 }
 
 div.field {
-  margin-left: 0.2em;
   display: inline;
 }
 
-
 /***************************************/
 /* messages                            */
 /***************************************/
--- a/web/views/primary.py	Sun Nov 08 19:37:44 2009 +0100
+++ b/web/views/primary.py	Sun Nov 08 19:53:28 2009 +0100
@@ -102,7 +102,11 @@
         return u''
 
     def render_entity_attributes(self, entity, siderelations=None):
-        for rschema, tschemas, role, dispctrl in self._section_def(entity, 'attributes'):
+        entity_attributes = self._section_def(entity, 'attributes')
+        if not entity_attributes:
+            return
+        self.w(u'<table>')
+        for rschema, tschemas, role, dispctrl in entity_attributes:
             vid = dispctrl.get('vid', 'reledit')
             if rschema.final or vid == 'reledit':
                 value = entity.view(vid, rtype=rschema.type, role=role)
@@ -114,7 +118,8 @@
                     value = None
             if self.skip_none and (value is None or value == ''):
                 continue
-            self._render_attribute(rschema, value)
+            self._render_attribute(rschema, value, role=role, table=True)
+        self.w(u'</table>')
 
     def render_entity_relations(self, entity, siderelations=None):
         for rschema, tschemas, role, dispctrl in self._section_def(entity, 'relations'):
@@ -191,13 +196,13 @@
                    initargs={'dispctrl': dispctrl})
         self.w(u'</div>')
 
-    def _render_attribute(self, rschema, value, role='subject'):
+    def _render_attribute(self, rschema, value, role='subject', table=False):
         if rschema.final:
             show_label = self.show_attr_label
         else:
             show_label = self.show_rel_label
         label = display_name(self.req, rschema.type, role)
-        self.field(label, value, show_label=show_label, tr=False)
+        self.field(label, value, show_label=show_label, tr=False, table=table)
 
 
 class RelatedView(EntityView):