cubicweb/server/sources/storages.py
changeset 11273 c655e19cbc35
parent 11057 0b59724cb3f2
child 12567 26744ad37953
equal deleted inserted replaced
11272:53fbd5644bff 11273:c655e19cbc35
   155         if entity._cw.transaction_data.get('fs_importing'):
   155         if entity._cw.transaction_data.get('fs_importing'):
   156             binary = Binary.from_file(entity.cw_edited[attr].getvalue())
   156             binary = Binary.from_file(entity.cw_edited[attr].getvalue())
   157             entity._cw_dont_cache_attribute(attr, repo_side=True)
   157             entity._cw_dont_cache_attribute(attr, repo_side=True)
   158         else:
   158         else:
   159             binary = entity.cw_edited.pop(attr)
   159             binary = entity.cw_edited.pop(attr)
   160             fd, fpath = self.new_fs_path(entity, attr)
   160             if binary is not None:
   161             # bytes storage used to store file's path
   161                 fd, fpath = self.new_fs_path(entity, attr)
   162             binary_obj = Binary(fpath if PY2 else fpath.encode('utf-8'))
   162                 # bytes storage used to store file's path
   163             entity.cw_edited.edited_attribute(attr, binary_obj)
   163                 binary_obj = Binary(fpath if PY2 else fpath.encode('utf-8'))
   164             self._writecontent(fd, binary)
   164                 entity.cw_edited.edited_attribute(attr, binary_obj)
   165             AddFileOp.get_instance(entity._cw).add_data(fpath)
   165                 self._writecontent(fd, binary)
       
   166                 AddFileOp.get_instance(entity._cw).add_data(fpath)
   166         return binary
   167         return binary
   167 
   168 
   168     def entity_updated(self, entity, attr):
   169     def entity_updated(self, entity, attr):
   169         """an entity using this storage for attr has been updated"""
   170         """an entity using this storage for attr has been updated"""
   170         # get the name of the previous file containing the value
   171         # get the name of the previous file containing the value
   257         return fspath
   258         return fspath
   258 
   259 
   259     def migrate_entity(self, entity, attribute):
   260     def migrate_entity(self, entity, attribute):
   260         """migrate an entity attribute to the storage"""
   261         """migrate an entity attribute to the storage"""
   261         entity.cw_edited = EditedEntity(entity, **entity.cw_attr_cache)
   262         entity.cw_edited = EditedEntity(entity, **entity.cw_attr_cache)
   262         self.entity_added(entity, attribute)
   263         binary = self.entity_added(entity, attribute)
   263         cnx = entity._cw
   264         if binary is not None:
   264         source = cnx.repo.system_source
   265             cnx = entity._cw
   265         attrs = source.preprocess_entity(entity)
   266             source = cnx.repo.system_source
   266         sql = source.sqlgen.update('cw_' + entity.cw_etype, attrs,
   267             attrs = source.preprocess_entity(entity)
   267                                    ['cw_eid'])
   268             sql = source.sqlgen.update('cw_' + entity.cw_etype, attrs,
   268         source.doexec(cnx, sql, attrs)
   269                                        ['cw_eid'])
       
   270             source.doexec(cnx, sql, attrs)
   269         entity.cw_edited = None
   271         entity.cw_edited = None
   270 
   272 
   271 
   273 
   272 class AddFileOp(hook.DataOperationMixIn, hook.Operation):
   274 class AddFileOp(hook.DataOperationMixIn, hook.Operation):
   273     def rollback_event(self):
   275     def rollback_event(self):