web/views/baseviews.py
changeset 2469 b87c4d150e09
parent 2468 93853b6f3bad
child 2471 3e2b50ece726
equal deleted inserted replaced
2468:93853b6f3bad 2469:b87c4d150e09
    19 
    19 
    20 from logilab.mtconverter import TransformError, xml_escape, xml_escape
    20 from logilab.mtconverter import TransformError, xml_escape, xml_escape
    21 
    21 
    22 from cubicweb import NoSelectableObject
    22 from cubicweb import NoSelectableObject
    23 from cubicweb.selectors import yes, empty_rset
    23 from cubicweb.selectors import yes, empty_rset
       
    24 from cubicweb.schema import display_name
    24 from cubicweb.view import EntityView, AnyRsetView, View
    25 from cubicweb.view import EntityView, AnyRsetView, View
    25 from cubicweb.common.uilib import cut, printable_value
    26 from cubicweb.common.uilib import cut, printable_value
    26 
    27 
    27 
    28 
    28 class NullView(AnyRsetView):
    29 class NullView(AnyRsetView):
   234     def call(self, klass=None, title=None, subvid=None, listid=None, **kwargs):
   235     def call(self, klass=None, title=None, subvid=None, listid=None, **kwargs):
   235         """display a list of entities by calling their <item_vid> view
   236         """display a list of entities by calling their <item_vid> view
   236 
   237 
   237         :param listid: the DOM id to use for the root element
   238         :param listid: the DOM id to use for the root element
   238         """
   239         """
       
   240         # XXX much of the behaviour here should probably be outside this view
   239         if subvid is None and 'subvid' in self.req.form:
   241         if subvid is None and 'subvid' in self.req.form:
   240             subvid = self.req.form.pop('subvid') # consume it
   242             subvid = self.req.form.pop('subvid') # consume it
   241         if listid:
   243         if listid:
   242             listid = u' id="%s"' % listid
   244             listid = u' id="%s"' % listid
   243         else:
   245         else:
   281 
   283 
   282 class SimpleListView(ListItemView):
   284 class SimpleListView(ListItemView):
   283     """list without bullets"""
   285     """list without bullets"""
   284     id = 'simplelist'
   286     id = 'simplelist'
   285     redirect_vid = 'incontext'
   287     redirect_vid = 'incontext'
       
   288 
       
   289 
       
   290 class AdaptedListView(ListItemView):
       
   291     """list of entities of the same type"""
       
   292     id = 'adaptedlist'
       
   293     __select__ = non_final_entity() & one_etype_rset()
       
   294     item_vid = 'adaptedlistitem'
       
   295 
       
   296     @property
       
   297     def title(self):
       
   298         etype = iter(self.rset.column_types(0)).next()
       
   299         return display_name(self.req, etype, form='plural'))
       
   300 
       
   301     def call(self, **kwargs):
       
   302         """display a list of entities by calling their <item_vid> view"""
       
   303         if not 'vtitle' in self.req.form:
       
   304             self.w(u'<h1>%s</h1>' % self.title)
       
   305         super(AdaptedListView, self).call(**kwargs)
       
   306 
       
   307     def cell_call(self, row, col=0, vid=None, **kwargs):
       
   308         self.wview(self.item_vid, self.rset, row=row, col=col, vid=vid, **kwargs)
       
   309 
       
   310 
       
   311 class AdaptedListItemView(ListItemView):
       
   312     id = 'adaptedlistitem'
   286 
   313 
   287 
   314 
   288 class CSVView(SimpleListView):
   315 class CSVView(SimpleListView):
   289     id = 'csv'
   316     id = 'csv'
   290     redirect_vid = 'incontext'
   317     redirect_vid = 'incontext'