Commit db03998c authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

[bfss] make it works when adding/updating entities with an attribute using bfss

parent 6bf1e46be6ae
"""custom storages for the system source""" """custom storages for the system source"""
from os import unlink, path as osp from os import unlink, path as osp
from cubicweb import Binary
from cubicweb.server.hook import Operation from cubicweb.server.hook import Operation
...@@ -77,16 +78,19 @@ class BytesFileSystemStorage(Storage): ...@@ -77,16 +78,19 @@ class BytesFileSystemStorage(Storage):
DeleteFileOp(entity._cw, filepath=self.current_fs_path(entity, attr)) DeleteFileOp(entity._cw, filepath=self.current_fs_path(entity, attr))
def new_fs_path(self, entity, attr): def new_fs_path(self, entity, attr):
fpath = osp.join(self.default_directory, '%s_%s_%s' % ( fspath = osp.join(self.default_directory, '%s_%s' % (entity.eid, attr))
self.default_directory, entity.eid, attr))
while osp.exists(fspath): while osp.exists(fspath):
fspath = '_' + fspath fspath = '_' + fspath
return fspath return fspath
def current_fs_path(self, entity, attr): def current_fs_path(self, entity, attr):
cu = entity._cw.system_sql('SELECT cw_%s.%s WHERE cw_eid=%s' % sysource = entity._cw.pool.source('system')
(entity.__regid__, attr, entity.eid)) cu = sysource.doexec(entity._cw,
return cu.fetchone()[0] 'SELECT cw_%s FROM cw_%s WHERE cw_eid=%s' % (
attr, entity.__regid__, entity.eid))
dbmod = sysource.dbapi_module
return dbmod.process_value(cu.fetchone()[0], [None, dbmod.BINARY],
binarywrap=str)
class AddFileOp(Operation): class AddFileOp(Operation):
...@@ -107,5 +111,5 @@ class UpdateFileOp(Operation): ...@@ -107,5 +111,5 @@ class UpdateFileOp(Operation):
def precommit_event(self): def precommit_event(self):
try: try:
file(self.filepath, 'w').write(self.filedata) file(self.filepath, 'w').write(self.filedata)
except: except Exception, ex:
pass self.exception(str(ex))
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