Commit f775a5f7 authored by Pierre-Yves David's avatar Pierre-Yves David
Browse files

use cw_etype instead of __regid__

We have a clean public API now.
parent c7a95ebcc093
......@@ -772,7 +772,7 @@ class NoHookRQLObjectStore(RQLObjectStore):
self.source.add_info(session, entity, self.source, None, complete=False)
kwargs = dict()
if inspect.getargspec(self.add_relation).keywords:
kwargs['subjtype'] = entity.__regid__
kwargs['subjtype'] = entity.cw_etype
for rtype, targeteids in rels.iteritems():
# targeteids may be a single eid or a list of eids
inlined = self.rschema(rtype).inlined
......@@ -1069,13 +1069,13 @@ class SQLGenSourceWrapper(object):
def add_entity(self, session, entity):
with self._storage_handler(entity, 'added'):
attrs = self.preprocess_entity(entity)
rtypes = self._inlined_rtypes_cache.get(entity.__regid__, ())
rtypes = self._inlined_rtypes_cache.get(entity.cw_etype, ())
if isinstance(rtypes, str):
rtypes = (rtypes,)
for rtype in rtypes:
if rtype not in attrs:
attrs[rtype] = None
sql = self.sqlgen.insert(SQL_PREFIX + entity.__regid__, attrs)
sql = self.sqlgen.insert(SQL_PREFIX + entity.cw_etype, attrs)
self._sql.eid_insertdicts[entity.eid] = attrs
self._append_to_entities(sql, attrs)
......@@ -1108,7 +1108,7 @@ class SQLGenSourceWrapper(object):
assert isinstance(extid, str)
extid = b64encode(extid)
uri = 'system' if source.copy_based_source else source.uri
attrs = {'type': entity.__regid__, 'eid': entity.eid, 'extid': extid,
attrs = {'type': entity.cw_etype, 'eid': entity.eid, 'extid': extid,
'source': uri, 'asource': source.uri, 'mtime': datetime.utcnow()}
self._handle_insert_entity_sql(session, self.sqlgen.insert('entities', attrs), attrs)
# insert core relations: is, is_instance_of and cw_source
......@@ -1127,7 +1127,7 @@ class SQLGenSourceWrapper(object):
self._handle_is_relation_sql(session, 'INSERT INTO cw_source_relation(eid_from,eid_to) VALUES (%s,%s)',
(entity.eid, source.eid))
# now we can update the full text index
if self.do_fti and self.need_fti_indexation(entity.__regid__):
if self.do_fti and self.need_fti_indexation(entity.cw_etype):
if complete:
entity.complete(entity.e_schema.indexable_attributes())
self.index_entity(session, entity=entity)
......@@ -330,7 +330,7 @@ class ITreeAdapter(view.EntityAdapter):
_done = set()
for child in self.children():
if child.eid in _done:
self.error('loop in %s tree: %s', child.__regid__.lower(), child)
self.error('loop in %s tree: %s', child.cw_etype.lower(), child)
continue
yield child
_done.add(child.eid)
......@@ -357,7 +357,7 @@ class ITreeAdapter(view.EntityAdapter):
entity = adapter.entity
while entity is not None:
if entity.eid in path:
self.error('loop in %s tree: %s', entity.__regid__.lower(), entity)
self.error('loop in %s tree: %s', entity.cw_etype.lower(), entity)
break
path.append(entity.eid)
try:
......
......@@ -124,7 +124,7 @@ class CWSourceSchemaConfig(AnyEntity):
fetch_attrs, cw_fetch_order = fetch_config(['cw_for_source', 'cw_schema', 'options'])
def dc_title(self):
return self._cw._(self.__regid__) + ' #%s' % self.eid
return self._cw._(self.cw_etype) + ' #%s' % self.eid
@property
def schema(self):
......
......@@ -186,7 +186,7 @@ class BaseTransition(AnyEntity):
fetch_attrs, cw_fetch_order = fetch_config(['name', 'type'])
def __init__(self, *args, **kwargs):
if self.__regid__ == 'BaseTransition':
if self.cw_etype == 'BaseTransition':
raise WorkflowException('should not be instantiated')
super(BaseTransition, self).__init__(*args, **kwargs)
......@@ -449,10 +449,10 @@ class IWorkflowableAdapter(WorkflowableMixIn, EntityAdapter):
"""return the default workflow for entities of this type"""
# XXX CWEType method
wfrset = self._cw.execute('Any WF WHERE ET default_workflow WF, '
'ET name %(et)s', {'et': self.entity.__regid__})
'ET name %(et)s', {'et': self.entity.cw_etype})
if wfrset:
return wfrset.get_entity(0, 0)
self.warning("can't find any workflow for %s", self.entity.__regid__)
self.warning("can't find any workflow for %s", self.entity.cw_etype)
return None
@property
......
......@@ -792,7 +792,7 @@ class Entity(AppObject):
for rtype in self.skip_copy_for:
skip_copy_for['subject'].add(rtype)
warn('[3.14] skip_copy_for on entity classes (%s) is deprecated, '
'use cw_skip_for instead with list of couples (rtype, role)' % self.__regid__,
'use cw_skip_for instead with list of couples (rtype, role)' % self.cw_etype,
DeprecationWarning)
for rtype, role in self.cw_skip_copy_for:
assert role in ('subject', 'object'), role
......@@ -844,7 +844,7 @@ class Entity(AppObject):
def as_rset(self): # XXX .cw_as_rset
"""returns a resultset containing `self` information"""
rset = ResultSet([(self.eid,)], 'Any X WHERE X eid %(x)s',
{'x': self.eid}, [(self.__regid__,)])
{'x': self.eid}, [(self.cw_etype,)])
rset.req = self._cw
return rset
......
......@@ -158,7 +158,7 @@ class ChangeEntityUpdateCaches(hook.Operation):
entity = self.entity
extid = entity.cw_metainformation()['extid']
repo._type_source_cache[entity.eid] = (
entity.__regid__, self.newsource.uri, None, self.newsource.uri)
entity.cw_etype, self.newsource.uri, None, self.newsource.uri)
if self.oldsource.copy_based_source:
uri = 'system'
else:
......@@ -216,7 +216,7 @@ class ChangeEntitySourceAddHook(MetaDataHook):
# but has been moved, ignore it'.
self._cw.system_sql('UPDATE entities SET eid=-eid WHERE eid=%(eid)s',
{'eid': self.eidfrom})
attrs = {'type': entity.__regid__, 'eid': entity.eid, 'extid': None,
attrs = {'type': entity.cw_etype, 'eid': entity.eid, 'extid': None,
'source': 'system', 'asource': 'system',
'mtime': datetime.now()}
self._cw.system_sql(syssource.sqlgen.insert('entities', attrs), attrs)
......
......@@ -233,5 +233,5 @@ class EntityDeleteHook(SomethingChangedHook):
# missing required relation
title = '#%s' % self.entity.eid
self._cw.transaction_data.setdefault('pendingchanges', []).append(
('delete_entity', (self.entity.eid, self.entity.__regid__, title)))
('delete_entity', (self.entity.eid, self.entity.cw_etype, title)))
return True
......@@ -10,14 +10,14 @@ for e in rql('Any X WHERE X cw_source S, S name %(name)s', {'name': source}).ent
try:
suri = ecnx.describe(meta['extid'])[1]
except UnknownEid:
print 'cant describe', e.__regid__, e.eid, meta
print 'cant describe', e.cw_etype, e.eid, meta
continue
if suri != 'system':
try:
print 'deleting', e.__regid__, e.eid, suri, e.dc_title().encode('utf8')
print 'deleting', e.cw_etype, e.eid, suri, e.dc_title().encode('utf8')
repo.delete_info(session, e, suri, scleanup=e.eid)
except UnknownEid:
print ' cant delete', e.__regid__, e.eid, meta
print ' cant delete', e.cw_etype, e.eid, meta
commit()
......@@ -39,7 +39,7 @@ todelete = defaultdict(list)
extids = set()
duplicates = []
for entity in rql('Any X WHERE X cw_source S, S eid %(s)s', {'s': source.eid}).entities():
etype = entity.__regid__
etype = entity.cw_etype
if not source.support_entity(etype):
print "source doesn't support %s, delete %s" % (etype, entity.eid)
todelete[etype].append(entity)
......
......@@ -47,7 +47,7 @@ from cubicweb.server import debugged
todelete = {}
host = source.config['base-url'].split('://')[1]
for entity in rql('Any X WHERE X cw_source S, S eid %(s)s', {'s': source.eid}).entities():
etype = entity.__regid__
etype = entity.cw_etype
if not source.support_entity(etype):
print "source doesn't support %s, delete %s" % (etype, entity.eid)
elif etype in DONT_GET_BACK_ETYPES:
......@@ -84,8 +84,8 @@ mapping = []
for mappart in rql('Any X,SCH WHERE X cw_schema SCH, X cw_for_source S, S eid %(s)s',
{'s': source.eid}).entities():
schemaent = mappart.cw_schema[0]
if schemaent.__regid__ != 'CWEType':
assert schemaent.__regid__ == 'CWRType'
if schemaent.cw_etype != 'CWEType':
assert schemaent.cw_etype == 'CWRType'
sch = schema._eid_index[schemaent.eid]
for rdef in sch.rdefs.itervalues():
if not source.support_entity(rdef.subject) \
......
......@@ -236,7 +236,7 @@ class TreeViewMixIn(object):
self.close_item(entity)
def open_item(self, entity):
self.w(u'<li class="%s">\n' % entity.__regid__.lower())
self.w(u'<li class="%s">\n' % entity.cw_etype.lower())
def close_item(self, entity):
self.w(u'</li>\n')
......
......@@ -329,7 +329,7 @@ def check_mandatory_relations(schema, session, eids, fix=1):
else:
rql = 'Any X WHERE NOT Y %s X, X is %s' % (rschema, etype)
for entity in session.execute(rql).entities():
sys.stderr.write(msg % (entity.__regid__, entity.eid, role, rschema))
sys.stderr.write(msg % (entity.cw_etype, entity.eid, role, rschema))
if fix:
#if entity.cw_describe()['source']['uri'] == 'system': XXX
entity.cw_delete() # XXX this is BRUTAL!
......@@ -350,7 +350,7 @@ def check_mandatory_attributes(schema, session, eids, fix=1):
rql = 'Any X WHERE X %s NULL, X is %s, X cw_source S, S name "system"' % (
rschema, rdef.subject)
for entity in session.execute(rql).entities():
sys.stderr.write(msg % (entity.__regid__, entity.eid, rschema))
sys.stderr.write(msg % (entity.cw_etype, entity.eid, rschema))
if fix:
entity.cw_delete()
notify_fixed(fix)
......
......@@ -1336,7 +1336,7 @@ class Repository(object):
suri = 'system'
extid = source.get_extid(entity)
self._extid_cache[(str(extid), suri)] = entity.eid
self._type_source_cache[entity.eid] = (entity.__regid__, suri, extid,
self._type_source_cache[entity.eid] = (entity.cw_etype, suri, extid,
source.uri)
return extid
......@@ -1350,13 +1350,13 @@ class Repository(object):
entity._cw_is_saved = False # entity has an eid but is not yet saved
# init edited_attributes before calling before_add_entity hooks
entity.cw_edited = edited
source = self.locate_etype_source(entity.__regid__)
source = self.locate_etype_source(entity.cw_etype)
# allocate an eid to the entity before calling hooks
entity.eid = self.system_source.create_eid(session)
# set caches asap
extid = self.init_entity_caches(session, entity, source)
if server.DEBUG & server.DBG_REPO:
print 'ADD entity', self, entity.__regid__, entity.eid, edited
print 'ADD entity', self, entity.cw_etype, entity.eid, edited
prefill_entity_caches(entity)
if source.should_call_hooks:
self.hm.call_hooks('before_add_entity', session, entity=entity)
......@@ -1389,7 +1389,7 @@ class Repository(object):
"""
entity = edited.entity
if server.DEBUG & server.DBG_REPO:
print 'UPDATE entity', entity.__regid__, entity.eid, \
print 'UPDATE entity', entity.cw_etype, entity.eid, \
entity.cw_attr_cache, edited
hm = self.hm
eschema = entity.e_schema
......
......@@ -247,7 +247,7 @@ repository.',
entity is deleted.
"""
attrs = {'cw_eid': entity.eid}
sql = self.sqladapter.sqlgen.delete(SQL_PREFIX + entity.__regid__, attrs)
sql = self.sqladapter.sqlgen.delete(SQL_PREFIX + entity.cw_etype, attrs)
self.doexec(session, sql, attrs)
def local_add_relation(self, session, subject, rtype, object):
......
......@@ -197,7 +197,7 @@ def _undo_rel_info(session, subj, rtype, obj):
sentity, oentity = entities
try:
rschema = session.vreg.schema.rschema(rtype)
rdef = rschema.rdefs[(sentity.__regid__, oentity.__regid__)]
rdef = rschema.rdefs[(sentity.cw_etype, oentity.cw_etype)]
except KeyError:
raise _UndoException(session._(
"Can't restore relation %(rtype)s between %(subj)s and "
......@@ -630,38 +630,38 @@ class NativeSQLSource(SQLAdapterMixIn, AbstractSource):
"""add a new entity to the source"""
with self._storage_handler(entity, 'added'):
attrs = self.preprocess_entity(entity)
sql = self.sqlgen.insert(SQL_PREFIX + entity.__regid__, attrs)
sql = self.sqlgen.insert(SQL_PREFIX + entity.cw_etype, attrs)
self.doexec(session, sql, attrs)
if session.ertype_supports_undo(entity.__regid__):
if session.ertype_supports_undo(entity.cw_etype):
self._record_tx_action(session, 'tx_entity_actions', 'C',
etype=entity.__regid__, eid=entity.eid)
etype=entity.cw_etype, eid=entity.eid)
def update_entity(self, session, entity):
"""replace an entity in the source"""
with self._storage_handler(entity, 'updated'):
attrs = self.preprocess_entity(entity)
if session.ertype_supports_undo(entity.__regid__):
if session.ertype_supports_undo(entity.cw_etype):
changes = self._save_attrs(session, entity, attrs)
self._record_tx_action(session, 'tx_entity_actions', 'U',
etype=entity.__regid__, eid=entity.eid,
etype=entity.cw_etype, eid=entity.eid,
changes=self._binary(dumps(changes)))
sql = self.sqlgen.update(SQL_PREFIX + entity.__regid__, attrs,
sql = self.sqlgen.update(SQL_PREFIX + entity.cw_etype, attrs,
['cw_eid'])
self.doexec(session, sql, attrs)
def delete_entity(self, session, entity):
"""delete an entity from the source"""
with self._storage_handler(entity, 'deleted'):
if session.ertype_supports_undo(entity.__regid__):
if session.ertype_supports_undo(entity.cw_etype):
attrs = [SQL_PREFIX + r.type
for r in entity.e_schema.subject_relations()
if (r.final or r.inlined) and not r in VIRTUAL_RTYPES]
changes = self._save_attrs(session, entity, attrs)
self._record_tx_action(session, 'tx_entity_actions', 'D',
etype=entity.__regid__, eid=entity.eid,
etype=entity.cw_etype, eid=entity.eid,
changes=self._binary(dumps(changes)))
attrs = {'cw_eid': entity.eid}
sql = self.sqlgen.delete(SQL_PREFIX + entity.__regid__, attrs)
sql = self.sqlgen.delete(SQL_PREFIX + entity.cw_etype, attrs)
self.doexec(session, sql, attrs)
def add_relation(self, session, subject, rtype, object, inlined=False):
......@@ -978,7 +978,7 @@ class NativeSQLSource(SQLAdapterMixIn, AbstractSource):
assert isinstance(extid, str)
extid = b64encode(extid)
uri = 'system' if source.copy_based_source else source.uri
attrs = {'type': entity.__regid__, 'eid': entity.eid, 'extid': extid,
attrs = {'type': entity.cw_etype, 'eid': entity.eid, 'extid': extid,
'source': uri, 'asource': source.uri, 'mtime': datetime.utcnow()}
self._handle_insert_entity_sql(session, self.sqlgen.insert('entities', attrs), attrs)
# insert core relations: is, is_instance_of and cw_source
......@@ -997,7 +997,7 @@ class NativeSQLSource(SQLAdapterMixIn, AbstractSource):
self._handle_is_relation_sql(session, 'INSERT INTO cw_source_relation(eid_from,eid_to) VALUES (%s,%s)',
(entity.eid, source.eid))
# now we can update the full text index
if self.do_fti and self.need_fti_indexation(entity.__regid__):
if self.do_fti and self.need_fti_indexation(entity.cw_etype):
if complete:
entity.complete(entity.e_schema.indexable_attributes())
self.index_entity(session, entity=entity)
......@@ -1009,7 +1009,7 @@ class NativeSQLSource(SQLAdapterMixIn, AbstractSource):
# one indexable attribute
self.index_entity(session, entity=entity)
# update entities.mtime.
# XXX Only if entity.__regid__ in self.multisources_etypes?
# XXX Only if entity.cw_etype in self.multisources_etypes?
attrs = {'eid': entity.eid, 'mtime': datetime.utcnow()}
self.doexec(session, self.sqlgen.update('entities', attrs, ['eid']), attrs)
......@@ -1191,7 +1191,7 @@ class NativeSQLSource(SQLAdapterMixIn, AbstractSource):
attributes of the entity
"""
restr = {'cw_eid': entity.eid}
sql = self.sqlgen.select(SQL_PREFIX + entity.__regid__, restr, attrs)
sql = self.sqlgen.select(SQL_PREFIX + entity.cw_etype, restr, attrs)
cu = self.doexec(session, sql, restr)
values = dict(zip(attrs, cu.fetchone()))
# ensure backend specific binary are converted back to string
......@@ -1302,7 +1302,7 @@ class NativeSQLSource(SQLAdapterMixIn, AbstractSource):
# restore record in entities (will update fti if needed)
self.add_info(session, entity, self, None, True)
# remove record from deleted_entities if entity's type is multi-sources
if entity.__regid__ in self.multisources_etypes:
if entity.cw_etype in self.multisources_etypes:
self.doexec(session,
'DELETE FROM deleted_entities WHERE eid=%s' % eid)
self.repo.hm.call_hooks('after_add_entity', session, entity=entity)
......@@ -1365,7 +1365,7 @@ class NativeSQLSource(SQLAdapterMixIn, AbstractSource):
# XXX check removal of inlined relation?
# delete the entity
attrs = {'cw_eid': eid}
sql = self.sqlgen.delete(SQL_PREFIX + entity.__regid__, attrs)
sql = self.sqlgen.delete(SQL_PREFIX + entity.cw_etype, attrs)
self.doexec(session, sql, attrs)
# remove record from entities (will update fti if needed)
self.delete_info_multi(session, [entity], self.uri)
......@@ -1385,7 +1385,7 @@ class NativeSQLSource(SQLAdapterMixIn, AbstractSource):
self._reedit_entity(entity, action.changes, err)
entity.cw_edited.check()
self.repo.hm.call_hooks('before_update_entity', session, entity=entity)
sql = self.sqlgen.update(SQL_PREFIX + entity.__regid__, action.changes,
sql = self.sqlgen.update(SQL_PREFIX + entity.cw_etype, action.changes,
['cw_eid'])
self.doexec(session, sql, action.changes)
self.repo.hm.call_hooks('after_update_entity', session, entity=entity)
......@@ -1403,7 +1403,7 @@ class NativeSQLSource(SQLAdapterMixIn, AbstractSource):
rschema = rdef.rtype
if rschema.inlined:
sql = 'SELECT 1 FROM cw_%s WHERE cw_eid=%s and cw_%s=%s'\
% (sentity.__regid__, subj, rtype, obj)
% (sentity.cw_etype, subj, rtype, obj)
else:
sql = 'SELECT 1 FROM %s_relation WHERE eid_from=%s and eid_to=%s'\
% (rtype, subj, obj)
......
......@@ -415,7 +415,7 @@ repository (default to 5 minutes).',
self._query_cache.clear()
return
cu = session.cnxset[self.uri]
cu.execute('DELETE %s X WHERE X eid %%(x)s' % entity.__regid__,
cu.execute('DELETE %s X WHERE X eid %%(x)s' % entity.cw_etype,
{'x': self.repo.eid2extid(self, entity.eid, session)})
self._query_cache.clear()
......
......@@ -239,7 +239,7 @@ class BytesFileSystemStorage(Storage):
sysource = entity._cw.cnxset.source('system')
cu = sysource.doexec(entity._cw,
'SELECT cw_%s FROM cw_%s WHERE cw_eid=%s' % (
attr, entity.__regid__, entity.eid))
attr, entity.cw_etype, entity.eid))
rawvalue = cu.fetchone()[0]
if rawvalue is None: # no previous value
return None
......@@ -253,7 +253,7 @@ class BytesFileSystemStorage(Storage):
session = entity._cw
source = session.repo.system_source
attrs = source.preprocess_entity(entity)
sql = source.sqlgen.update('cw_' + entity.__regid__, attrs,
sql = source.sqlgen.update('cw_' + entity.cw_etype, attrs,
['cw_eid'])
source.doexec(session, sql, attrs)
entity.cw_edited = None
......
......@@ -218,7 +218,7 @@ class CWEntityXMLParser(datafeed.DataFeedXMLParser):
return entity
def process_relations(self, entity, rels):
etype = entity.__regid__
etype = entity.cw_etype
for (rtype, role, action), rules in self.source.mapping.get(etype, {}).iteritems():
try:
related_items = rels[role][rtype]
......
......@@ -85,7 +85,7 @@ class DataFeedLDAPAdapter(datafeed.DataFeedParser):
# disable read security to allow password selection
with entity._cw.security_enabled(read=False):
entity.complete(tuple(attrs))
if entity.__regid__ == 'CWUser':
if entity.cw_etype == 'CWUser':
wf = entity.cw_adapt_to('IWorkflowable')
if wf.state == 'deactivated':
wf.fire_transition('activate')
......@@ -112,7 +112,7 @@ class DataFeedLDAPAdapter(datafeed.DataFeedParser):
return tdict
def before_entity_copy(self, entity, sourceparams):
if entity.__regid__ == 'EmailAddress':
if entity.cw_etype == 'EmailAddress':
entity.cw_edited['address'] = sourceparams['address']
else:
self.ldap2cwattrs(sourceparams, entity.cw_edited)
......@@ -126,7 +126,7 @@ class DataFeedLDAPAdapter(datafeed.DataFeedParser):
def after_entity_copy(self, entity, sourceparams):
super(DataFeedLDAPAdapter, self).after_entity_copy(entity, sourceparams)
if entity.__regid__ == 'EmailAddress':
if entity.cw_etype == 'EmailAddress':
return
groups = filter(None, [self._get_group(name)
for name in self.source.user_default_groups])
......
......@@ -363,7 +363,7 @@ class ResultSetTC(CubicWebTC):
('CWGroup', 'users'))
for entity in rset.entities(): # test get_entity for each row actually
etype, n = expected[entity.cw_row]
self.assertEqual(entity.__regid__, etype)
self.assertEqual(entity.cw_etype, etype)
attr = etype == 'Bookmark' and 'title' or 'name'
self.assertEqual(entity.cw_attr_cache[attr], n)
......@@ -385,7 +385,7 @@ class ResultSetTC(CubicWebTC):
self.assertEqual(rtype, 'title')
self.assertEqual(entity.title, 'aaaa')
entity, rtype = rset.related_entity(1, 1)
self.assertEqual(entity.__regid__, 'CWGroup')
self.assertEqual(entity.cw_etype, 'CWGroup')
self.assertEqual(rtype, 'name')
self.assertEqual(entity.name, 'guests')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment