deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 13 Aug 2009 12:18:14 +0200
changeset 2822 f26578339214
parent 2821 526f44213b70
child 2823 a4e3e9b1a9cd
deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
appobject.py
entity.py
selectors.py
server/hooksmanager.py
server/repository.py
view.py
--- a/appobject.py	Thu Aug 13 11:56:49 2009 +0200
+++ b/appobject.py	Thu Aug 13 12:18:14 2009 +0200
@@ -247,8 +247,6 @@
         the right hook to create an instance for example). By default the
         appobject is returned without any transformation.
         """
-        cls.build___select__()
-        cls.vreg = registry.vreg
         pdefs = getattr(cls, 'cw_property_defs', {})
         for propid, pdef in pdefs.items():
             pdef = pdef.copy() # may be shared
@@ -257,19 +255,16 @@
             registry.vreg.register_property(cls._cwpropkey(propid), **pdef)
         return cls
 
-    def __init__(self, req=None, rset=None, row=None, col=None, **extra):
+    def __init__(self, req, **extra):
         super(AppObject, self).__init__()
-        self.req = req
-        self.rset = rset
-        self.row = row
-        self.col = col
-        self.extra_kwargs = extra
-
-    def view(self, __vid, rset=None, __fallback_oid=None, __registry='views',
-             **kwargs):
-        """shortcut to self.vreg.view method avoiding to pass self.req"""
-        return self.vreg[__registry].render(__vid, self.req, __fallback_oid,
-                                            rset=rset, **kwargs)
+        self.cw_req = req
+        try:
+            self.cw_rset = extra.pop('rset')
+            self.cw_row = extra.pop('row', None)
+            self.cw_col = extra.pop('col', None)
+        except KeyError:
+            pass
+        self.cw_extra_kwargs = extra
 
     # persistent class properties ##############################################
     #
@@ -315,31 +310,60 @@
         return selector
 
     @property
-    @deprecated('[3.5] use req.vreg')
+    @deprecated('[3.5] use cw_req.vreg')
     def vreg(self):
-        return self.req.vreg
+        return self.cw_req.vreg
+
+    @property
+    @deprecated('[3.5] use cw_req.vreg.schema')
+    def schema(self):
+        return self.cw_req.vreg.schema
 
     @property
-    @deprecated('[3.5] use req.vreg.schema')
-    def schema(self):
-        return self.req.vreg.schema
+    @deprecated('[3.5] use cw_req.vreg.config')
+    def config(self):
+        return self.cw_req.vreg.config
+
+    @property
+    @deprecated('use self.cw_req')
+    def req(self):
+        return self.cw_req
+
+    @property
+    @deprecated('use self.cw_rset')
+    def rset(self):
+        return self.cw_rset
 
     @property
-    @deprecated('[3.5] use req.vreg.config')
-    def config(self):
-        return self.req.vreg.config
+    @deprecated('use self.cw_row')
+    def row(self):
+        return self.cw_row
 
-    @deprecated('[3.5] use req.varmaker')
-    def initialize_varmaker(self):
-        self.varmaker = self.req.varmaker
+    @property
+    @deprecated('use self.cw_col')
+    def col(self):
+        return self.cw_col
+
+    @property
+    @deprecated('use self.cw_extra_kwargs')
+    def extra_kwargs(self):
+        return self.cw_extra_kwargs
 
-    @deprecated('[3.5] use req.get_cache')
-    def get_cache(self, cachename):
-        return self.req.get_cache(cachename)
+    @deprecated('[3.5] use cw_req.view')
+    def view(self, *args, **kwargs):
+        return self.cw_req.view(*args, **kwargs)
+
+    @deprecated('[3.5] use cw_req.varmaker')
+    def initialize_varmaker(self):
+        self.varmaker = self.cw_req.varmaker
 
-    @deprecated('[3.5] use req.build_url')
+    @deprecated('[3.5] use cw_req.get_cache')
+    def get_cache(self, cachename):
+        return self.cw_req.get_cache(cachename)
+
+    @deprecated('[3.5] use cw_req.build_url')
     def build_url(self, *args, **kwargs):
-        return self.req.build_url(*args, **kwargs)
+        return self.cw_req.build_url(*args, **kwargs)
 
     @deprecated('[3.5] use rset.limited_rql')
     def limited_rql(self):
@@ -353,32 +377,32 @@
     def entity(self, row, col=0):
         return self.rset.get_entity(row, col)
 
-    @deprecated('[3.5] use req.user_rql_callback')
+    @deprecated('[3.5] use cw_req.user_rql_callback')
     def user_rql_callback(self, args, msg=None):
-        return self.req.user_rql_callback(args, msg)
+        return self.cw_req.user_rql_callback(args, msg)
 
-    @deprecated('[3.5] use req.user_callback')
+    @deprecated('[3.5] use cw_req.user_callback')
     def user_callback(self, cb, args, msg=None, nonify=False):
-        return self.req.user_callback(cb, args, msg, nonify)
+        return self.cw_req.user_callback(cb, args, msg, nonify)
 
-    @deprecated('[3.5] use req.format_date')
+    @deprecated('[3.5] use cw_req.format_date')
     def format_date(self, date, date_format=None, time=False):
-        return self.req.format_date(date, date_format, time)
+        return self.cw_req.format_date(date, date_format, time)
 
-    @deprecated('[3.5] use req.format_timoe')
+    @deprecated('[3.5] use cw_req.format_timoe')
     def format_time(self, time):
-        return self.req.format_time(time)
+        return self.cw_req.format_time(time)
 
-    @deprecated('[3.5] use req.format_float')
+    @deprecated('[3.5] use cw_req.format_float')
     def format_float(self, num):
-        return self.req.format_float(num)
+        return self.cw_req.format_float(num)
 
-    @deprecated('[3.5] use req.parse_datetime')
+    @deprecated('[3.5] use cw_req.parse_datetime')
     def parse_datetime(self, value, etype='Datetime'):
-        return self.req.parse_datetime(value, etype)
+        return self.cw_req.parse_datetime(value, etype)
 
     @deprecated('[3.5] use self.cw_propval')
     def propval(self, propid):
-        return self.req.property_value(self._cwpropkey(propid))
+        return self.cw_req.property_value(self._cwpropkey(propid))
 
 set_log_methods(AppObject, getLogger('cubicweb.appobject'))
--- a/entity.py	Thu Aug 13 11:56:49 2009 +0200
+++ b/entity.py	Thu Aug 13 12:18:14 2009 +0200
@@ -291,7 +291,7 @@
         return mainattr, needcheck
 
     def __init__(self, req, rset=None, row=None, col=0):
-        AppObject.__init__(self, req, rset, row, col)
+        AppObject.__init__(self, req, rset=rset, row=row, col=col)
         dict.__init__(self)
         self._related_cache = {}
         if rset is not None:
--- a/selectors.py	Thu Aug 13 11:56:49 2009 +0200
+++ b/selectors.py	Thu Aug 13 12:18:14 2009 +0200
@@ -112,13 +112,13 @@
         return traceback is None
 
 
-def score_interface(cls_or_inst, cls, iface):
+def score_interface(etypesreg, cls_or_inst, cls, iface):
     """Return XXX if the give object (maybe an instance or class) implements
     the interface.
     """
     if getattr(iface, '__registry__', None) == 'etypes':
         # adjust score if the interface is an entity class
-        parents = cls_or_inst.parent_classes()
+        parents = etypesreg.parent_classes(cls_or_inst.id)
         if iface is cls:
             return len(parents) + 4
         if iface is parents[-1]: # Any
@@ -157,17 +157,18 @@
         return '%s(%s)' % (self.__class__.__name__,
                            ','.join(str(s) for s in self.expected_ifaces))
 
-    def score_interfaces(self, cls_or_inst, cls):
+    def score_interfaces(self, req, cls_or_inst, cls):
         score = 0
-        vreg, eschema = cls_or_inst.vreg, cls_or_inst.e_schema
+        etypesreg = req.vreg['etypes']
+        eschema = cls_or_inst.e_schema
         for iface in self.expected_ifaces:
             if isinstance(iface, basestring):
                 # entity type
                 try:
-                    iface = vreg['etypes'].etype_class(iface)
+                    iface = etypesreg.etype_class(iface)
                 except KeyError:
                     continue # entity type not in the schema
-            score += score_interface(cls_or_inst, cls, iface)
+            score += score_interface(etypesreg, cls_or_inst, cls, iface)
         return score
 
 
@@ -211,7 +212,7 @@
     def score(self, cls, req, etype):
         if etype in BASE_TYPES:
             return 0
-        return self.score_class(cls.vreg['etypes'].etype_class(etype), req)
+        return self.score_class(req.vreg['etypes'].etype_class(etype), req)
 
     def score_class(self, eclass, req):
         raise NotImplementedError()
@@ -560,7 +561,7 @@
 
     def __call__(self, cls, req, **kwargs):
         try:
-            cls.vreg[self.registry].select(self.oid, req, **kwargs)
+            req.vreg[self.registry].select(self.oid, req, **kwargs)
             return 1
         except NoSelectableObject:
             return 0
@@ -584,7 +585,7 @@
           proximity so the most specific object'll be selected
     """
     def score_class(self, eclass, req):
