# HG changeset patch # User Sylvain Thénault # Date 1264497757 -3600 # Node ID 48dadeeacfa517cc57ce246391d8a00ad952256b # Parent 6bf1e46be6ae26449eb878fd18fca207a5ce5ad3 [bfss] make it works when adding/updating entities with an attribute using bfss diff -r 6bf1e46be6ae -r 48dadeeacfa5 server/sources/storages.py --- a/server/sources/storages.py Mon Jan 25 21:17:44 2010 +0100 +++ b/server/sources/storages.py Tue Jan 26 10:22:37 2010 +0100 @@ -1,6 +1,7 @@ """custom storages for the system source""" from os import unlink, path as osp +from cubicweb import Binary from cubicweb.server.hook import Operation @@ -77,16 +78,19 @@ DeleteFileOp(entity._cw, filepath=self.current_fs_path(entity, attr)) def new_fs_path(self, entity, attr): - fpath = osp.join(self.default_directory, '%s_%s_%s' % ( - self.default_directory, entity.eid, attr)) + fspath = osp.join(self.default_directory, '%s_%s' % (entity.eid, attr)) while osp.exists(fspath): fspath = '_' + fspath return fspath def current_fs_path(self, entity, attr): - cu = entity._cw.system_sql('SELECT cw_%s.%s WHERE cw_eid=%s' % - (entity.__regid__, attr, entity.eid)) - return cu.fetchone()[0] + sysource = entity._cw.pool.source('system') + cu = sysource.doexec(entity._cw, + '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): @@ -107,5 +111,5 @@ def precommit_event(self): try: file(self.filepath, 'w').write(self.filedata) - except: - pass + except Exception, ex: + self.exception(str(ex))