[cwvreg] inline function dump_class()
Grepping the entire code base (cubicweb+all the known cubes) shows that
inlining this function is harmless: no one is using it.
# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr## This file is part of CubicWeb.## CubicWeb is free software: you can redistribute it and/or modify it under the# terms of the GNU Lesser General Public License as published by the Free# Software Foundation, either version 2.1 of the License, or (at your option)# any later version.## CubicWeb is distributed in the hope that it will be useful, but WITHOUT# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more# details.## You should have received a copy of the GNU Lesser General Public License along# with CubicWeb. If not, see <http://www.gnu.org/licenses/>."""Core hooks: set generic metadata"""__docformat__="restructuredtext en"fromdatetimeimportdatetimefromcubicweb.selectorsimportis_instancefromcubicweb.serverimporthookfromcubicweb.server.editionimportEditedEntityclassMetaDataHook(hook.Hook):__abstract__=Truecategory='metadata'classInitMetaAttrsHook(MetaDataHook):"""before create a new entity -> set creation and modification date this is a conveniency hook, you shouldn't have to disable it """__regid__='metaattrsinit'events=('before_add_entity',)def__call__(self):timestamp=datetime.now()edited=self.entity.cw_editededited.setdefault('creation_date',timestamp)edited.setdefault('modification_date',timestamp)ifnotself._cw.get_shared_data('do-not-insert-cwuri'):cwuri=u'%s%s'%(self._cw.base_url(),self.entity.eid)edited.setdefault('cwuri',cwuri)classUpdateMetaAttrsHook(MetaDataHook):"""update an entity -> set modification date"""__regid__='metaattrsupdate'events=('before_update_entity',)def__call__(self):# repairing is true during c-c upgrade/shell and similar commands. We# usually don't want to update modification date in such cases.## XXX to be really clean, we should turn off modification_date update# explicitly on each command where we do not want that behaviour.ifnotself._cw.vreg.config.repairing:self.entity.cw_edited.setdefault('modification_date',datetime.now())classSetCreatorOp(hook.DataOperationMixIn,hook.Operation):defprecommit_event(self):session=self.sessionrelations=[(eid,session.user.eid)foreidinself.get_data()# don't consider entities that have been created and deleted in# the same transaction, nor ones where created_by has been# explicitly setifnotsession.deleted_in_transaction(eid)and \notsession.entity_from_eid(eid).created_by]session.add_relations([('created_by',relations)])classSetOwnershipHook(MetaDataHook):"""create a new entity -> set owner and creator metadata"""__regid__='setowner'events=('after_add_entity',)def__call__(self):ifnotself._cw.is_internal_session:self._cw.add_relation(self.entity.eid,'owned_by',self._cw.user.eid)SetCreatorOp.get_instance(self._cw).add_data(self.entity.eid)classSyncOwnersOp(hook.DataOperationMixIn,hook.Operation):defprecommit_event(self):forcompositeeid,composedeidinself.get_data():self.session.execute('SET X owned_by U WHERE C owned_by U, C eid %(c)s,''NOT EXISTS(X owned_by U, X eid %(x)s)',{'c':compositeeid,'x':composedeid})classSyncCompositeOwner(MetaDataHook):"""when adding composite relation, the composed should have the same owners has the composite """__regid__='synccompositeowner'events=('after_add_relation',)def__call__(self):ifself.rtype=='wf_info_for':# skip this special composite relation # XXX (syt) why?returneidfrom,eidto=self.eidfrom,self.eidtocomposite=self._cw.schema_rproperty(self.rtype,eidfrom,eidto,'composite')ifcomposite=='subject':SyncOwnersOp.get_instance(self._cw).add_data((eidfrom,eidto))elifcomposite=='object':SyncOwnersOp.get_instance(self._cw).add_data((eidto,eidfrom))classFixUserOwnershipHook(MetaDataHook):"""when a user has been created, add owned_by relation on itself"""__regid__='fixuserowner'__select__=MetaDataHook.__select__&is_instance('CWUser')events=('after_add_entity',)def__call__(self):self._cw.add_relation(self.entity.eid,'owned_by',self.entity.eid)classUpdateFTIHook(MetaDataHook):"""sync fulltext index text index container when a relation with fulltext_container set is added / removed """__regid__='updateftirel'events=('after_add_relation','after_delete_relation')def__call__(self):rtype=self.rtypesession=self._cwftcontainer=session.vreg.schema.rschema(rtype).fulltext_containerifftcontainer=='subject':session.repo.system_source.index_entity(session,session.entity_from_eid(self.eidfrom))elifftcontainer=='object':session.repo.system_source.index_entity(session,session.entity_from_eid(self.eidto))# entity source handling #######################################################classChangeEntityUpdateCaches(hook.Operation):defpostcommit_event(self):self.oldsource.reset_caches()repo=self.session.repoentity=self.entityextid=entity.cw_metainformation()['extid']repo._type_source_cache[entity.eid]=(entity.__regid__,self.newsource.uri,None)ifself.oldsource.copy_based_source:uri='system'else:uri=self.oldsource.urirepo._extid_cache[(extid,uri)]=-entity.eidclassChangeEntitySourceDeleteHook(MetaDataHook):"""support for moving an entity from an external source by watching 'Any cw_source CWSource' relation """__regid__='cw.metadata.source-change'__select__=MetaDataHook.__select__&hook.match_rtype('cw_source')events=('before_delete_relation',)def__call__(self):if(self._cw.deleted_in_transaction(self.eidfrom)orself._cw.deleted_in_transaction(self.eidto)):returnschange=self._cw.transaction_data.setdefault('cw_source_change',{})schange[self.eidfrom]=self.eidtoclassChangeEntitySourceAddHook(MetaDataHook):__regid__='cw.metadata.source-change'__select__=MetaDataHook.__select__&hook.match_rtype('cw_source')events=('before_add_relation',)def__call__(self):schange=self._cw.transaction_data.get('cw_source_change')ifschangeisnotNoneandself.eidfrominschange:newsource=self._cw.entity_from_eid(self.eidto)ifnewsource.name!='system':raiseException('changing source to something else than the ''system source is unsupported')syssource=newsource.repo_sourceoldsource=self._cw.entity_from_eid(schange[self.eidfrom])entity=self._cw.entity_from_eid(self.eidfrom)# copy entity if necessaryifnotoldsource.repo_source.copy_based_source:entity.complete(skip_bytes=False)entity.cw_edited=EditedEntity(entity,**entity.cw_attr_cache)syssource.add_entity(self._cw,entity)# we don't want the moved entity to be reimported later. To# distinguish this state, the trick is to change the associated# record in the 'entities' system table with eid=-eid while leaving# other fields unchanged, and to add a new record with eid=eid,# source='system'. External source will then have consider case# where `extid2eid` return a negative eid as 'this entity was known# but has been moved, ignore it'.self._cw.system_sql('UPDATE entities SET eid=-eid,source=%(source)s WHERE eid=%(eid)s',{'eid':self.eidfrom,'source':newsource.name})attrs={'type':entity.__regid__,'eid':entity.eid,'extid':None,'source':'system','mtime':datetime.now()}self._cw.system_sql(syssource.sqlgen.insert('entities',attrs),attrs)# register an operation to update repository/sources cachesChangeEntityUpdateCaches(self._cw,entity=entity,oldsource=oldsource.repo_source,newsource=syssource)