web/views/baseviews.py
branchtls-sprint
changeset 1477 b056a49c16dc
parent 1453 a9841184be7c
parent 1457 89567fcc6b15
child 1491 742aff97dbf7
--- a/web/views/baseviews.py	Fri Apr 24 16:48:38 2009 +0200
+++ b/web/views/baseviews.py	Fri Apr 24 17:04:14 2009 +0200
@@ -138,6 +138,9 @@
         self.render_entity_metadata(entity)
         # entity's attributes and relations, excluding meta data
         # if the entity isn't meta itself
+        boxes = self._preinit_side_related(entity, siderelations)
+        if boxes:
+            self.w(u'<table width="100%"><tr><td width="75%">')
         self.w(u'<div>')
         self.w(u'<div class="mainInfo">')
         self.render_entity_attributes(entity, siderelations)
@@ -146,13 +149,16 @@
         if self.main_related_section:
             self.render_entity_relations(entity, siderelations)
         self.w(u'</div>')
-        # side boxes
-        self.w(u'<div class="primaryRight">')
-        self.render_side_related(entity, siderelations)
-        self.w(u'</div>')
-        self.w(u'<div class="clear"></div>')
+        if boxes:
+            self.w(u'</td><td>')
+            # side boxes
+            self.w(u'<div class="primaryRight">')
+            self.render_side_related(entity, siderelations)
+            self.w(u'</div>')
+            self.w(u'</td></tr></table>')
         self.content_navigation_components('navcontentbottom')
 
+
     def content_navigation_components(self, context):
         self.w(u'<div class="%s">' % context)
         for comp in self.vreg.possible_vobjects('contentnavigation',
@@ -217,35 +223,46 @@
                 continue
             self._render_related_entities(entity, rschema, value)
 
-    def render_entity_relations(self, entity, siderelations):
+    def _preinit_side_related(self, entity, siderelations):
+        self._sideboxes = None
+        self._related_entities = []
         if hasattr(self, 'get_side_boxes_defs'):
-            return
-        eschema = entity.e_schema
-        maxrelated = self.req.property_value('navigation.related-limit')
-        for rschema, targetschemas, x in self.iter_relations(entity):
-            try:
-                related = entity.related(rschema.type, x, limit=maxrelated+1)
-            except Unauthorized:
-                continue
-            if not related:
-                continue
-            if self.is_side_related(rschema, eschema):
-                siderelations.append((rschema, related, x))
-                continue
-            self._render_related_entities(entity, rschema, related, x)
+            self._sideboxes = [(label, rset) for label, rset in self.get_side_boxes_defs(entity)
+                               if rset]
+        else:
+            eschema = entity.e_schema
+            maxrelated = self.req.property_value('navigation.related-limit')
+            for rschema, targetschemas, x in self.iter_relations(entity):
+                try:
+                    related = entity.related(rschema.type, x, limit=maxrelated+1)
+                except Unauthorized:
+                    continue
+                if not related:
+                    continue
+                if self.is_side_related(rschema, eschema):
+                    siderelations.append((rschema, related, x))
+                    continue
+                self._related_entities.append((rschema, related, x))
+        self._boxes_in_context = list(self.vreg.possible_vobjects('boxes', self.req, self.rset,
+                                                 row=self.row, view=self,
+                                                 context='incontext'))
+        return self._sideboxes or self._boxes_in_context or self._related_entities or siderelations
+
+    def render_entity_relations(self, entity, siderelations):
+        if self._related_entities:
+            for rschema, related, x in self._related_entities:
+                self._render_related_entities(entity, rschema, related, x)
+
 
     def render_side_related(self, entity, siderelations):
         """display side related relations:
         non-meta in a first step, meta in a second step
         """
-        if hasattr(self, 'get_side_boxes_defs'):
-            sideboxes = [(label, rset) for label, rset in self.get_side_boxes_defs(entity)
-                         if rset]
-            if sideboxes:
-                for label, rset in sideboxes:
-                    self.w(u'<div class="sideRelated">')
-                    self.wview('sidebox', rset, title=label)
-                    self.w(u'</div>')
+        if self._sideboxes:
+            for label, rset in self._sideboxes:
+                self.w(u'<div class="sideRelated">')
+                self.wview('sidebox', rset, title=label)
+                self.w(u'</div>')
         elif siderelations:
             self.w(u'<div class="sideRelated">')
             for relatedinfos in siderelations:
@@ -253,11 +270,9 @@
                 #    continue
                 self._render_related_entities(entity, *relatedinfos)
             self.w(u'</div>')
-        boxes = list(self.vreg.possible_vobjects('boxes', self.req, self.rset,
-                                                 row=self.row, view=self,
-                                                 context='incontext'))
-        if boxes:
-            for box in boxes:
+
+        if self._boxes_in_context:
+            for box in self._boxes_in_context:
                 try:
                     box.dispatch(w=self.w, row=self.row)
                 except NotImplementedError:
@@ -365,7 +380,7 @@
             self.w(u'#%s - ' % entity.eid)
         if entity.modification_date != entity.creation_date:
             self.w(u'<span>%s</span> ' % _('latest update on'))
-            self.w(u'<span class="value">%s</span>,&nbsp;'
+            self.w(u'<span class="value">%s</span>, ;'
                    % self.format_date(entity.modification_date))
         # entities from external source may not have a creation date (eg ldap)
         if entity.creation_date:
@@ -373,7 +388,7 @@
             self.w(u'<span class="value">%s</span>'
                    % self.format_date(entity.creation_date))
         if entity.creator:
-            self.w(u'&nbsp;<span>%s</span> ' % _('by'))
+            self.w(u' <span>%s</span> ' % _('by'))
             self.w(u'<span class="value">%s</span>' % entity.creator.name())
         self.w(u'</div>')
 
@@ -519,7 +534,6 @@
     def cell_call(self, row, col):
         self.wview('incontext', self.rset, row=row, col=col)
 
-
 class TextSearchResultView(EntityView):
     """this view is used to display full-text search