--- a/appobject.py Thu Aug 13 13:06:10 2009 +0200
+++ b/appobject.py Thu Aug 13 13:07:21 2009 +0200
@@ -204,7 +204,7 @@
:__registry__:
name of the registry for this object (string like 'views',
'templates'...)
- :id:
+ :__id__:
object's identifier in the registry (string like 'main',
'primary', 'folder_box')
:__select__:
@@ -235,7 +235,7 @@
are interested in, else None
"""
__registry__ = None
- id = None
+ __id__ = None
__select__ = yes()
@classmethod
--- a/cwvreg.py Thu Aug 13 13:06:10 2009 +0200
+++ b/cwvreg.py Thu Aug 13 13:07:21 2009 +0200
@@ -18,7 +18,7 @@
ObjectNotFound, NoSelectableObject, RegistryNotFound,
RegistryOutOfDate, CW_EVENT_MANAGER)
from cubicweb.utils import dump_class
-from cubicweb.vregistry import VRegistry, Registry
+from cubicweb.vregistry import VRegistry, Registry, class_regid
from cubicweb.rtags import RTAGS
@@ -96,10 +96,10 @@
clear_cache(self, 'etype_class')
def register(self, obj, **kwargs):
- oid = kwargs.get('oid') or obj.id
+ oid = kwargs.get('oid') or class_regid(obj)
if oid != 'Any' and not oid in self.schema:
self.error('don\'t register %s, %s type not defined in the '
- 'schema', obj, obj.id)
+ 'schema', obj, oid)
return
kwargs['clear'] = True
super(ETypeRegistry, self).register(obj, **kwargs)
@@ -145,11 +145,11 @@
objects = self['Any']
assert len(objects) == 1, objects
cls = objects[0]
- if cls.id == etype:
+ if cls.__id__ == etype:
cls.__initialize__(self.schema)
return cls
cls = dump_class(cls, etype)
- cls.id = etype
+ cls.__id__ = etype
cls.__initialize__(self.schema)
return cls
--- a/entity.py Thu Aug 13 13:06:10 2009 +0200
+++ b/entity.py Thu Aug 13 13:07:21 2009 +0200
@@ -64,7 +64,6 @@
__select__ = yes()
# class attributes that must be set in class definition
- id = None
rest_attr = None
fetch_attrs = None
skip_copy_for = ()
@@ -76,7 +75,7 @@
"""initialize a specific entity class by adding descriptors to access
entity type's attributes and relations
"""
- etype = cls.id
+ etype = cls.__id__
assert etype != 'Any', etype
cls.e_schema = eschema = schema.eschema(etype)
for rschema, _ in eschema.attribute_definitions():
@@ -107,7 +106,7 @@
"""return a rql to fetch all entities of the class type"""
restrictions = restriction or []
if settype:
- restrictions.append('%s is %s' % (mainvar, cls.id))
+ restrictions.append('%s is %s' % (mainvar, cls.__id__))
if fetchattrs is None:
fetchattrs = cls.fetch_attrs
selection = [mainvar]
@@ -140,7 +139,7 @@
rschema = eschema.subject_relation(attr)
except KeyError:
cls.warning('skipping fetch_attr %s defined in %s (not found in schema)',
- attr, cls.id)
+ attr, cls.__id__)
continue
if not user.matching_groups(rschema.get_groups('read')):
continue
@@ -274,7 +273,7 @@
kwargs['_restpath'] = self.rest_path(kwargs.get('base_url'))
except TypeError:
warn('%s: rest_path() now take use_ext_eid argument, '
- 'please update' % self.id, DeprecationWarning)
+ 'please update' % self.__id__, DeprecationWarning)
kwargs['_restpath'] = self.rest_path()
else:
kwargs['rql'] = 'Any X WHERE X eid %s' % self.eid
@@ -416,7 +415,7 @@
def as_rset(self):
"""returns a resultset containing `self` information"""
rset = ResultSet([(self.eid,)], 'Any X WHERE X eid %(x)s',
- {'x': self.eid}, [(self.id,)])
+ {'x': self.eid}, [(self.__id__,)])
return self.req.decorate_rset(rset)
def to_complete_relations(self):
--- a/vregistry.py Thu Aug 13 13:06:10 2009 +0200
+++ b/vregistry.py Thu Aug 13 13:07:21 2009 +0200
@@ -58,6 +58,16 @@
"""returns a unique identifier for an appobject class"""
return '%s.%s' % (cls.__module__, cls.__name__)
+def class_regid(cls):
+ """returns a unique identifier for an appobject class"""
+ if 'id' in cls.__dict__:
+ warn('%s: id is deprecated, use __id__')
+ cls.__id__ = cls.id
+ if hasattr(cls, 'id'):
+ return cls.id
+ return cls.__id__
+
+
class Registry(dict):
def __init__(self, config):
@@ -76,7 +86,7 @@
def register(self, obj, oid=None, clear=False):
"""base method to add an object in the registry"""
assert not '__abstract__' in obj.__dict__
- oid = oid or obj.id
+ oid = oid or class_regid(obj)
assert oid
if clear:
appobjects = self[oid] = []
@@ -94,7 +104,7 @@
# or simplify by calling unregister then register here
if not isinstance(replaced, basestring):
replaced = classid(replaced)
- registered_objs = self.get(obj.id, ())
+ registered_objs = self.get(class_regid(obj), ())
for index, registered in enumerate(registered_objs):
if classid(registered) == replaced:
del registered_objs[index]
@@ -105,17 +115,18 @@
self.register(obj)
def unregister(self, obj):
- oid = classid(obj)
- for registered in self.get(obj.id, ()):
+ clsid = classid(obj)
+ oid = class_regid(obj)
+ for registered in self.get(oid, ()):
# use classid() to compare classes because vreg will probably
# have its own version of the class, loaded through execfile
- if classid(registered) == oid:
+ if classid(registered) == clsid:
# XXX automatic reloading management
- self[obj.id].remove(registered)
+ self[oid].remove(registered)
break
else:
self.warning('can\'t remove %s, no id %s in the registry',
- oid, obj.id)
+ clsid, oid)
def all_objects(self):
"""return a list containing all objects in this registry.
@@ -286,7 +297,7 @@
try:
if obj.__module__ != modname or obj in butclasses:
continue
- oid = obj.id
+ oid = class_regid(obj)
except AttributeError:
continue
if oid and not '__abstract__' in obj.__dict__:
@@ -420,10 +431,10 @@
to a non empty string to be registered.
"""
if (cls.__dict__.get('__abstract__') or cls.__name__[0] == '_'
- or not cls.__registry__ or not cls.id):
+ or not cls.__registry__ or not class_regid(cls)):
return
regname = cls.__registry__
- if '%s.%s' % (regname, cls.id) in self.config['disable-appobjects']:
+ if '%s.%s' % (regname, class_regid(cls)) in self.config['disable-appobjects']:
return
self.register(cls)