[REF] netsvc: object_proxy is no longer in netsvc.

bzr revid: vmt@openerp.com-20110729083824-onx5kklbgzb9pok2
This commit is contained in:
Vo Minh Thu 2011-07-29 10:38:24 +02:00
parent 64490ad5ac
commit c4d7dde645
5 changed files with 38 additions and 29 deletions

View File

@ -60,6 +60,12 @@ def close_socket(sock):
#.apidoc title: Common Services: netsvc
#.apidoc module-mods: member-order: bysource
def abort_response(error, description, origin, details):
if not tools.config['debug_mode']:
raise Exception("%s -- %s\n\n%s"%(origin, description, details))
else:
raise
class Service(object):
""" Base class for *Local* services
@ -86,6 +92,11 @@ class Service(object):
raise
def LocalService(name):
# Special case for addons support, will be removed in a few days when addons
# are updated to directly use openerp.osv.osv.service.
if name == 'object_proxy':
return openerp.osv.osv.service
return Service._services[name]
class ExportService(object):

View File

@ -39,11 +39,13 @@ class except_osv(Exception):
self.value = value
self.args = (exc_type, name)
service = None
class object_proxy(netsvc.Service):
class object_proxy():
def __init__(self):
self.logger = logging.getLogger('web-services')
netsvc.Service.__init__(self, 'object_proxy')
global service
service = self
def check(f):
@wraps(f)
@ -117,14 +119,14 @@ class object_proxy(netsvc.Service):
except orm.except_orm, inst:
if inst.name == 'AccessError':
self.logger.debug("AccessError", exc_info=True)
self.abortResponse(1, inst.name, 'warning', inst.value)
netsvc.abort_response(1, inst.name, 'warning', inst.value)
except except_osv, inst:
self.abortResponse(1, inst.name, inst.exc_type, inst.value)
netsvc.abort_response(1, inst.name, inst.exc_type, inst.value)
except IntegrityError, inst:
osv_pool = pooler.get_pool(dbname)
for key in osv_pool._sql_error.keys():
if key in inst[0]:
self.abortResponse(1, _('Constraint Error'), 'warning',
netsvc.abort_response(1, _('Constraint Error'), 'warning',
tr(osv_pool._sql_error[key], 'sql_constraint') or inst[0])
if inst.pgcode in (errorcodes.NOT_NULL_VIOLATION, errorcodes.FOREIGN_KEY_VIOLATION, errorcodes.RESTRICT_VIOLATION):
msg = _('The operation cannot be completed, probably due to the following:\n- deletion: you may be trying to delete a record while other records still reference it\n- creation/update: a mandatory field is not correctly set')
@ -145,9 +147,9 @@ class object_proxy(netsvc.Service):
msg += _('\n\n[object with reference: %s - %s]') % (model_name, model)
except Exception:
pass
self.abortResponse(1, _('Integrity Error'), 'warning', msg)
netsvc.abort_response(1, _('Integrity Error'), 'warning', msg)
else:
self.abortResponse(1, _('Integrity Error'), 'warning', inst[0])
netsvc.abort_response(1, _('Integrity Error'), 'warning', inst[0])
except Exception:
self.logger.exception("Uncaught exception")
raise

View File

@ -136,16 +136,15 @@ class report_custom(report_int):
ids = self.pool.get(report.model_id.model).search(cr, uid, [])
datas['ids'] = ids
service = netsvc.LocalService("object_proxy")
report_id = datas['report_id']
report = service.execute(cr.dbname, uid, 'ir.report.custom', 'read', [report_id], context=context)[0]
fields = service.execute(cr.dbname, uid, 'ir.report.custom.fields', 'read', report['fields_child0'], context=context)
report = self.pool.get('ir.report.custom').read(cr, uid, [report_id], context=context)[0]
fields = self.pool.get('ir.report.custom.fields').read(cr, uid, report['fields_child0'], context=context)
fields.sort(lambda x,y : x['sequence'] - y['sequence'])
if report['field_parent']:
parent_field = service.execute(cr.dbname, uid, 'ir.model.fields', 'read', [report['field_parent'][0]],['model'])
model_name = service.execute(cr.dbname, uid, 'ir.model', 'read', [report['model_id'][0]], ['model'],context=context)[0]['model']
parent_field = self.pool.get('ir.model.fields').read(cr, uid, [report['field_parent'][0]], ['model'])
model_name = self.pool.get('ir.model').read(cr, uid, [report['model_id'][0]], ['model'], context=context)[0]['model']
fct = {}
fct['id'] = lambda x : x
@ -160,9 +159,7 @@ class report_custom(report_int):
field_child = f['field_child'+str(i)]
if field_child:
row.append(
service.execute(cr.dbname, uid,
'ir.model.fields', 'read', [field_child[0]],
['name'], context=context)[0]['name']
self.pool.get('ir.model.fields').read(cr, uid, [field_child[0]], ['name'], context=context)[0]['name']
)
if f['fc'+str(i)+'_operande']:
fct_name = 'id'
@ -346,7 +343,7 @@ class report_custom(report_int):
def _create_lines(self, cr, uid, ids, report, fields, results, context):
service = netsvc.LocalService("object_proxy")
pool = pooler.get_pool(cr.dbname)
pdf_string = cStringIO.StringIO()
can = canvas.init(fname=pdf_string, format='pdf')
@ -376,7 +373,7 @@ class report_custom(report_int):
for f in fields:
field_id = (f['field_child3'] and f['field_child3'][0]) or (f['field_child2'] and f['field_child2'][0]) or (f['field_child1'] and f['field_child1'][0]) or (f['field_child0'] and f['field_child0'][0])
if field_id:
type = service.execute(cr.dbname, uid, 'ir.model.fields', 'read', [field_id],['ttype'])
type = pool.get('ir.model.fields').read(cr, uid, [field_id],['ttype'])
if type[0]['ttype'] == 'date':
date_idx = idx
fct[idx] = process_date[report['frequency']]
@ -449,7 +446,7 @@ class report_custom(report_int):
def _create_bars(self, cr, uid, ids, report, fields, results, context):
service = netsvc.LocalService("object_proxy")
pool = pooler.get_pool(cr.dbname)
pdf_string = cStringIO.StringIO()
can = canvas.init(fname=pdf_string, format='pdf')
@ -475,7 +472,7 @@ class report_custom(report_int):
for f in fields:
field_id = (f['field_child3'] and f['field_child3'][0]) or (f['field_child2'] and f['field_child2'][0]) or (f['field_child1'] and f['field_child1'][0]) or (f['field_child0'] and f['field_child0'][0])
if field_id:
type = service.execute(cr.dbname, uid, 'ir.model.fields', 'read', [field_id],['ttype'])
type = pool.get('ir.model.fields').read(cr, uid, [field_id],['ttype'])
if type[0]['ttype'] == 'date':
date_idx = idx
fct[idx] = process_date[report['frequency']]

View File

@ -137,9 +137,8 @@ class document(object):
value = self.get_value(browser, attrs['name'])
service = netsvc.LocalService("object_proxy")
ids = service.execute(self.cr.dbname, self.uid, 'ir.attachment', 'search', [('res_model','=',model),('res_id','=',int(value))])
datas = service.execute(self.cr.dbname, self.uid, 'ir.attachment', 'read', ids)
ids = self.pool.get('ir.attachment').search(self.cr, self.uid, [('res_model','=',model),('res_id','=',int(value))])
datas = self.pool.get('ir.attachment').read(self.cr, self.uid, ids)
if len(datas):
# if there are several, pick first

View File

@ -344,9 +344,9 @@ class db(netsvc.ExportService):
tools.config['update']['base'] = True
pooler.restart_pool(db, force_demo=False, update_module=True)
except except_orm, inst:
self.abortResponse(1, inst.name, 'warning', inst.value)
netsvc.abort_response(1, inst.name, 'warning', inst.value)
except except_osv, inst:
self.abortResponse(1, inst.name, inst.exc_type, inst.value)
netsvc.abort_response(1, inst.name, inst.exc_type, inst.value)
except Exception:
import traceback
tb_s = reduce(lambda x, y: x+y, traceback.format_exception( sys.exc_type, sys.exc_value, sys.exc_traceback))
@ -419,7 +419,7 @@ GNU Public Licence.
return rc.get_available_updates(rc.id, openerp.modules.get_modules_with_version())
except tm.RemoteContractException, e:
self.abortResponse(1, 'Migration Error', 'warning', str(e))
netsvc.abort_response(1, 'Migration Error', 'warning', str(e))
def exp_get_migration_scripts(self, contract_id, contract_password):
@ -487,7 +487,7 @@ GNU Public Licence.
return True
except tm.RemoteContractException, e:
self.abortResponse(1, 'Migration Error', 'warning', str(e))
netsvc.abort_response(1, 'Migration Error', 'warning', str(e))
except Exception, e:
import traceback
tb_s = reduce(lambda x, y: x+y, traceback.format_exception( sys.exc_type, sys.exc_value, sys.exc_traceback))
@ -560,8 +560,8 @@ class objects_proxy(netsvc.ExportService):
if method not in ['execute','exec_workflow']:
raise NameError("Method not available %s" % method)
security.check(db,uid,passwd)
ls = netsvc.LocalService('object_proxy')
fn = getattr(ls, method)
assert openerp.osv.osv.service, "The object_proxy class must be started with start_object_proxy."
fn = getattr(openerp.osv.osv.service, method)
res = fn(db, uid, *params)
return res
@ -701,7 +701,7 @@ class report_spool(netsvc.ExportService):
result = self._reports[report_id]
exc = result['exception']
if exc:
self.abortResponse(exc, exc.message, 'warning', exc.traceback)
netsvc.abort_response(exc, exc.message, 'warning', exc.traceback)
res = {'state': result['state']}
if res['state']:
if tools.config['reportgz']: