merge
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 10 Aug 2009 18:01:46 +0200
changeset 2758 8a54f91a43e1
parent 2756 2c94606eefc0 (current diff)
parent 2757 c8e28e1754f0 (diff)
child 2759 23d7a75693f8
child 2760 30063071aee0
merge
--- a/web/box.py	Mon Aug 10 18:00:50 2009 +0200
+++ b/web/box.py	Mon Aug 10 18:01:46 2009 +0200
@@ -171,11 +171,12 @@
         self.req.add_js('cubicweb.ajax.js')
         entity = self.entity(row, col)
         box = SideBoxWidget(display_name(self.req, self.rtype), self.id)
-        count = self.w_related(box, entity)
-        if count:
+        related = self.related_boxitems(entity)
+        unrelated = self.unrelated_boxitems(entity)
+        box.extend(related)
+        if related and unrelated:
             box.append(BoxSeparator())
-        if not self.w_unrelated(box, entity):
-            del box.items[-1] # remove useless separator
+        box.extend(unrelated)
         box.render(self.w)
 
     def div_id(self):
@@ -192,22 +193,22 @@
                                                etarget.view('incontext'))
         return RawBoxItem(label, liclass=u'invisible')
 
-    def w_related(self, box, entity):
-        """appends existing relations to the `box`"""
+    def related_boxitems(self, entity):
         rql = 'DELETE S %s O WHERE S eid %%(s)s, O eid %%(o)s' % self.rtype
-        related = self.related_entities(entity)
-        for etarget in related:
-            box.append(self.box_item(entity, etarget, rql, u'-'))
-        return len(related)
+        related = []
+        for etarget in self.related_entities(entity):
+            related.append(self.box_item(entity, etarget, rql, u'-'))
+        return related
 
-    def w_unrelated(self, box, entity):
-        """appends unrelated entities to the `box`"""
+    def unrelated_boxitems(self, entity):
         rql = 'SET S %s O WHERE S eid %%(s)s, O eid %%(o)s' % self.rtype
-        i = 0
+        unrelated = []
         for etarget in self.unrelated_entities(entity):
-            box.append(self.box_item(entity, etarget, rql, u'+'))
-            i += 1
-        return i
+            unrelated.append(self.box_item(entity, etarget, rql, u'+'))
+        return unrelated
+
+    def related_entities(self, entity):
+        return entity.related(self.rtype, get_role(self), entities=True)
 
     def unrelated_entities(self, entity):
         """returns the list of unrelated entities
@@ -229,6 +230,3 @@
                 entities.append(rset.get_entity(0, 0))
         return entities
 
-    def related_entities(self, entity):
-        return entity.related(self.rtype, get_role(self), entities=True)
-
--- a/web/htmlwidgets.py	Mon Aug 10 18:00:50 2009 +0200
+++ b/web/htmlwidgets.py	Mon Aug 10 18:01:46 2009 +0200
@@ -58,6 +58,9 @@
     def append(self, item):
         self.items.append(item)
 
+    def extend(self, items):
+        self.items.extend(items)
+
     title_class = 'boxTitle'
     main_div_class = 'boxContent'
     listing_class = 'boxListing'