web/box.py
changeset 250 7fd7a0d387d7
parent 237 3df2e0ae2eba
child 431 18b4dd650ef8
equal deleted inserted replaced
249:5ab64969df20 250:7fd7a0d387d7
     7 __docformat__ = "restructuredtext en"
     7 __docformat__ = "restructuredtext en"
     8 
     8 
     9 from logilab.common.decorators import cached
     9 from logilab.common.decorators import cached
    10 from logilab.mtconverter import html_escape
    10 from logilab.mtconverter import html_escape
    11 
    11 
    12 from cubicweb import Unauthorized
    12 from cubicweb import Unauthorized, role as get_role
    13 from cubicweb.common.registerers import (accepts_registerer,
    13 from cubicweb.common.registerers import (
    14                                       extresources_registerer,
    14     accepts_registerer, extresources_registerer,
    15                                       etype_rtype_priority_registerer)
    15     etype_rtype_priority_registerer)
    16 from cubicweb.common.selectors import (etype_rtype_selector, one_line_rset,
    16 from cubicweb.common.selectors import (
    17                                        accept_selector, accept_rtype_selector,
    17     etype_rtype_selector, one_line_rset, accept_selector, accept_rtype_selector,
    18                                        primaryview_selector, contextprop_selector,
    18     primaryview_selector, contextprop_selector, has_related_entities,
    19                                        _rqlcondition_selector)
    19     _rqlcondition_selector)
    20 from cubicweb.common.view import Template
    20 from cubicweb.common.view import Template
    21 from cubicweb.common.appobject import ReloadableMixIn
    21 from cubicweb.common.appobject import ReloadableMixIn
    22 
    22 
    23 from cubicweb.web.htmlwidgets import (BoxLink, BoxWidget, SideBoxWidget,
    23 from cubicweb.web.htmlwidgets import (BoxLink, BoxWidget, SideBoxWidget,
    24                                    RawBoxItem, BoxSeparator)
    24                                       RawBoxItem, BoxSeparator)
    25 from cubicweb.web.action import UnregisteredAction
    25 from cubicweb.web.action import UnregisteredAction
    26 
    26 
    27 _ = unicode
    27 _ = unicode
    28 
    28 
    29 
    29 
   162         """classes inheriting from EntityBoxTemplate should defined cell_call,
   162         """classes inheriting from EntityBoxTemplate should defined cell_call,
   163         """
   163         """
   164         self.cell_call(row, col, **kwargs)
   164         self.cell_call(row, col, **kwargs)
   165 
   165 
   166 
   166 
       
   167 class RelatedEntityBoxTemplate(EntityBoxTemplate):
       
   168     __selectors__ = EntityBoxTemplate.__selectors__ + (has_related_entities,)
       
   169     
       
   170     def cell_call(self, row, col, **kwargs):
       
   171         entity = self.entity(row, col)
       
   172         limit = self.req.property_value('navigation.related-limit') + 1
       
   173         role = get_role(self)
       
   174         self.w(u'<div class="sideRelated">')
       
   175         self.wview('sidebox', entity.related(self.rtype, role, limit=limit),
       
   176                    title=display_name(self.req, self.rtype, role))
       
   177         self.w(u'</div>')
       
   178 
   167 
   179 
   168 class EditRelationBoxTemplate(ReloadableMixIn, EntityBoxTemplate):
   180 class EditRelationBoxTemplate(ReloadableMixIn, EntityBoxTemplate):
   169     """base class for boxes which let add or remove entities linked
   181     """base class for boxes which let add or remove entities linked
   170     by a given relation
   182     by a given relation
   171 
   183