cubicweb/view.py
changeset 12846 ba3cf6aaa695
parent 12831 b1ef9690f357
child 12880 59d4ad7e7df3
equal deleted inserted replaced
12845:dd557dca2e86 12846:ba3cf6aaa695
    20 
    20 
    21 from cubicweb import _
    21 from cubicweb import _
    22 
    22 
    23 import re
    23 import re
    24 from io import BytesIO
    24 from io import BytesIO
    25 from typing import Union
       
    26 from warnings import warn
    25 from warnings import warn
    27 from functools import partial
    26 from functools import partial
    28 from inspect import getframeinfo, stack
    27 from inspect import getframeinfo, stack
    29 
    28 
    30 from logilab.common.registry import yes, Predicate
    29 from logilab.common.registry import yes
    31 from logilab.mtconverter import xml_escape
    30 from logilab.mtconverter import xml_escape
    32 
    31 
    33 from rql import nodes
    32 from rql import nodes
    34 
    33 
    35 from cubicweb import NotAnEntity
    34 from cubicweb import NotAnEntity
   357 
   356 
   358 # concrete views base classes #################################################
   357 # concrete views base classes #################################################
   359 
   358 
   360 class EntityView(View):
   359 class EntityView(View):
   361     """base class for views applying on an entity (i.e. uniform result set)"""
   360     """base class for views applying on an entity (i.e. uniform result set)"""
   362     __select__: Union[None, str, Predicate] = non_final_entity()
   361     __select__ = non_final_entity()
   363     category = _('entityview')
   362     category = _('entityview')
   364 
   363 
   365     def call(self, **kwargs):
   364     def call(self, **kwargs):
   366         if self.cw_rset is None:
   365         if self.cw_rset is None:
   367             # * cw_extra_kwargs is the place where extra selection arguments are
   366             # * cw_extra_kwargs is the place where extra selection arguments are
   389 
   388 
   390 class StartupView(View):
   389 class StartupView(View):
   391     """base class for views which doesn't need a particular result set to be
   390     """base class for views which doesn't need a particular result set to be
   392     displayed (so they can always be displayed!)
   391     displayed (so they can always be displayed!)
   393     """
   392     """
   394     __select__: Union[None, str, Predicate] = none_rset()
   393     __select__ = none_rset()
   395 
   394 
   396     category = _('startupview')
   395     category = _('startupview')
   397 
   396 
   398     def html_headers(self):
   397     def html_headers(self):
   399         """return a list of html headers (eg something to be inserted between
   398         """return a list of html headers (eg something to be inserted between
   406 
   405 
   407 class EntityStartupView(EntityView):
   406 class EntityStartupView(EntityView):
   408     """base class for entity views which may also be applied to None
   407     """base class for entity views which may also be applied to None
   409     result set (usually a default rql is provided by the view class)
   408     result set (usually a default rql is provided by the view class)
   410     """
   409     """
   411     __select__: Union[None, str, Predicate] = none_rset() | non_final_entity()
   410     __select__ = none_rset() | non_final_entity()
   412 
   411 
   413     default_rql = None
   412     default_rql = None
   414 
   413 
   415     def __init__(self, req, rset=None, **kwargs):
   414     def __init__(self, req, rset=None, **kwargs):
   416         super(EntityStartupView, self).__init__(req, rset=rset, **kwargs)
   415         super(EntityStartupView, self).__init__(req, rset=rset, **kwargs)
   440             self.no_entities(**kwargs)
   439             self.no_entities(**kwargs)
   441 
   440 
   442 
   441 
   443 class AnyRsetView(View):
   442 class AnyRsetView(View):
   444     """base class for views applying on any non empty result sets"""
   443     """base class for views applying on any non empty result sets"""
   445     __select__: Union[None, str, Predicate] = nonempty_rset()
   444     __select__ = nonempty_rset()
   446 
   445 
   447     category = _('anyrsetview')
   446     category = _('anyrsetview')
   448 
   447 
   449     def columns_labels(self, mainindex=0, tr=True):
   448     def columns_labels(self, mainindex=0, tr=True):
   450         """compute the label of the rset colums
   449         """compute the label of the rset colums
   540 
   539 
   541 
   540 
   542 class Component(ReloadableMixIn, View):
   541 class Component(ReloadableMixIn, View):
   543     """base class for components"""
   542     """base class for components"""
   544     __registry__ = 'components'
   543     __registry__ = 'components'
   545     __select__: Union[None, str, Predicate] = yes()
   544     __select__ = yes()
   546 
   545 
   547     # XXX huummm, much probably useless (should be...)
   546     # XXX huummm, much probably useless (should be...)
   548     htmlclass = 'mainRelated'
   547     htmlclass = 'mainRelated'
   549     @property
   548     @property
   550     def cssclass(self):
   549     def cssclass(self):