-        return self.score_interfaces(eclass, eclass)
+        return self.score_interfaces(req, eclass, eclass)
 
 
 class specified_etype_implements(implements):
@@ -614,11 +615,11 @@
             # only check this is a known type if etype comes from req.form,
             # else we want the error to propagate
             try:
-                etype = cls.vreg.case_insensitive_etypes[etype.lower()]
+                etype = req.vreg.case_insensitive_etypes[etype.lower()]
                 req.form['etype'] = etype
             except KeyError:
                 return 0
-        return self.score_class(cls.vreg['etypes'].etype_class(etype), req)
+        return self.score_class(req.vreg['etypes'].etype_class(etype), req)
 
 
 class entity_implements(ImplementsMixIn, EntitySelector):
@@ -637,7 +638,7 @@
           proximity so the most specific object'll be selected
     """
     def score_entity(self, entity):
-        return self.score_interfaces(entity, entity.__class__)
+        return self.score_interfaces(entity.req, entity, entity.__class__)
 
 
 class relation_possible(EClassSelector):
--- a/server/hooksmanager.py	Thu Aug 13 11:56:49 2009 +0200
+++ b/server/hooksmanager.py	Thu Aug 13 12:18:14 2009 +0200
@@ -213,7 +213,7 @@
     enabled = True
 
     def __init__(self, event=None):
-        super(Hook, self).__init__()
+        super(Hook, self).__init__(None)
         self.event = event
 
     @classmethod
--- a/server/repository.py	Thu Aug 13 11:56:49 2009 +0200
+++ b/server/repository.py	Thu Aug 13 12:18:14 2009 +0200
@@ -574,7 +574,7 @@
         finally:
             session.close()
         session = Session(user, self, cnxprops)
-        user.req = user.rset.req = session
+        user.cw_req = user.rset.req = session
         user.clear_related_cache()
         self._sessions[session.id] = session
         self.info('opened %s', session)
--- a/view.py	Thu Aug 13 11:56:49 2009 +0200
+++ b/view.py	Thu Aug 13 12:18:14 2009 +0200
@@ -101,7 +101,7 @@
     category = 'view'
 
     def __init__(self, req=None, rset=None, **kwargs):
-        super(View, self).__init__(req, rset, **kwargs)
+        super(View, self).__init__(req, rset=rset, **kwargs)
         self.w = None
 
     @property