remove more cruft

bzr revid: al@openerp.com-20121216204737-4mfsbp0v6s0g799j
This commit is contained in:
Antony Lesuisse 2012-12-16 21:47:37 +01:00
parent c90a1492d6
commit 893f34555f
2 changed files with 2 additions and 87 deletions

View File

@ -55,7 +55,7 @@ ATTENTION:
'report/document_report_view.xml',
'board_document_view.xml',
],
'demo': [ 'document_demo.xml','board_document_demo.xml'],
'demo': [ 'document_demo.xml' ],
'test': ['test/document_test2.yml'],
'js': ['static/src/js/document.js'],
'installable': True,

View File

@ -62,9 +62,7 @@ class document_file(osv.osv):
if ids is not None:
raise NotImplementedError("Ids are just there by convention, please do not use it.")
cr.execute("UPDATE ir_attachment " \
"SET parent_id = %s, db_datas = decode(encode(db_datas,'escape'), 'base64') " \
"WHERE parent_id IS NULL", (parent_id,))
cr.execute("UPDATE ir_attachment SET parent_id = %s WHERE parent_id IS NULL", (parent_id,))
cr.execute("UPDATE ir_attachment SET file_size=length(db_datas) WHERE file_size = 0 and type = 'binary'")
@ -72,67 +70,17 @@ class document_file(osv.osv):
return True
def _get_filestore(self, cr):
return os.path.join(DMS_ROOT_PATH, cr.dbname)
def _data_get(self, cr, uid, ids, name, arg, context=None):
if context is None:
context = {}
fbrl = self.browse(cr, uid, ids, context=context)
nctx = nodes.get_node_context(cr, uid, context={})
# nctx will /not/ inherit the caller's context. Most of
# it would be useless, anyway (like active_id, active_model,
# bin_size etc.)
result = {}
bin_size = context.get('bin_size', False)
for fbro in fbrl:
fnode = nodes.node_file(None, None, nctx, fbro)
if not bin_size:
data = fnode.get_data(cr, fbro)
result[fbro.id] = base64.encodestring(data or '')
else:
result[fbro.id] = fnode.get_data_len(cr, fbro)
return result
#
# This code can be improved
#
def _data_set(self, cr, uid, id, name, value, arg, context=None):
if not value:
return True
fbro = self.browse(cr, uid, id, context=context)
nctx = nodes.get_node_context(cr, uid, context={})
fnode = nodes.node_file(None, None, nctx, fbro)
res = fnode.set_data(cr, base64.decodestring(value), fbro)
return res
_columns = {
# Columns from ir.attachment:
'create_date': fields.datetime('Date Created', readonly=True),
'create_uid': fields.many2one('res.users', 'Creator', readonly=True),
'write_date': fields.datetime('Date Modified', readonly=True),
'write_uid': fields.many2one('res.users', 'Last Modification User', readonly=True),
'res_model': fields.char('Attached Model', size=64, readonly=True, change_default=True),
'res_id': fields.integer('Attached ID', readonly=True),
# If ir.attachment contained any data before document is installed, preserve
# the data, don't drop the column!
'db_datas': fields.binary('Data', oldname='datas'),
'datas': fields.function(_data_get, fnct_inv=_data_set, string='File Content', type="binary", nodrop=True),
# Fields of document:
'user_id': fields.many2one('res.users', 'Owner', select=1),
# 'group_ids': fields.many2many('res.groups', 'document_group_rel', 'item_id', 'group_id', 'Groups'),
# the directory id now is mandatory. It can still be computed automatically.
'parent_id': fields.many2one('document.directory', 'Directory', select=1, required=True, change_default=True),
'index_content': fields.text('Indexed Content'),
'partner_id':fields.many2one('res.partner', 'Partner', select=1),
'file_size': fields.integer('File Size', required=True),
'file_type': fields.char('Content Type', size=128),
# fields used for file storage
'store_fname': fields.char('Stored Filename', size=200),
}
_order = "id desc"
@ -185,7 +133,6 @@ class document_file(osv.osv):
ids.remove(doc_id)
return len(ids) if count else ids
def copy(self, cr, uid, id, default=None, context=None):
if not default:
default = {}
@ -282,36 +229,4 @@ class document_file(osv.osv):
return bro.partner_id.id
return False
def unlink(self, cr, uid, ids, context=None):
stor = self.pool.get('document.storage')
unres = []
# We have to do the unlink in 2 stages: prepare a list of actual
# files to be unlinked, update the db (safer to do first, can be
# rolled back) and then unlink the files. The list wouldn't exist
# after we discard the objects
ids = self.search(cr, uid, [('id','in',ids)])
for f in self.browse(cr, uid, ids, context=context):
# TODO: update the node cache
par = f.parent_id
storage_id = None
while par:
if par.storage_id:
storage_id = par.storage_id
break
par = par.parent_id
#assert storage_id, "Strange, found file #%s w/o storage!" % f.id #TOCHECK: after run yml, it's fail
if storage_id:
r = stor.prepare_unlink(cr, uid, storage_id, f)
if r:
unres.append(r)
else:
self.loggerdoc.warning("Unlinking attachment #%s %s that has no storage.",
f.id, f.name)
res = super(document_file, self).unlink(cr, uid, ids, context)
stor.do_unlink(cr, uid, unres)
return res
document_file()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: