web/box.py
branch3.5
changeset 3220 11b6016e3970
parent 2757 c8e28e1754f0
child 3230 1d25e928c299
child 4205 4458c7cc193b
equal deleted inserted replaced
3219:be8cfc00ae04 3220:11b6016e3970
    58     def sort_actions(self, actions):
    58     def sort_actions(self, actions):
    59         """return a list of (category, actions_sorted_by_title)"""
    59         """return a list of (category, actions_sorted_by_title)"""
    60         result = []
    60         result = []
    61         actions_by_cat = {}
    61         actions_by_cat = {}
    62         for action in actions:
    62         for action in actions:
    63             actions_by_cat.setdefault(action.category, []).append((action.title, action))
    63             actions_by_cat.setdefault(action.category, []).append(
       
    64                 (action.title, action) )
    64         for key, values in actions_by_cat.items():
    65         for key, values in actions_by_cat.items():
    65             actions_by_cat[key] = [act for title, act in sorted(values)]
    66             actions_by_cat[key] = [act for title, act in sorted(values)]
    66         for cat in self.categories_in_order:
    67         for cat in self.categories_in_order:
    67             if cat in actions_by_cat:
    68             if cat in actions_by_cat:
    68                 result.append( (cat, actions_by_cat[cat]) )
    69                 result.append( (cat, actions_by_cat[cat]) )
   148 
   149 
   149 class RelatedEntityBoxTemplate(EntityBoxTemplate):
   150 class RelatedEntityBoxTemplate(EntityBoxTemplate):
   150     __select__ = EntityBoxTemplate.__select__ & partial_has_related_entities()
   151     __select__ = EntityBoxTemplate.__select__ & partial_has_related_entities()
   151 
   152 
   152     def cell_call(self, row, col, **kwargs):
   153     def cell_call(self, row, col, **kwargs):
   153         entity = self.entity(row, col)
   154         entity = self.rset.get_entity(row, col)
   154         limit = self.req.property_value('navigation.related-limit') + 1
   155         limit = self.req.property_value('navigation.related-limit') + 1
   155         role = get_role(self)
   156         role = get_role(self)
   156         self.w(u'<div class="sideBox">')
   157         self.w(u'<div class="sideBox">')
   157         self.wview('sidebox', entity.related(self.rtype, role, limit=limit),
   158         self.wview('sidebox', entity.related(self.rtype, role, limit=limit),
   158                    title=display_name(self.req, self.rtype, role))
   159                    title=display_name(self.req, self.rtype, role))
   167     class attributes.
   168     class attributes.
   168     """
   169     """
   169 
   170 
   170     def cell_call(self, row, col, view=None, **kwargs):
   171     def cell_call(self, row, col, view=None, **kwargs):
   171         self.req.add_js('cubicweb.ajax.js')
   172         self.req.add_js('cubicweb.ajax.js')
   172         entity = self.entity(row, col)
   173         entity = self.rset.get_entity(row, col)
   173         box = SideBoxWidget(display_name(self.req, self.rtype), self.id)
   174         box = SideBoxWidget(display_name(self.req, self.rtype), self.id)
   174         related = self.related_boxitems(entity)
   175         related = self.related_boxitems(entity)
   175         unrelated = self.unrelated_boxitems(entity)
   176         unrelated = self.unrelated_boxitems(entity)
   176         box.extend(related)
   177         box.extend(related)
   177         if related and unrelated:
   178         if related and unrelated: