hooks/metadata.py
branchstable
changeset 7683 a21e24831ae4
parent 7543 570522300e22
child 7708 45be3a9debe6
equal deleted inserted replaced
7682:07b592a62be3 7683:a21e24831ae4
   194             oldsource = self._cw.entity_from_eid(schange[self.eidfrom])
   194             oldsource = self._cw.entity_from_eid(schange[self.eidfrom])
   195             entity = self._cw.entity_from_eid(self.eidfrom)
   195             entity = self._cw.entity_from_eid(self.eidfrom)
   196             # copy entity if necessary
   196             # copy entity if necessary
   197             if not oldsource.repo_source.copy_based_source:
   197             if not oldsource.repo_source.copy_based_source:
   198                 entity.complete(skip_bytes=False)
   198                 entity.complete(skip_bytes=False)
       
   199                 if not entity.creation_date:
       
   200                     entity.cw_attr_cache['creation_date'] = datetime.now()
       
   201                 if not entity.modification_date:
       
   202                     entity.cw_attr_cache['modification_date'] = datetime.now()
       
   203                 entity.cw_attr_cache['cwuri'] = u'%s%s' % (self._cw.base_url(), entity.eid)
       
   204                 for rschema, attrschema in entity.e_schema.attribute_definitions():
       
   205                     if attrschema == 'Password' and \
       
   206                        rschema.rdef(entity.e_schema, attrschema).cardinality[0] == '1':
       
   207                         from logilab.common.shellutils import generate_password
       
   208                         entity.cw_attr_cache[rschema.type] = generate_password()
   199                 entity.cw_edited = EditedEntity(entity, **entity.cw_attr_cache)
   209                 entity.cw_edited = EditedEntity(entity, **entity.cw_attr_cache)
   200                 syssource.add_entity(self._cw, entity)
   210                 syssource.add_entity(self._cw, entity)
   201             # we don't want the moved entity to be reimported later.  To
   211             # we don't want the moved entity to be reimported later.  To
   202             # distinguish this state, the trick is to change the associated
   212             # distinguish this state, the trick is to change the associated
   203             # record in the 'entities' system table with eid=-eid while leaving
   213             # record in the 'entities' system table with eid=-eid while leaving
   204             # other fields unchanged, and to add a new record with eid=eid,
   214             # other fields unchanged, and to add a new record with eid=eid,
   205             # source='system'. External source will then have consider case
   215             # source='system'. External source will then have consider case
   206             # where `extid2eid` return a negative eid as 'this entity was known
   216             # where `extid2eid` return a negative eid as 'this entity was known
   207             # but has been moved, ignore it'.
   217             # but has been moved, ignore it'.
   208             self._cw.system_sql('UPDATE entities SET eid=-eid,source=%(source)s '
   218             self._cw.system_sql('UPDATE entities SET eid=-eid WHERE eid=%(eid)s',
   209                                 'WHERE eid=%(eid)s',
   219                                 {'eid': self.eidfrom})
   210                                 {'eid': self.eidfrom, 'source': newsource.name})
       
   211             attrs = {'type': entity.__regid__, 'eid': entity.eid, 'extid': None,
   220             attrs = {'type': entity.__regid__, 'eid': entity.eid, 'extid': None,
   212                      'source': 'system', 'asource': 'system',
   221                      'source': 'system', 'asource': 'system',
   213                      'mtime': datetime.now()}
   222                      'mtime': datetime.now()}
   214             self._cw.system_sql(syssource.sqlgen.insert('entities', attrs), attrs)
   223             self._cw.system_sql(syssource.sqlgen.insert('entities', attrs), attrs)
   215             # register an operation to update repository/sources caches
   224             # register an operation to update repository/sources caches