cubicweb/entities/__init__.py
changeset 12506 d97f9b8df92a
parent 12202 1c912b7d9503
child 12567 26744ad37953
equal deleted inserted replaced
12505:55014a79b2a5 12506:d97f9b8df92a
    15 #
    15 #
    16 # You should have received a copy of the GNU Lesser General Public License along
    16 # You should have received a copy of the GNU Lesser General Public License along
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    18 """base application's entities class implementation: `AnyEntity`"""
    18 """base application's entities class implementation: `AnyEntity`"""
    19 
    19 
    20 
       
    21 
       
    22 from warnings import warn
       
    23 
       
    24 from six import text_type, string_types
    20 from six import text_type, string_types
    25 
    21 
    26 from logilab.common.decorators import classproperty
    22 from logilab.common.decorators import classproperty
    27 from logilab.common.deprecation import deprecated
       
    28 
    23 
    29 from cubicweb import Unauthorized
    24 from cubicweb import Unauthorized
    30 from cubicweb.entity import Entity
    25 from cubicweb.entity import Entity
    31 
    26 
    32 
    27 
    45     def cw_create_url(cls, req, **kwargs):
    40     def cw_create_url(cls, req, **kwargs):
    46         """ return the url of the entity creation form for this entity type"""
    41         """ return the url of the entity creation form for this entity type"""
    47         return req.build_url('add/%s' % cls.__regid__, **kwargs)
    42         return req.build_url('add/%s' % cls.__regid__, **kwargs)
    48 
    43 
    49     @classmethod
    44     @classmethod
    50     @deprecated('[3.22] use cw_fti_index_rql_limit instead')
       
    51     def cw_fti_index_rql_queries(cls, req):
       
    52         """return the list of rql queries to fetch entities to FT-index
       
    53 
       
    54         The default is to fetch all entities at once and to prefetch
       
    55         indexable attributes but one could imagine iterating over
       
    56         "smaller" resultsets if the table is very big or returning
       
    57         a subset of entities that match some business-logic condition.
       
    58         """
       
    59         restrictions = ['X is %s' % cls.__regid__]
       
    60         selected = ['X']
       
    61         for attrschema in sorted(cls.e_schema.indexable_attributes()):
       
    62             varname = attrschema.type.upper()
       
    63             restrictions.append('X %s %s' % (attrschema, varname))
       
    64             selected.append(varname)
       
    65         return ['Any %s WHERE %s' % (', '.join(selected),
       
    66                                      ', '.join(restrictions))]
       
    67 
       
    68     @classmethod
       
    69     def cw_fti_index_rql_limit(cls, req, limit=1000):
    45     def cw_fti_index_rql_limit(cls, req, limit=1000):
    70         """generate rsets of entities to FT-index
    46         """generate rsets of entities to FT-index
    71 
    47 
    72         By default, each successive result set is limited to 1000 entities
    48         By default, each successive result set is limited to 1000 entities
    73         """
    49         """
    74         if cls.cw_fti_index_rql_queries.__func__ != AnyEntity.cw_fti_index_rql_queries.__func__:
       
    75             warn("[3.22] cw_fti_index_rql_queries is replaced by cw_fti_index_rql_limit",
       
    76                  DeprecationWarning)
       
    77             for rql in cls.cw_fti_index_rql_queries(req):
       
    78                 yield req.execute(rql)
       
    79             return
       
    80         restrictions = ['X is %s' % cls.__regid__]
    50         restrictions = ['X is %s' % cls.__regid__]
    81         selected = ['X']
    51         selected = ['X']
    82         start = 0
    52         start = 0
    83         for attrschema in sorted(cls.e_schema.indexable_attributes()):
    53         for attrschema in sorted(cls.e_schema.indexable_attributes()):
    84             varname = attrschema.type.upper()
    54             varname = attrschema.type.upper()