cwvreg.py
changeset 3293 69c0ba095536
parent 3230 1d25e928c299
parent 3240 8604a15995d1
child 3369 7b88d12b4ee2
equal deleted inserted replaced
3230:1d25e928c299 3293:69c0ba095536
   295                     cpath = cfg.build_vregistry_cube_path([cfg.cube_dir(cube)])
   295                     cpath = cfg.build_vregistry_cube_path([cfg.cube_dir(cube)])
   296                     cleanup_sys_modules(cpath)
   296                     cleanup_sys_modules(cpath)
   297 
   297 
   298     def set_schema(self, schema):
   298     def set_schema(self, schema):
   299         """set instance'schema and load application objects"""
   299         """set instance'schema and load application objects"""
   300         self.schema = schema
   300         self._set_schema(schema)
   301         clear_cache(self, 'rqlhelper')
       
   302         # now we can load application's web objects
   301         # now we can load application's web objects
   303         searchpath = self.config.vregistry_path()
   302         searchpath = self.config.vregistry_path()
   304         self.reset(searchpath, force_reload=False)
   303         self.reset(searchpath, force_reload=False)
   305         self.register_objects(searchpath, force_reload=False)
   304         self.register_objects(searchpath, force_reload=False)
   306         # map lowered entity type names to their actual name
   305         # map lowered entity type names to their actual name
   307         self.case_insensitive_etypes = {}
   306         self.case_insensitive_etypes = {}
   308         for etype in self.schema.entities():
   307         for etype in self.schema.entities():
   309             etype = str(etype)
   308             etype = str(etype)
   310             self.case_insensitive_etypes[etype.lower()] = etype
   309             self.case_insensitive_etypes[etype.lower()] = etype
       
   310 
       
   311     def _set_schema(self, schema):
       
   312         """set instance'schema"""
       
   313         self.schema = schema
       
   314         clear_cache(self, 'rqlhelper')
   311 
   315 
   312     def update_schema(self, schema):
   316     def update_schema(self, schema):
   313         """update .schema attribute on registered objects, necessary for some
   317         """update .schema attribute on registered objects, necessary for some
   314         tests
   318         tests
   315         """
   319         """
   392                     self.unregister(obj)
   396                     self.unregister(obj)
   393         # clear needs_iface so we don't try to remove some not-anymore-in
   397         # clear needs_iface so we don't try to remove some not-anymore-in
   394         # objects on automatic reloading
   398         # objects on automatic reloading
   395         self._needs_iface.clear()
   399         self._needs_iface.clear()
   396 
   400 
   397     def parse(self, session, rql, args=None):
   401     # rql parsing utilities ####################################################
   398         rqlst = self.rqlhelper.parse(rql)
       
   399         def type_from_eid(eid, session=session):
       
   400             return session.describe(eid)[0]
       
   401         try:
       
   402             self.rqlhelper.compute_solutions(rqlst, {'eid': type_from_eid}, args)
       
   403         except UnknownEid:
       
   404             for select in rqlst.children:
       
   405                 select.solutions = []
       
   406         return rqlst
       
   407 
   402 
   408     @property
   403     @property
   409     @cached
   404     @cached
   410     def rqlhelper(self):
   405     def rqlhelper(self):
   411         return RQLHelper(self.schema,
   406         return RQLHelper(self.schema,
   412                          special_relations={'eid': 'uid', 'has_text': 'fti'})
   407                          special_relations={'eid': 'uid', 'has_text': 'fti'})
   413 
   408 
   414 
   409     def solutions(self, req, rqlst, args):
   415     @deprecated('[3.4] use vreg["etypes"].etype_class(etype)')
   410         def type_from_eid(eid, req=req):
   416     def etype_class(self, etype):
   411             return req.describe(eid)[0]
   417         return self["etypes"].etype_class(etype)
   412         self.rqlhelper.compute_solutions(rqlst, {'eid': type_from_eid}, args)
   418 
   413 
   419     @deprecated('[3.4] use vreg["views"].main_template(*args, **kwargs)')
   414     def parse(self, req, rql, args=None):
   420     def main_template(self, req, oid='main-template', **context):
   415         rqlst = self.rqlhelper.parse(rql)
   421         return self["views"].main_template(req, oid, **context)
   416         try:
   422 
   417             self.solutions(req, rqlst, args)
   423     @deprecated('[3.4] use vreg[registry].possible_vobjects(*args, **kwargs)')
   418         except UnknownEid:
   424     def possible_vobjects(self, registry, *args, **kwargs):
   419             for select in rqlst.children:
   425         return self[registry].possible_vobjects(*args, **kwargs)
   420                 select.solutions = []
   426 
   421         return rqlst
   427     @deprecated('[3.4] use vreg["actions"].possible_actions(*args, **kwargs)')
       
   428     def possible_actions(self, req, rset=None, **kwargs):
       
   429         return self["actions"].possible_actions(req, rest=rset, **kwargs)
       
   430 
       
   431     @deprecated("[3.4] use vreg['boxes'].select_or_none(...)")
       
   432     def select_box(self, oid, *args, **kwargs):
       
   433         return self['boxes'].select_or_none(oid, *args, **kwargs)
       
   434 
       
   435     @deprecated("[3.4] use vreg['components'].select_or_none(...)")
       
   436     def select_component(self, cid, *args, **kwargs):
       
   437         return self['components'].select_or_none(cid, *args, **kwargs)
       
   438 
       
   439     @deprecated("[3.4] use vreg['actions'].select_or_none(...)")
       
   440     def select_action(self, oid, *args, **kwargs):
       
   441         return self['actions'].select_or_none(oid, *args, **kwargs)
       
   442 
       
   443     @deprecated("[3.4] use vreg['views'].select(...)")
       
   444     def select_view(self, __vid, req, rset=None, **kwargs):
       
   445         return self['views'].select(__vid, req, rset=rset, **kwargs)
       
   446 
   422 
   447     # properties handling #####################################################
   423     # properties handling #####################################################
   448 
   424 
   449     def user_property_keys(self, withsitewide=False):
   425     def user_property_keys(self, withsitewide=False):
   450         if withsitewide:
   426         if withsitewide:
   512                 self.warning('%s (you should probably delete that property '
   488                 self.warning('%s (you should probably delete that property '
   513                              'from the database)', ex)
   489                              'from the database)', ex)
   514             except UnknownProperty, ex:
   490             except UnknownProperty, ex:
   515                 self.warning('%s (you should probably delete that property '
   491                 self.warning('%s (you should probably delete that property '
   516                              'from the database)', ex)
   492                              'from the database)', ex)
       
   493 
       
   494     # deprecated code ####################################################
       
   495 
       
   496     @deprecated('[3.4] use vreg["etypes"].etype_class(etype)')
       
   497     def etype_class(self, etype):
       
   498         return self["etypes"].etype_class(etype)
       
   499 
       
   500     @deprecated('[3.4] use vreg["views"].main_template(*args, **kwargs)')
       
   501     def main_template(self, req, oid='main-template', **context):
       
   502         return self["views"].main_template(req, oid, **context)
       
   503 
       
   504     @deprecated('[3.4] use vreg[registry].possible_vobjects(*args, **kwargs)')
       
   505     def possible_vobjects(self, registry, *args, **kwargs):
       
   506         return self[registry].possible_vobjects(*args, **kwargs)
       
   507 
       
   508     @deprecated('[3.4] use vreg["actions"].possible_actions(*args, **kwargs)')
       
   509     def possible_actions(self, req, rset=None, **kwargs):
       
   510         return self["actions"].possible_actions(req, rest=rset, **kwargs)
       
   511 
       
   512     @deprecated('[3.4] use vreg["boxes"].select_object(...)')
       
   513     def select_box(self, oid, *args, **kwargs):
       
   514         return self['boxes'].select_object(oid, *args, **kwargs)
       
   515 
       
   516     @deprecated('[3.4] use vreg["components"].select_object(...)')
       
   517     def select_component(self, cid, *args, **kwargs):
       
   518         return self['components'].select_object(cid, *args, **kwargs)
       
   519 
       
   520     @deprecated('[3.4] use vreg["actions"].select_object(...)')
       
   521     def select_action(self, oid, *args, **kwargs):
       
   522         return self['actions'].select_object(oid, *args, **kwargs)
       
   523 
       
   524     @deprecated('[3.4] use vreg["views"].select(...)')
       
   525     def select_view(self, __vid, req, rset=None, **kwargs):
       
   526         return self['views'].select(__vid, req, rset=rset, **kwargs)
   517 
   527 
   518 
   528 
   519 from datetime import datetime, date, time, timedelta
   529 from datetime import datetime, date, time, timedelta
   520 
   530 
   521 YAMS_TO_PY = {
   531 YAMS_TO_PY = {