# HG changeset patch # User Sylvain Thénault # Date 1243260652 -7200 # Node ID 3802c2e37e72b530f964154d038d690fbc67cec7 # Parent 1a0ddb675951f64ed990e7f5b7ab2e46da9f1eb6 handle speaking to an instance using old entity types diff -r 1a0ddb675951 -r 3802c2e37e72 cwvreg.py --- a/cwvreg.py Mon May 25 16:09:34 2009 +0200 +++ b/cwvreg.py Mon May 25 16:10:52 2009 +0200 @@ -11,7 +11,7 @@ from rql import RQLHelper -from cubicweb import Binary, UnknownProperty, UnknownEid +from cubicweb import ETYPE_NAME_MAP, Binary, UnknownProperty, UnknownEid from cubicweb.vregistry import VRegistry, ObjectNotFound, NoSelectableObject from cubicweb.rtags import RTAGS @@ -170,7 +170,10 @@ # browse ancestors from most specific to most generic and # try to find an associated custom entity class for baseschema in baseschemas: - btype = str(baseschema) + try: + btype = ETYPE_NAME_MAP[baseschema] + except KeyError: + btype = str(baseschema) try: cls = self.select(self.registry_objects('etypes', btype), etype) break @@ -387,7 +390,14 @@ vobject.vreg = self vobject.schema = self.schema vobject.config = self.config - return super(MulCnxCubicWebRegistry, self).select(vobjects, *args, **kwargs) + selected = super(MulCnxCubicWebRegistry, self).select(vobjects, *args, + **kwargs) + # redo the same thing on the instance so it won't use equivalent class + # attributes (which may change) + selected.vreg = self + selected.schema = self.schema + selected.config = self.config + return selected from datetime import datetime, date, time, timedelta diff -r 1a0ddb675951 -r 3802c2e37e72 dbapi.py --- a/dbapi.py Mon May 25 16:09:34 2009 +0200 +++ b/dbapi.py Mon May 25 16:10:52 2009 +0200 @@ -13,7 +13,8 @@ from logging import getLogger from time import time, clock -from cubicweb import ConnectionError, RequestSessionMixIn, set_log_methods +from logilab.common.logging_ext import set_log_methods +from cubicweb import ETYPE_NAME_MAP, ConnectionError, RequestSessionMixIn from cubicweb.cwvreg import CubicWebRegistry, MulCnxCubicWebRegistry from cubicweb.cwconfig import CubicWebNoAppConfiguration @@ -101,7 +102,12 @@ vreg = MulCnxCubicWebRegistry(config, initlog=initlog) else: vreg = CubicWebRegistry(config, initlog=initlog) - vreg.set_schema(repo.get_schema()) + schema = repo.get_schema() + for oldetype, newetype in ETYPE_NAME_MAP.items(): + if oldetype in schema: + print 'aliasing', newetype, 'to', oldetype + schema._entities[newetype] = schema._entities[oldetype] + vreg.set_schema(schema) else: vreg = None cnx = repo_connect(repo, user, password, cnxprops) @@ -325,11 +331,6 @@ self.vreg = None # session's data self.data = {} - # XXX < 3.2 bw compat - if 'EUser' in self._repo.get_schema(): - self._user_etype = 'EUser' - else: - self._user_etype = 'CWUser' def __repr__(self): if self.anonymous_connection: @@ -435,9 +436,9 @@ eid, login, groups, properties = self._repo.user_info(self.sessionid, props) if req is None: req = self.request() - rset = req.eid_rset(eid, self._user_etype) - user = self.vreg.etype_class(self._user_etype)(req, rset, row=0, groups=groups, - properties=properties) + rset = req.eid_rset(eid, 'CWUser') + user = self.vreg.etype_class('CWUser')(req, rset, row=0, groups=groups, + properties=properties) user['login'] = login # cache login return user