--- a/appobject.py Fri Aug 14 14:23:21 2009 +0200
+++ b/appobject.py Fri Aug 14 14:31:25 2009 +0200
@@ -219,7 +219,7 @@
At selection time, the following attributes are set on the instance:
- :cw_req:
+ :_cw:
current request
:cw_extra_kwargs:
other received arguments
@@ -260,7 +260,7 @@
def __init__(self, req, **extra):
super(AppObject, self).__init__()
- self.cw_req = req
+ self._cw = req
try:
self.cw_rset = extra.pop('rset')
self.cw_row = extra.pop('row', None)
@@ -313,24 +313,24 @@
return selector
@property
- @deprecated('[3.5] use cw_req.vreg')
+ @deprecated('[3.5] use _cw.vreg')
def vreg(self):
- return self.cw_req.vreg
+ return self._cw.vreg
@property
- @deprecated('[3.5] use cw_req.vreg.schema')
+ @deprecated('[3.5] use _cw.vreg.schema')
def schema(self):
- return self.cw_req.vreg.schema
+ return self._cw.vreg.schema
@property
- @deprecated('[3.5] use cw_req.vreg.config')
+ @deprecated('[3.5] use _cw.vreg.config')
def config(self):
- return self.cw_req.vreg.config
+ return self._cw.vreg.config
@property
- @deprecated('use self.cw_req')
+ @deprecated('use self._cw')
def req(self):
- return self.cw_req
+ return self._cw
@property
@deprecated('use self.cw_rset')
@@ -352,21 +352,21 @@
def extra_kwargs(self):
return self.cw_extra_kwargs
- @deprecated('[3.5] use cw_req.view')
+ @deprecated('[3.5] use _cw.view')
def view(self, *args, **kwargs):
- return self.cw_req.view(*args, **kwargs)
+ return self._cw.view(*args, **kwargs)
- @deprecated('[3.5] use cw_req.varmaker')
+ @deprecated('[3.5] use _cw.varmaker')
def initialize_varmaker(self):
- self.varmaker = self.cw_req.varmaker
+ self.varmaker = self._cw.varmaker
- @deprecated('[3.5] use cw_req.get_cache')
+ @deprecated('[3.5] use _cw.get_cache')
def get_cache(self, cachename):
- return self.cw_req.get_cache(cachename)
+ return self._cw.get_cache(cachename)
- @deprecated('[3.5] use cw_req.build_url')
+ @deprecated('[3.5] use _cw.build_url')
def build_url(self, *args, **kwargs):
- return self.cw_req.build_url(*args, **kwargs)
+ return self._cw.build_url(*args, **kwargs)
@deprecated('[3.5] use rset.limited_rql')
def limited_rql(self):
@@ -380,32 +380,32 @@
def entity(self, row, col=0):
return self.rset.get_entity(row, col)
- @deprecated('[3.5] use cw_req.user_rql_callback')
+ @deprecated('[3.5] use _cw.user_rql_callback')
def user_rql_callback(self, args, msg=None):
- return self.cw_req.user_rql_callback(args, msg)
+ return self._cw.user_rql_callback(args, msg)
- @deprecated('[3.5] use cw_req.user_callback')
+ @deprecated('[3.5] use _cw.user_callback')
def user_callback(self, cb, args, msg=None, nonify=False):
- return self.cw_req.user_callback(cb, args, msg, nonify)
+ return self._cw.user_callback(cb, args, msg, nonify)
- @deprecated('[3.5] use cw_req.format_date')
+ @deprecated('[3.5] use _cw.format_date')
def format_date(self, date, date_format=None, time=False):
- return self.cw_req.format_date(date, date_format, time)
+ return self._cw.format_date(date, date_format, time)
- @deprecated('[3.5] use cw_req.format_timoe')
+ @deprecated('[3.5] use _cw.format_timoe')
def format_time(self, time):
- return self.cw_req.format_time(time)
+ return self._cw.format_time(time)
- @deprecated('[3.5] use cw_req.format_float')
+ @deprecated('[3.5] use _cw.format_float')
def format_float(self, num):
- return self.cw_req.format_float(num)
+ return self._cw.format_float(num)
- @deprecated('[3.5] use cw_req.parse_datetime')
+ @deprecated('[3.5] use _cw.parse_datetime')
def parse_datetime(self, value, etype='Datetime'):
- return self.cw_req.parse_datetime(value, etype)
+ return self._cw.parse_datetime(value, etype)
@deprecated('[3.5] use self.cw_propval')
def propval(self, propid):
- return self.cw_req.property_value(self._cwpropkey(propid))
+ return self._cw.property_value(self._cwpropkey(propid))
set_log_methods(AppObject, getLogger('cubicweb.appobject'))
--- a/hooks/bookmark.py Fri Aug 14 14:23:21 2009 +0200
+++ b/hooks/bookmark.py Fri Aug 14 14:31:25 2009 +0200
@@ -27,5 +27,5 @@
events = ('after_delete_relation',)
def __call__(self):
- AutoDeleteBookmarkOp(self.cw_req,
- bookmark=self.cw_req.entity_from_eid(self.eidfrom))
+ AutoDeleteBookmarkOp(self._cw,
+ bookmark=self._cw.entity_from_eid(self.eidfrom))
--- a/hooks/email.py Fri Aug 14 14:23:21 2009 +0200
+++ b/hooks/email.py Fri Aug 14 14:31:25 2009 +0200
@@ -43,10 +43,10 @@
events = ('after_add_relation',)
def __call__(self):
- entity = self.cw_req.entity_from_eid(self.eidfrom)
+ entity = self._cw.entity_from_eid(self.eidfrom)
if 'primary_email' in entity.e_schema.subject_relations():
- SetPrimaryEmailRelationOp(self.cw_req, entity=entity,
- email=self.cw_req.entity_from_eid(self.eidto))
+ SetPrimaryEmailRelationOp(self._cw, entity=entity,
+ email=self._cw.entity_from_eid(self.eidto))
class SetUseEmailHook(hook.Hook):
"""notify when a bug or story or version has its state modified"""
@@ -56,7 +56,7 @@
events = ('after_add_relation',)
def __call__(self):
- entity = self.cw_req.entity_from_eid(self.eidfrom)
+ entity = self._cw.entity_from_eid(self.eidfrom)
if 'use_email' in entity.e_schema.subject_relations():
- SetUseEmailRelationOp(self.cw_req, entity=entity,
- email=self.cw_req.entity_from_eid(self.eidto))
+ SetUseEmailRelationOp(self._cw, entity=entity,
+ email=self._cw.entity_from_eid(self.eidto))
--- a/hooks/integrity.py Fri Aug 14 14:23:21 2009 +0200
+++ b/hooks/integrity.py Fri Aug 14 14:31:25 2009 +0200
@@ -74,11 +74,11 @@
def checkrel_if_necessary(self, opcls, rtype, eid):
"""check an equivalent operation has not already been added"""
- for op in self.cw_req.pending_operations:
+ for op in self._cw.pending_operations:
if isinstance(op, opcls) and op.rtype == rtype and op.eid == eid:
break
else:
- opcls(self.cw_req, rtype=rtype, eid=eid)
+ opcls(self._cw, rtype=rtype, eid=eid)
def after_add_entity(self):
eid = self.entity.eid
@@ -105,7 +105,7 @@
rtype = self.rtype
if rtype in DONT_CHECK_RTYPES_ON_DEL:
return
- session = self.cw_req
+ session = self._cw
eidfrom, eidto = self.eidfrom, self.eidto
card = session.schema_rproperty(rtype, eidfrom, eidto, 'cardinality')
pendingrdefs = session.transaction_data.get('pendingrdefs', ())
@@ -149,10 +149,10 @@
events = ('after_add_relation',)
def __call__(self):
- constraints = self.cw_req.schema_rproperty(self.rtype, self.eidfrom, self.eidto,
+ constraints = self._cw.schema_rproperty(self.rtype, self.eidfrom, self.eidto,
'constraints')
if constraints:
- _CheckConstraintsOp(self.cw_req, constraints=constraints,
+ _CheckConstraintsOp(self._cw, constraints=constraints,
rdef=(self.eidfrom, self.rtype, self.eidto))
@@ -170,9 +170,9 @@
if eschema.subject_relation(attr).is_final() and \
eschema.has_unique_values(attr):
rql = '%s X WHERE X %s %%(val)s' % (entity.e_schema, attr)
- rset = self.cw_req.unsafe_execute(rql, {'val': val})
+ rset = self._cw.unsafe_execute(rql, {'val': val})
if rset and rset[0][0] != entity.eid:
- msg = self.cw_req._('the value "%s" is already used, use another one')
+ msg = self._cw._('the value "%s" is already used, use another one')
raise ValidationError(entity.eid, {attr: msg % val})
@@ -199,13 +199,13 @@
events = ('before_delete_relation',)
def __call__(self):
- composite = self.cw_req.schema_rproperty(self.rtype, self.eidfrom, self.eidto,
+ composite = self._cw.schema_rproperty(self.rtype, self.eidfrom, self.eidto,
'composite')
if composite == 'subject':
- _DelayedDeleteOp(self.cw_req, eid=self.eidto,
+ _DelayedDeleteOp(self._cw, eid=self.eidto,
relation='Y %s X' % self.rtype)
elif composite == 'object':
- _DelayedDeleteOp(self.cw_req, eid=self.eidfrom,
+ _DelayedDeleteOp(self._cw, eid=self.eidfrom,
relation='X %s Y' % self.rtype)
@@ -218,12 +218,12 @@
def __call__(self):
if self.event == 'before_delete_entity' and self.entity.name == 'owners':
- raise ValidationError(self.entity.eid, {None: self.cw_req._('can\'t be deleted')})
+ raise ValidationError(self.entity.eid, {None: self._cw._('can\'t be deleted')})
elif self.event == 'before_update_entity' and 'name' in self.entity.edited_attribute:
newname = self.entity.pop('name')
oldname = self.entity.name
if oldname == 'owners' and newname != oldname:
- raise ValidationError(self.entity.eid, {'name': self.cw_req._('can\'t be changed')})
+ raise ValidationError(self.entity.eid, {'name': self._cw._('can\'t be changed')})
self.entity['name'] = newname
@@ -243,7 +243,7 @@
continue # no text to tidy
if isinstance(value, unicode): # filter out None and Binary
if getattr(entity, str(metaattr)) == 'text/html':
- entity[attr] = soup2xhtml(value, self.cw_req.encoding)
+ entity[attr] = soup2xhtml(value, self._cw.encoding)
class StripCWUserLoginHook(IntegrityHook):
--- a/hooks/metadata.py Fri Aug 14 14:23:21 2009 +0200
+++ b/hooks/metadata.py Fri Aug 14 14:31:25 2009 +0200
@@ -43,8 +43,8 @@
timestamp = datetime.now()
self.entity.setdefault('creation_date', timestamp)
self.entity.setdefault('modification_date', timestamp)
- if not self.cw_req.get_shared_data('do-not-insert-cwuri'):
- cwuri = u'%seid/%s' % (self.cw_req.base_url(), self.entity.eid)
+ if not self._cw.get_shared_data('do-not-insert-cwuri'):
+ cwuri = u'%seid/%s' % (self._cw.base_url(), self.entity.eid)
self.entity.setdefault('cwuri', cwuri)
@@ -76,7 +76,7 @@
def __call__(self):
if hasattr(self.entity, '_cw_recreating'):
return
- session = self.cw_req
+ session = self._cw
entity = self.entity
try:
session.add_relation(entity.eid, 'is',
@@ -95,9 +95,9 @@
events = ('after_add_entity',)
def __call__(self):
- asession = self.cw_req.actual_session()
+ asession = self._cw.actual_session()
if not asession.is_internal_session:
- self.cw_req.add_relation(self.entity.eid, 'owned_by', asession.user.eid)
+ self._cw.add_relation(self.entity.eid, 'owned_by', asession.user.eid)
_SetCreatorOp(asession, entity=self.entity)
@@ -121,11 +121,11 @@
# skip this special composite relation # XXX (syt) why?
return
eidfrom, eidto = self.eidfrom, self.eidto
- composite = self.cw_req.schema_rproperty(self.rtype, eidfrom, eidto, 'composite')
+ composite = self._cw.schema_rproperty(self.rtype, eidfrom, eidto, 'composite')
if composite == 'subject':
- _SyncOwnersOp(self.cw_req, compositeeid=eidfrom, composedeid=eidto)
+ _SyncOwnersOp(self._cw, compositeeid=eidfrom, composedeid=eidto)
elif composite == 'object':
- _SyncOwnersOp(self.cw_req, compositeeid=eidto, composedeid=eidfrom)
+ _SyncOwnersOp(self._cw, compositeeid=eidto, composedeid=eidfrom)
class FixUserOwnershipHook(MetaDataHook):
@@ -135,7 +135,7 @@
events = ('after_add_entity',)
def __call__(self):
- self.cw_req.add_relation(self.entity.eid, 'owned_by', self.entity.eid)
+ self._cw.add_relation(self.entity.eid, 'owned_by', self.entity.eid)
class UpdateFTIHook(MetaDataHook):
@@ -146,7 +146,7 @@
def __call__(self):
rtype = self.rtype
- session = self.cw_req
+ session = self._cw
if self.event == 'after_add_relation':
# Reindexing the contained entity is enough since it will implicitly
# reindex the container entity.
--- a/hooks/notification.py Fri Aug 14 14:23:21 2009 +0200
+++ b/hooks/notification.py Fri Aug 14 14:31:25 2009 +0200
@@ -28,7 +28,7 @@
category = 'notification'
def select_view(self, vid, rset, row=0, col=0):
- return self.cw_req.vreg['views'].select_object(vid, self.cw_req,
+ return self._cw.vreg['views'].select_object(vid, self._cw,
rset=rset, row=0, col=0)
@@ -50,7 +50,7 @@
if comment:
comment = normalize_text(comment, 80,
rest=entity.comment_format=='text/rest')
- RenderAndSendNotificationView(self.cw_req, view=view, viewargs={
+ RenderAndSendNotificationView(self._cw, view=view, viewargs={
'comment': comment, 'previous_state': entity.previous_state.name,
'current_state': entity.new_state.name})
@@ -64,12 +64,12 @@
"""if a notification view is defined for the event, send notification
email defined by the view
"""
- rset = self.cw_req.eid_rset(self.eidfrom)
+ rset = self._cw.eid_rset(self.eidfrom)
view = self.select_view('notif_%s_%s' % (self.event, self.rtype),
rset=rset, row=0)
if view is None:
return
- RenderAndSendNotificationView(self.cw_req, view=view)
+ RenderAndSendNotificationView(self._cw, view=view)
class EntityChangeHook(NotificationHook):
@@ -84,7 +84,7 @@
view = self.select_view('notif_%s' % self.event, rset=rset, row=0)
if view is None:
return
- RenderAndSendNotificationView(self.cw_req, view=view)
+ RenderAndSendNotificationView(self._cw, view=view)
# supervising ##################################################################
@@ -95,16 +95,16 @@
'after_add_entity', 'before_update_entity')
def __call__(self):
- dest = self.cw_req.vreg.config['supervising-addrs']
+ dest = self._cw.vreg.config['supervising-addrs']
if not dest: # no supervisors, don't do this for nothing...
return
if self._call():
- SupervisionMailOp(self.cw_req)
+ SupervisionMailOp(self._cw)
def _call(self):
event = self.event.split('_', 1)[1]
if event == 'update_entity':
- if self.cw_req.added_in_transaction(self.entity.eid):
+ if self._cw.added_in_transaction(self.entity.eid):
return False
if self.entity.e_schema == 'CWUser':
if not (self.entity.edited_attributes - frozenset(('eid', 'modification_date',
@@ -112,7 +112,7 @@
# don't record last_login_time update which are done
# automatically at login time
return False
- self.cw_req.transaction_data.setdefault('pendingchanges', []).append(
+ self._cw.transaction_data.setdefault('pendingchanges', []).append(
(event, self))
return True
@@ -128,6 +128,6 @@
# may raise an error during deletion process, for instance due to
# missing required relation
title = '#%s' % eid
- self.cw_req.transaction_data.setdefault('pendingchanges', []).append(
+ self._cw.transaction_data.setdefault('pendingchanges', []).append(
('delete_entity', (self.eid, str(self.entity.e_schema), title)))
return True
--- a/hooks/security.py Fri Aug 14 14:23:21 2009 +0200
+++ b/hooks/security.py Fri Aug 14 14:31:25 2009 +0200
@@ -60,7 +60,7 @@
events = ('after_add_entity',)
def __call__(self):
- _CheckEntityPermissionOp(self.cw_req, entity=self.entity, action='add')
+ _CheckEntityPermissionOp(self._cw, entity=self.entity, action='add')
class AfterUpdateEntitySecurityHook(SecurityHook):
@@ -71,10 +71,10 @@
try:
# check user has permission right now, if not retry at commit time
self.entity.check_perm('update')
- check_entity_attributes(self.cw_req, self.entity)
+ check_entity_attributes(self._cw, self.entity)
except Unauthorized:
self.entity.clear_local_perm_cache('update')
- _CheckEntityPermissionOp(self.cw_req, entity=self.entity, action='update')
+ _CheckEntityPermissionOp(self._cw, entity=self.entity, action='update')
class BeforeDelEntitySecurityHook(SecurityHook):
@@ -82,7 +82,7 @@
events = ('before_delete_entity',)
def __call__(self):
- self.entity.e_schema.check_perm(self.cw_req, 'delete', eid)
+ self.entity.e_schema.check_perm(self._cw, 'delete', eid)
class BeforeAddRelationSecurityHook(SecurityHook):
@@ -91,8 +91,8 @@
def __call__(self):
if self.rtype in BEFORE_ADD_RELATIONS:
- rschema = self.cw_req.repo.schema[self.rtype]
- rschema.check_perm(self.cw_req, 'add', self.eidfrom, self.eidto)
+ rschema = self._cw.repo.schema[self.rtype]
+ rschema.check_perm(self._cw, 'add', self.eidfrom, self.eidto)
class AfterAddRelationSecurityHook(SecurityHook):
@@ -101,14 +101,14 @@
def __call__(self):
if not self.rtype in BEFORE_ADD_RELATIONS:
- rschema = self.cw_req.repo.schema[self.rtype]
+ rschema = self._cw.repo.schema[self.rtype]
if self.rtype in ON_COMMIT_ADD_RELATIONS:
- _CheckRelationPermissionOp(self.cw_req, action='add',
+ _CheckRelationPermissionOp(self._cw, action='add',
rschema=rschema,
eidfrom=self.eidfrom,
eidto=self.eidto)
else:
- rschema.check_perm(self.cw_req, 'add', self.eidfrom, self.eidto)
+ rschema.check_perm(self._cw, 'add', self.eidfrom, self.eidto)
class BeforeDelRelationSecurityHook(SecurityHook):
@@ -116,6 +116,6 @@
events = ('before_delete_relation',)
def __call__(self):
- self.cw_req.repo.schema[self.rtype].check_perm(self.cw_req, 'delete',
+ self._cw.repo.schema[self.rtype].check_perm(self._cw, 'delete',
self.eidfrom, self.eidto)
--- a/hooks/syncschema.py Fri Aug 14 14:23:21 2009 +0200
+++ b/hooks/syncschema.py Fri Aug 14 14:31:25 2009 +0200
@@ -749,11 +749,11 @@
# final entities can't be deleted, don't care about that
name = self.entity.name
if name in CORE_ETYPES:
- raise ValidationError(self.entity.eid, {None: self.cw_req._('can\'t be deleted')})
+ raise ValidationError(self.entity.eid, {None: self._cw._('can\'t be deleted')})
# delete every entities of this type
- self.cw_req.unsafe_execute('DELETE %s X' % name)
- DropTable(self.cw_req, table=SQL_PREFIX + name)
- MemSchemaCWETypeDel(self.cw_req, name)
+ self._cw.unsafe_execute('DELETE %s X' % name)
+ DropTable(self._cw, table=SQL_PREFIX + name)
+ MemSchemaCWETypeDel(self._cw, name)
class AfterDelCWETypeHook(DelCWETypeHook):
@@ -762,8 +762,8 @@
def __call__(self):
# workflow cleanup
- self.cw_req.execute('DELETE State X WHERE NOT X state_of Y')
- self.cw_req.execute('DELETE Transition X WHERE NOT X transition_of Y')
+ self._cw.execute('DELETE State X WHERE NOT X state_of Y')
+ self._cw.execute('DELETE Transition X WHERE NOT X transition_of Y')
class AfterAddCWETypeHook(DelCWETypeHook):
@@ -782,17 +782,17 @@
entity = self.entity
if entity.get('final'):
return
- schema = self.cw_req.schema
+ schema = self._cw.schema
name = entity['name']
etype = EntityType(name=name, description=entity.get('description'),
meta=entity.get('meta')) # don't care about final
# fake we add it to the schema now to get a correctly initialized schema
# but remove it before doing anything more dangerous...
- schema = self.cw_req.schema
+ schema = self._cw.schema
eschema = schema.add_entity_type(etype)
eschema.set_default_groups()
# generate table sql and rql to add metadata
- tablesql = eschema2sql(self.cw_req.pool.source('system').dbhelper, eschema,
+ tablesql = eschema2sql(self._cw.pool.source('system').dbhelper, eschema,
prefix=SQL_PREFIX)
relrqls = []
for rtype in (META_RTYPES - VIRTUAL_RTYPES):
@@ -806,15 +806,15 @@
# create the necessary table
for sql in tablesql.split(';'):
if sql.strip():
- self.cw_req.system_sql(sql)
+ self._cw.system_sql(sql)
# register operation to modify the schema on commit
# this have to be done before adding other relations definitions
# or permission settings
etype.eid = entity.eid
- MemSchemaCWETypeAdd(self.cw_req, etype)
+ MemSchemaCWETypeAdd(self._cw, etype)
# add meta relations
for rql, kwargs in relrqls:
- self.cw_req.execute(rql, kwargs)
+ self._cw.execute(rql, kwargs)
class BeforeUpdateCWETypeHook(DelCWETypeHook):
@@ -824,14 +824,14 @@
def __call__(self):
entity = self.entity
- check_valid_changes(self.cw_req, entity, ro_attrs=('final',))
+ check_valid_changes(self._cw, entity, ro_attrs=('final',))
# don't use getattr(entity, attr), we would get the modified value if any
if 'name' in entity.edited_attributes:
newname = entity.pop('name')
oldname = entity.name
if newname.lower() != oldname.lower():
- SourceDbCWETypeRename(self.cw_req, oldname=oldname, newname=newname)
- MemSchemaCWETypeRename(self.cw_req, oldname=oldname, newname=newname)
+ SourceDbCWETypeRename(self._cw, oldname=oldname, newname=newname)
+ MemSchemaCWETypeRename(self._cw, oldname=oldname, newname=newname)
entity['name'] = newname
@@ -850,13 +850,13 @@
def __call__(self):
name = self.entity.name
if name in CORE_ETYPES:
- raise ValidationError(self.entity.eid, {None: self.cw_req._('can\'t be deleted')})
+ raise ValidationError(self.entity.eid, {None: self._cw._('can\'t be deleted')})
# delete relation definitions using this relation type
- self.cw_req.execute('DELETE CWAttribute X WHERE X relation_type Y, Y eid %(x)s',
+ self._cw.execute('DELETE CWAttribute X WHERE X relation_type Y, Y eid %(x)s',
{'x': self.entity.eid})
- self.cw_req.execute('DELETE CWRelation X WHERE X relation_type Y, Y eid %(x)s',
+ self._cw.execute('DELETE CWRelation X WHERE X relation_type Y, Y eid %(x)s',
{'x': self.entity.eid})
- MemSchemaCWRTypeDel(self.cw_req, name)
+ MemSchemaCWRTypeDel(self._cw, name)
class AfterAddCWRTypeHook(DelCWRTypeHook):
@@ -877,7 +877,7 @@
inlined=entity.get('inlined', False),
symetric=entity.get('symetric', False),
eid=entity.eid)
- MemSchemaCWRTypeAdd(self.cw_req, rtype)
+ MemSchemaCWRTypeAdd(self._cw, rtype)
class BeforeUpdateCWRTypeHook(DelCWRTypeHook):
@@ -886,7 +886,7 @@
events = ('before_update_entity',)
def __call__(self):
- check_valid_changes(self.cw_req, self.entity)
+ check_valid_changes(self._cw, self.entity)
class AfterUpdateCWRTypeHook(DelCWRTypeHook):
@@ -895,14 +895,14 @@
def __call__(self):
entity = self.entity
- rschema = self.cw_req.schema.rschema(entity.name)
+ rschema = self._cw.schema.rschema(entity.name)
newvalues = {}
for prop in ('meta', 'symetric', 'inlined'):
if prop in entity:
newvalues[prop] = entity[prop]
if newvalues:
- MemSchemaCWRTypeUpdate(self.cw_req, rschema=rschema, values=newvalues)
- SourceDbCWRTypeUpdate(self.cw_req, rschema=rschema, values=newvalues,
+ MemSchemaCWRTypeUpdate(self._cw, rschema=rschema, values=newvalues)
+ SourceDbCWRTypeUpdate(self._cw, rschema=rschema, values=newvalues,
entity=entity)
@@ -922,7 +922,7 @@
events = ('after_delete_relation',)
def __call__(self):
- session = self.cw_req
+ session = self._cw
subjschema, rschema, objschema = session.schema.schema_by_eid(self.eidfrom)
pendings = session.transaction_data.get('pendingeids', ())
# first delete existing relation if necessary
@@ -968,7 +968,7 @@
events = ('after_add_entity',)
def __call__(self):
- SourceDbCWAttributeAdd(self.cw_req, entity=self.entity)
+ SourceDbCWAttributeAdd(self._cw, entity=self.entity)
class AfterAddCWRelationHook(AfterAddCWAttributeHook):
@@ -976,7 +976,7 @@
__select__ = SyncSchemaHook.__select__ & entity_implements('CWRelation')
def __call__(self):
- SourceDbCWRelationAdd(self.cw_req, entity=self.entity)
+ SourceDbCWRelationAdd(self._cw, entity=self.entity)
class AfterUpdateCWRDefHook(SyncSchemaHook):
@@ -987,10 +987,10 @@
def __call__(self):
entity = self.entity
- if self.cw_req.deleted_in_transaction(entity.eid):
+ if self._cw.deleted_in_transaction(entity.eid):
return
desttype = entity.otype.name
- rschema = self.cw_req.schema[entity.rtype.name]
+ rschema = self._cw.schema[entity.rtype.name]
newvalues = {}
for prop in rschema.rproperty_defs(desttype):
if prop == 'constraints':
@@ -1001,9 +1001,9 @@
newvalues[prop] = entity[prop]
if newvalues:
subjtype = entity.stype.name
- MemSchemaRDefUpdate(self.cw_req, kobj=(subjtype, desttype),
+ MemSchemaRDefUpdate(self._cw, kobj=(subjtype, desttype),
rschema=rschema, values=newvalues)
- SourceDbRDefUpdate(self.cw_req, kobj=(subjtype, desttype),
+ SourceDbRDefUpdate(self._cw, kobj=(subjtype, desttype),
rschema=rschema, values=newvalues)
@@ -1015,8 +1015,8 @@
events = ('after_add_entity', 'after_update_entity')
def __call__(self):
- MemSchemaCWConstraintAdd(self.cw_req, entity=self.entity)
- SourceDbCWConstraintAdd(self.cw_req, entity=self.entity)
+ MemSchemaCWConstraintAdd(self._cw, entity=self.entity)
+ SourceDbCWConstraintAdd(self._cw, entity=self.entity)
class AfterAddConstrainedByHook(SyncSchemaHook):
@@ -1025,8 +1025,8 @@
events = ('after_add_relation',)
def __call__(self):
- if self.cw_req.added_in_transaction(self.eidfrom):
- self.cw_req.transaction_data.setdefault(self.eidfrom, []).append(self.eidto)
+ if self._cw.added_in_transaction(self.eidfrom):
+ self._cw.transaction_data.setdefault(self.eidfrom, []).append(self.eidto)
class BeforeDeleteConstrainedByHook(AfterAddConstrainedByHook):
@@ -1034,20 +1034,20 @@
events = ('before_delete_relation',)
def __call__(self):
- if self.cw_req.deleted_in_transaction(self.eidfrom):
+ if self._cw.deleted_in_transaction(self.eidfrom):
return
- schema = self.cw_req.schema
- entity = self.cw_req.entity_from_eid(self.eidto)
+ schema = self._cw.schema
+ entity = self._cw.entity_from_eid(self.eidto)
subjtype, rtype, objtype = schema.schema_by_eid(self.eidfrom)
try:
cstr = rtype.constraint_by_type(subjtype, objtype,
entity.cstrtype[0].name)
except IndexError:
- self.cw_req.critical('constraint type no more accessible')
+ self._cw.critical('constraint type no more accessible')
else:
- SourceDbCWConstraintDel(self.cw_req, subjtype=subjtype, rtype=rtype,
+ SourceDbCWConstraintDel(self._cw, subjtype=subjtype, rtype=rtype,
objtype=objtype, cstr=cstr)
- MemSchemaCWConstraintDel(self.cw_req, subjtype=subjtype, rtype=rtype,
+ MemSchemaCWConstraintDel(self._cw, subjtype=subjtype, rtype=rtype,
objtype=objtype, cstr=cstr)
@@ -1064,11 +1064,11 @@
def __call__(self):
perm = self.rtype.split('_', 1)[0]
- if self.cw_req.describe(self.eidto)[0] == 'CWGroup':
- MemSchemaPermCWGroupAdd(self.cw_req, perm, self.eidfrom, self.eidto)
+ if self._cw.describe(self.eidto)[0] == 'CWGroup':
+ MemSchemaPermCWGroupAdd(self._cw, perm, self.eidfrom, self.eidto)
else: # RQLExpression
- expr = self.cw_req.entity_from_eid(self.eidto).expression
- MemSchemaPermRQLExpressionAdd(self.cw_req, perm, self.eidfrom, expr)
+ expr = self._cw.entity_from_eid(self.eidto).expression
+ MemSchemaPermRQLExpressionAdd(self._cw, perm, self.eidfrom, expr)
class BeforeDelPermissionHook(AfterAddPermissionHook):
@@ -1080,14 +1080,14 @@
events = ('before_delete_relation',)
def __call__(self):
- if self.cw_req.deleted_in_transaction(self.eidfrom):
+ if self._cw.deleted_in_transaction(self.eidfrom):
return
perm = self.rtype.split('_', 1)[0]
- if self.cw_req.describe(self.eidto)[0] == 'CWGroup':
- MemSchemaPermCWGroupDel(self.cw_req, perm, self.eidfrom, self.eidto)
+ if self._cw.describe(self.eidto)[0] == 'CWGroup':
+ MemSchemaPermCWGroupDel(self._cw, perm, self.eidfrom, self.eidto)
else: # RQLExpression
- expr = self.cw_req.entity_from_eid(self.eidto).expression
- MemSchemaPermRQLExpressionDel(self.cw_req, perm, self.eidfrom, expr)
+ expr = self._cw.entity_from_eid(self.eidto).expression
+ MemSchemaPermRQLExpressionDel(self._cw, perm, self.eidfrom, expr)
@@ -1100,4 +1100,4 @@
# registering a schema operation will trigger a call to
# repo.set_schema() on commit which will in turn rebuild
# infered relation definitions
- MemSchemaNotifyChanges(self.cw_req)
+ MemSchemaNotifyChanges(self._cw)
--- a/hooks/syncsession.py Fri Aug 14 14:23:21 2009 +0200
+++ b/hooks/syncsession.py Fri Aug 14 14:31:25 2009 +0200
@@ -74,8 +74,8 @@
opcls = _DeleteGroupOp
else:
opcls = _AddGroupOp
- for session in get_user_sessions(self.cw_req.repo, self.eidfrom):
- opcls(self.cw_req, cnxuser=session.user, geid=self.eidto)
+ for session in get_user_sessions(self._cw.repo, self.eidfrom):
+ opcls(self._cw, cnxuser=session.user, geid=self.eidto)
class _DelUserOp(hook.Operation):
@@ -99,8 +99,8 @@
def __call__(self):
"""modify user permission, need to update users"""
- for session in get_user_sessions(self.cw_req.repo, self.entity.eid):
- _DelUserOp(self.cw_req, session.id)
+ for session in get_user_sessions(self._cw.repo, self.entity.eid):
+ _DelUserOp(self._cw, session.id)
# CWProperty hooks #############################################################
@@ -143,7 +143,7 @@
def __call__(self):
key, value = self.entity.pkey, self.entity.value
- session = self.cw_req
+ session = self._cw
try:
value = session.vreg.typed_value(key, value)
except UnknownProperty:
@@ -168,7 +168,7 @@
'value' in entity.edited_attributes):
return
key, value = entity.pkey, entity.value
- session = self.cw_req
+ session = self._cw
try:
value = session.vreg.typed_value(key, value)
except UnknownProperty:
@@ -191,7 +191,7 @@
def __call__(self):
eid = self.entity.eid
- session = self.cw_req
+ session = self._cw
for eidfrom, rtype, eidto in session.transaction_data.get('pendingrelations', ()):
if rtype == 'for_user' and eidfrom == self.entity.eid:
# if for_user was set, delete has already been handled
@@ -206,7 +206,7 @@
events = ('after_add_relation',)
def __call__(self):
- session = self.cw_req
+ session = self._cw
eidfrom = self.eidfrom
if not session.describe(eidfrom)[0] == 'CWProperty':
return
@@ -225,7 +225,7 @@
events = ('after_delete_relation',)
def __call__(self):
- session = self.cw_req
+ session = self._cw
key = session.execute('Any K WHERE P eid %(x)s, P pkey K',
{'x': self.eidfrom}, 'x')[0][0]
session.transaction_data.setdefault('pendingrelations', []).append(
--- a/hooks/workflow.py Fri Aug 14 14:23:21 2009 +0200
+++ b/hooks/workflow.py Fri Aug 14 14:31:25 2009 +0200
@@ -65,7 +65,7 @@
events = ('after_add_entity',)
def __call__(self):
- _SetInitialStateOp(self.cw_req, entity=self.entity)
+ _SetInitialStateOp(self._cw, entity=self.entity)
class PrepareStateChangeHook(WorkflowHook):
@@ -75,7 +75,7 @@
events = ('before_delete_relation',)
def __call__(self):
- self.cw_req.transaction_data.setdefault('pendingrelations', []).append(
+ self._cw.transaction_data.setdefault('pendingrelations', []).append(
(self.eidfrom, self.rtype, self.eidto))
@@ -85,7 +85,7 @@
events = ('before_add_relation',)
def __call__(self):
- session = self.cw_req
+ session = self._cw
eidfrom = self.eidfrom
eidto = self.eidto
state = previous_state(session, eidfrom)
@@ -134,10 +134,10 @@
events = ('after_add_relation',)
def __call__(self):
- if self.cw_req.added_in_transaction(self.eidfrom):
+ if self._cw.added_in_transaction(self.eidfrom):
# new entity, not needed
return
- entity = self.cw_req.entity_from_eid(self.eidfrom)
+ entity = self._cw.entity_from_eid(self.eidfrom)
try:
entity.set_attributes(modification_date=datetime.now())
except RepositoryError, ex:
--- a/server/hook.py Fri Aug 14 14:23:21 2009 +0200
+++ b/server/hook.py Fri Aug 14 14:31:25 2009 +0200
@@ -20,10 +20,10 @@
after_delete_relation) all have `eidfrom`, `rtype`, `eidto` attributes.
Server start/stop hooks (eg server_startup, server_shutdown) have a `repo`
-attribute, but *their `cw_req` attribute is None*.
+attribute, but *their `_cw` attribute is None*.
Backup/restore hooks (eg server_backup, server_restore) have a `repo` and a
-`timestamp` attributes, but *their `cw_req` attribute is None*.
+`timestamp` attributes, but *their `_cw` attribute is None*.
Session hooks (eg session_open, session_close) have no special attribute.
@@ -72,10 +72,11 @@
def call_hooks(self, event, req=None, **kwargs):
kwargs['event'] = event
- # XXX remove .enabled
- for hook in sorted([x for x in self.possible_objects(req, **kwargs)
- if x.enabled], key=lambda x: x.order):
- hook()
+ for hook in sorted(self.possible_objects(req, **kwargs), key=lambda x: x.order):
+ if hook.enabled:
+ hook()
+ else:
+ warn('[3.5] %s: enabled is deprecated' % cls)
VRegistry.REGISTRY_FACTORY['hooks'] = HooksRegistry
@@ -165,15 +166,15 @@
if hasattr(self, 'call'):
warn('[3.5] %s: call is deprecated, implements __call__' % self.__class__)
if self.event.endswith('_relation'):
- self.call(self.cw_req, self.eidfrom, self.rtype, self.eidto)
+ self.call(self._cw, self.eidfrom, self.rtype, self.eidto)
elif 'delete' in self.event:
- self.call(self.cw_req, self.entity.eid)
+ self.call(self._cw, self.entity.eid)
elif self.event.startswith('server_'):
self.call(self.repo)
elif self.event.startswith('session_'):
- self.call(self.cw_req)
+ self.call(self._cw)
else:
- self.call(self.cw_req, self.entity)
+ self.call(self._cw, self.entity)
set_log_methods(Hook, getLogger('cubicweb.hook'))
--- a/server/repository.py Fri Aug 14 14:23:21 2009 +0200
+++ b/server/repository.py Fri Aug 14 14:31:25 2009 +0200
@@ -527,7 +527,7 @@
finally:
session.close()
session = Session(user, self, cnxprops)
- user.cw_req = user.rset.req = session
+ user._cw = user.rset.req = session
user.clear_related_cache()
self._sessions[session.id] = session
self.info('opened %s', session)