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