parent
4c2a727132
commit
cc5a062faf
|
@ -42,14 +42,17 @@ _group={}
|
||||||
_res_id = 1
|
_res_id = 1
|
||||||
_res = {}
|
_res = {}
|
||||||
|
|
||||||
|
|
||||||
class ServiceEndPointCall(object):
|
class ServiceEndPointCall(object):
|
||||||
def __init__(self, id, method):
|
def __init__(self, id, method):
|
||||||
self._id = id
|
self._id = id
|
||||||
self._meth = method
|
self._meth = method
|
||||||
|
|
||||||
def __call__(self, *args):
|
def __call__(self, *args):
|
||||||
_res[self._id] = self._meth(*args)
|
_res[self._id] = self._meth(*args)
|
||||||
return self._id
|
return self._id
|
||||||
|
|
||||||
|
|
||||||
class ServiceEndPoint(object):
|
class ServiceEndPoint(object):
|
||||||
def __init__(self, name, id):
|
def __init__(self, name, id):
|
||||||
self._id = id
|
self._id = id
|
||||||
|
@ -57,11 +60,14 @@ class ServiceEndPoint(object):
|
||||||
s = _service[name]
|
s = _service[name]
|
||||||
for m in s._method:
|
for m in s._method:
|
||||||
self._meth[m] = s._method[m]
|
self._meth[m] = s._method[m]
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
return ServiceEndPointCall(self._id, self._meth[name])
|
return ServiceEndPointCall(self._id, self._meth[name])
|
||||||
|
|
||||||
|
|
||||||
class Service(object):
|
class Service(object):
|
||||||
_serviceEndPointID = 0
|
_serviceEndPointID = 0
|
||||||
|
|
||||||
def __init__(self, name, audience=''):
|
def __init__(self, name, audience=''):
|
||||||
_service[name] = self
|
_service[name] = self
|
||||||
self.__name = name
|
self.__name = name
|
||||||
|
@ -118,6 +124,7 @@ class Service(object):
|
||||||
def currentFailure(self, s):
|
def currentFailure(self, s):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class LocalService(Service):
|
class LocalService(Service):
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
self.__name = name
|
self.__name = name
|
||||||
|
@ -126,12 +133,15 @@ class LocalService(Service):
|
||||||
for m in s._method:
|
for m in s._method:
|
||||||
setattr(self, m, s._method[m])
|
setattr(self, m, s._method[m])
|
||||||
|
|
||||||
|
|
||||||
class ServiceUnavailable(Exception):
|
class ServiceUnavailable(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def service_exist(name):
|
def service_exist(name):
|
||||||
return (name in _service) and bool(_service[name])
|
return (name in _service) and bool(_service[name])
|
||||||
|
|
||||||
|
|
||||||
def get_rpc_paths():
|
def get_rpc_paths():
|
||||||
return map(lambda s: '/xmlrpc/%s' % s, _service)
|
return map(lambda s: '/xmlrpc/%s' % s, _service)
|
||||||
|
|
||||||
|
@ -141,6 +151,7 @@ LOG_WARNING='warn'
|
||||||
LOG_ERROR = 'error'
|
LOG_ERROR = 'error'
|
||||||
LOG_CRITICAL = 'critical'
|
LOG_CRITICAL = 'critical'
|
||||||
|
|
||||||
|
|
||||||
def init_logger():
|
def init_logger():
|
||||||
from tools import config
|
from tools import config
|
||||||
import os
|
import os
|
||||||
|
@ -179,6 +190,7 @@ class Logger(object):
|
||||||
log = logging.getLogger(name)
|
log = logging.getLogger(name)
|
||||||
getattr(log, level)(msg)
|
getattr(log, level)(msg)
|
||||||
|
|
||||||
|
|
||||||
class Agent(object):
|
class Agent(object):
|
||||||
_timers = []
|
_timers = []
|
||||||
_logger = Logger()
|
_logger = Logger()
|
||||||
|
@ -203,23 +215,29 @@ class Agent(object):
|
||||||
timer.cancel()
|
timer.cancel()
|
||||||
quit = classmethod(quit)
|
quit = classmethod(quit)
|
||||||
|
|
||||||
|
|
||||||
class RpcGateway(object):
|
class RpcGateway(object):
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
|
|
||||||
class Dispatcher(object):
|
class Dispatcher(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def monitor(self, signal):
|
def monitor(self, signal):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class xmlrpc(object):
|
class xmlrpc(object):
|
||||||
class RpcGateway(object):
|
class RpcGateway(object):
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
|
|
||||||
class GenericXMLRPCRequestHandler:
|
class GenericXMLRPCRequestHandler:
|
||||||
def _dispatch(self, method, params):
|
def _dispatch(self, method, params):
|
||||||
import traceback
|
import traceback
|
||||||
|
@ -244,10 +262,12 @@ class GenericXMLRPCRequestHandler:
|
||||||
pdb.post_mortem(tb)
|
pdb.post_mortem(tb)
|
||||||
raise xmlrpclib.Fault(s, tb_s)
|
raise xmlrpclib.Fault(s, tb_s)
|
||||||
|
|
||||||
|
|
||||||
class SimpleXMLRPCRequestHandler(GenericXMLRPCRequestHandler,
|
class SimpleXMLRPCRequestHandler(GenericXMLRPCRequestHandler,
|
||||||
SimpleXMLRPCServer.SimpleXMLRPCRequestHandler):
|
SimpleXMLRPCServer.SimpleXMLRPCRequestHandler):
|
||||||
SimpleXMLRPCServer.SimpleXMLRPCRequestHandler.rpc_paths = get_rpc_paths()
|
SimpleXMLRPCServer.SimpleXMLRPCRequestHandler.rpc_paths = get_rpc_paths()
|
||||||
|
|
||||||
|
|
||||||
class SimpleThreadedXMLRPCServer(SocketServer.ThreadingMixIn,
|
class SimpleThreadedXMLRPCServer(SocketServer.ThreadingMixIn,
|
||||||
SimpleXMLRPCServer.SimpleXMLRPCServer):
|
SimpleXMLRPCServer.SimpleXMLRPCServer):
|
||||||
|
|
||||||
|
@ -256,6 +276,7 @@ class SimpleThreadedXMLRPCServer(SocketServer.ThreadingMixIn,
|
||||||
socket.SO_REUSEADDR, 1)
|
socket.SO_REUSEADDR, 1)
|
||||||
SimpleXMLRPCServer.SimpleXMLRPCServer.server_bind(self)
|
SimpleXMLRPCServer.SimpleXMLRPCServer.server_bind(self)
|
||||||
|
|
||||||
|
|
||||||
class HttpDaemon(threading.Thread):
|
class HttpDaemon(threading.Thread):
|
||||||
|
|
||||||
def __init__(self, interface, port, secure=False):
|
def __init__(self, interface, port, secure=False):
|
||||||
|
@ -287,7 +308,7 @@ class HttpDaemon(threading.Thread):
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.running = False
|
self.running = False
|
||||||
if os.name <> 'nt':
|
if os.name != 'nt':
|
||||||
if hasattr(socket, 'SHUT_RDWR'):
|
if hasattr(socket, 'SHUT_RDWR'):
|
||||||
if self.secure:
|
if self.secure:
|
||||||
self.server.socket.sock_shutdown(socket.SHUT_RDWR)
|
self.server.socket.sock_shutdown(socket.SHUT_RDWR)
|
||||||
|
@ -368,6 +389,7 @@ class TinySocketClientThread(threading.Thread):
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.running = False
|
self.running = False
|
||||||
|
|
||||||
|
|
||||||
class TinySocketServerThread(threading.Thread):
|
class TinySocketServerThread(threading.Thread):
|
||||||
def __init__(self, interface, port, secure=False):
|
def __init__(self, interface, port, secure=False):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
from tools import flatten
|
from tools import flatten
|
||||||
|
|
||||||
|
|
||||||
class expression(object):
|
class expression(object):
|
||||||
"""
|
"""
|
||||||
parse a domain expression
|
parse a domain expression
|
||||||
|
@ -103,7 +104,7 @@ class expression(object):
|
||||||
if isinstance(self.__right, list):
|
if isinstance(self.__right, list):
|
||||||
self.__right = tuple(self.__right)
|
self.__right = tuple(self.__right)
|
||||||
elif exp and not self._is_expression(self.__exp):
|
elif exp and not self._is_expression(self.__exp):
|
||||||
raise ValueError, 'Bad expression: %r' % (self.__exp,)
|
raise ValueError('Bad expression: %r' % (self.__exp,))
|
||||||
|
|
||||||
def parse(self, cr, uid, table, context):
|
def parse(self, cr, uid, table, context):
|
||||||
|
|
||||||
|
@ -202,7 +203,7 @@ class expression(object):
|
||||||
ids2 = list(self.__right)
|
ids2 = list(self.__right)
|
||||||
|
|
||||||
self.__operator = 'in'
|
self.__operator = 'in'
|
||||||
if field._obj <> self.__table._name:
|
if field._obj != self.__table._name:
|
||||||
self.__right = ids2 + _rec_get(ids2, field_obj, self.__table._parent_name)
|
self.__right = ids2 + _rec_get(ids2, field_obj, self.__table._parent_name)
|
||||||
else:
|
else:
|
||||||
self.__right = ids2 + _rec_get(ids2, self.__table, self.__left)
|
self.__right = ids2 + _rec_get(ids2, self.__table, self.__left)
|
||||||
|
@ -264,7 +265,7 @@ class expression(object):
|
||||||
del params[i]
|
del params[i]
|
||||||
|
|
||||||
len_after = len(params)
|
len_after = len(params)
|
||||||
check_nulls = len_after <> len_before
|
check_nulls = len_after != len_before
|
||||||
query = '(1=0)'
|
query = '(1=0)'
|
||||||
|
|
||||||
if len_after:
|
if len_after:
|
||||||
|
|
|
@ -49,6 +49,7 @@ import warnings
|
||||||
|
|
||||||
import tools
|
import tools
|
||||||
|
|
||||||
|
|
||||||
def _symbol_set(symb):
|
def _symbol_set(symb):
|
||||||
if symb == None or symb == False:
|
if symb == None or symb == False:
|
||||||
return None
|
return None
|
||||||
|
@ -56,6 +57,7 @@ def _symbol_set(symb):
|
||||||
return symb.encode('utf-8')
|
return symb.encode('utf-8')
|
||||||
return str(symb)
|
return str(symb)
|
||||||
|
|
||||||
|
|
||||||
class _column(object):
|
class _column(object):
|
||||||
_classic_read = True
|
_classic_read = True
|
||||||
_classic_write = True
|
_classic_write = True
|
||||||
|
@ -97,20 +99,24 @@ class _column(object):
|
||||||
|
|
||||||
def set(self, cr, obj, id, name, value, user=None, context=None):
|
def set(self, cr, obj, id, name, value, user=None, context=None):
|
||||||
cr.execute('update '+obj._table+' set '+name+'='+self._symbol_set[0]+' where id=%d', (self._symbol_set[1](value), id))
|
cr.execute('update '+obj._table+' set '+name+'='+self._symbol_set[0]+' where id=%d', (self._symbol_set[1](value), id))
|
||||||
|
|
||||||
def set_memory(self, cr, obj, id, name, value, user=None, context=None):
|
def set_memory(self, cr, obj, id, name, value, user=None, context=None):
|
||||||
raise Exception, _('Not implemented set_memory method !')
|
raise Exception(_('Not implemented set_memory method !'))
|
||||||
|
|
||||||
def get_memory(self, cr, obj, ids, name, context=None, values=None):
|
def get_memory(self, cr, obj, ids, name, context=None, values=None):
|
||||||
raise Exception, _('Not implemented get_memory method !')
|
raise Exception(_('Not implemented get_memory method !'))
|
||||||
|
|
||||||
def get(self, cr, obj, ids, name, context=None, values=None):
|
def get(self, cr, obj, ids, name, context=None, values=None):
|
||||||
raise Exception, _('undefined get method !')
|
raise Exception(_('undefined get method !'))
|
||||||
|
|
||||||
def search(self, cr, obj, args, name, value, offset=0, limit=None, uid=None):
|
def search(self, cr, obj, args, name, value, offset=0, limit=None, uid=None):
|
||||||
ids = obj.search(cr, uid, args+self._domain+[(name, 'ilike', value)], offset, limit)
|
ids = obj.search(cr, uid, args+self._domain+[(name, 'ilike', value)], offset, limit)
|
||||||
res = obj.read(cr, uid, ids, [name])
|
res = obj.read(cr, uid, ids, [name])
|
||||||
return [x[name] for x in res]
|
return [x[name] for x in res]
|
||||||
|
|
||||||
def search_memory(self, cr, obj, args, name, value, offset=0, limit=None, uid=None, context=None):
|
def search_memory(self, cr, obj, args, name, value, offset=0, limit=None, uid=None, context=None):
|
||||||
raise Exception, _('Not implemented search_memory method !')
|
raise Exception(_('Not implemented search_memory method !'))
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
# Simple fields
|
# Simple fields
|
||||||
|
@ -121,17 +127,21 @@ class boolean(_column):
|
||||||
_symbol_f = lambda x: x and 'True' or 'False'
|
_symbol_f = lambda x: x and 'True' or 'False'
|
||||||
_symbol_set = (_symbol_c, _symbol_f)
|
_symbol_set = (_symbol_c, _symbol_f)
|
||||||
|
|
||||||
|
|
||||||
class integer(_column):
|
class integer(_column):
|
||||||
_type = 'integer'
|
_type = 'integer'
|
||||||
_symbol_c = '%d'
|
_symbol_c = '%d'
|
||||||
_symbol_f = lambda x: int(x or 0)
|
_symbol_f = lambda x: int(x or 0)
|
||||||
_symbol_set = (_symbol_c, _symbol_f)
|
_symbol_set = (_symbol_c, _symbol_f)
|
||||||
|
|
||||||
|
|
||||||
class reference(_column):
|
class reference(_column):
|
||||||
_type = 'reference'
|
_type = 'reference'
|
||||||
|
|
||||||
def __init__(self, string, selection, size, **args):
|
def __init__(self, string, selection, size, **args):
|
||||||
_column.__init__(self, string=string, size=size, selection=selection, **args)
|
_column.__init__(self, string=string, size=size, selection=selection, **args)
|
||||||
|
|
||||||
|
|
||||||
class char(_column):
|
class char(_column):
|
||||||
_type = 'char'
|
_type = 'char'
|
||||||
|
|
||||||
|
@ -158,35 +168,43 @@ class char(_column):
|
||||||
u_symb = unicode(symb)
|
u_symb = unicode(symb)
|
||||||
return u_symb.encode('utf8')[:self.size]
|
return u_symb.encode('utf8')[:self.size]
|
||||||
|
|
||||||
|
|
||||||
class text(_column):
|
class text(_column):
|
||||||
_type = 'text'
|
_type = 'text'
|
||||||
|
|
||||||
import __builtin__
|
import __builtin__
|
||||||
|
|
||||||
|
|
||||||
class float(_column):
|
class float(_column):
|
||||||
_type = 'float'
|
_type = 'float'
|
||||||
_symbol_c = '%f'
|
_symbol_c = '%f'
|
||||||
_symbol_f = lambda x: __builtin__.float(x or 0.0)
|
_symbol_f = lambda x: __builtin__.float(x or 0.0)
|
||||||
_symbol_set = (_symbol_c, _symbol_f)
|
_symbol_set = (_symbol_c, _symbol_f)
|
||||||
|
|
||||||
def __init__(self, string='unknown', digits=None, **args):
|
def __init__(self, string='unknown', digits=None, **args):
|
||||||
_column.__init__(self, string=string, **args)
|
_column.__init__(self, string=string, **args)
|
||||||
self.digits = digits
|
self.digits = digits
|
||||||
|
|
||||||
|
|
||||||
class date(_column):
|
class date(_column):
|
||||||
_type = 'date'
|
_type = 'date'
|
||||||
|
|
||||||
|
|
||||||
class datetime(_column):
|
class datetime(_column):
|
||||||
_type = 'datetime'
|
_type = 'datetime'
|
||||||
|
|
||||||
|
|
||||||
class time(_column):
|
class time(_column):
|
||||||
_type = 'time'
|
_type = 'time'
|
||||||
|
|
||||||
|
|
||||||
class binary(_column):
|
class binary(_column):
|
||||||
_type = 'binary'
|
_type = 'binary'
|
||||||
_symbol_c = '%s'
|
_symbol_c = '%s'
|
||||||
_symbol_f = lambda symb: symb and psycopg.Binary(symb) or None
|
_symbol_f = lambda symb: symb and psycopg.Binary(symb) or None
|
||||||
_symbol_set = (_symbol_c, _symbol_f)
|
_symbol_set = (_symbol_c, _symbol_f)
|
||||||
|
|
||||||
|
|
||||||
class selection(_column):
|
class selection(_column):
|
||||||
_type = 'selection'
|
_type = 'selection'
|
||||||
|
|
||||||
|
@ -233,6 +251,7 @@ class one2one(_column):
|
||||||
def search(self, cr, obj, args, name, value, offset=0, limit=None, uid=None):
|
def search(self, cr, obj, args, name, value, offset=0, limit=None, uid=None):
|
||||||
return obj.pool.get(self._obj).search(cr, uid, args+self._domain+[('name', 'like', value)], offset, limit)
|
return obj.pool.get(self._obj).search(cr, uid, args+self._domain+[('name', 'like', value)], offset, limit)
|
||||||
|
|
||||||
|
|
||||||
class many2one(_column):
|
class many2one(_column):
|
||||||
_classic_read = False
|
_classic_read = False
|
||||||
_classic_write = True
|
_classic_write = True
|
||||||
|
@ -309,6 +328,7 @@ class many2one(_column):
|
||||||
def search(self, cr, obj, args, name, value, offset=0, limit=None, uid=None):
|
def search(self, cr, obj, args, name, value, offset=0, limit=None, uid=None):
|
||||||
return obj.pool.get(self._obj).search(cr, uid, args+self._domain+[('name', 'like', value)], offset, limit)
|
return obj.pool.get(self._obj).search(cr, uid, args+self._domain+[('name', 'like', value)], offset, limit)
|
||||||
|
|
||||||
|
|
||||||
class one2many(_column):
|
class one2many(_column):
|
||||||
_classic_read = False
|
_classic_read = False
|
||||||
_classic_write = False
|
_classic_write = False
|
||||||
|
@ -365,7 +385,6 @@ class one2many(_column):
|
||||||
def search_memory(self, cr, obj, args, name, value, offset=0, limit=None, uid=None, operator='like', context=None):
|
def search_memory(self, cr, obj, args, name, value, offset=0, limit=None, uid=None, operator='like', context=None):
|
||||||
raise _('Not Implemented')
|
raise _('Not Implemented')
|
||||||
|
|
||||||
|
|
||||||
def get(self, cr, obj, ids, name, user=None, offset=0, context=None, values=None):
|
def get(self, cr, obj, ids, name, user=None, offset=0, context=None, values=None):
|
||||||
if not context:
|
if not context:
|
||||||
context = {}
|
context = {}
|
||||||
|
@ -408,9 +427,11 @@ class one2many(_column):
|
||||||
cr.execute('update '+_table+' set '+self._fields_id+'=NULL where '+self._fields_id+'=%d and id not in ('+','.join(map(str, ids2))+')', (id,))
|
cr.execute('update '+_table+' set '+self._fields_id+'=NULL where '+self._fields_id+'=%d and id not in ('+','.join(map(str, ids2))+')', (id,))
|
||||||
if act[2]:
|
if act[2]:
|
||||||
cr.execute('update '+_table+' set '+self._fields_id+'=%d where id in ('+','.join(map(str, act[2]))+')', (id,))
|
cr.execute('update '+_table+' set '+self._fields_id+'=%d where id in ('+','.join(map(str, act[2]))+')', (id,))
|
||||||
|
|
||||||
def search(self, cr, obj, args, name, value, offset=0, limit=None, uid=None, operator='like'):
|
def search(self, cr, obj, args, name, value, offset=0, limit=None, uid=None, operator='like'):
|
||||||
return obj.pool.get(self._obj).name_search(cr, uid, value, self._domain, offset, limit)
|
return obj.pool.get(self._obj).name_search(cr, uid, value, self._domain, offset, limit)
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Values: (0, 0, { fields }) create
|
# Values: (0, 0, { fields }) create
|
||||||
# (1, ID, { fields }) modification
|
# (1, ID, { fields }) modification
|
||||||
|
@ -527,7 +548,6 @@ class many2many(_column):
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
# Function fields
|
# Function fields
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
|
|
||||||
class function(_column):
|
class function(_column):
|
||||||
_classic_read = False
|
_classic_read = False
|
||||||
_classic_write = False
|
_classic_write = False
|
||||||
|
@ -579,6 +599,7 @@ class function(_column):
|
||||||
if self._fnct_inv:
|
if self._fnct_inv:
|
||||||
self._fnct_inv(obj, cr, user, id, name, value, self._fnct_inv_arg, context)
|
self._fnct_inv(obj, cr, user, id, name, value, self._fnct_inv_arg, context)
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
# Serialized fields
|
# Serialized fields
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
|
|
|
@ -49,21 +49,18 @@
|
||||||
import time
|
import time
|
||||||
import types
|
import types
|
||||||
from xml import dom, xpath
|
from xml import dom, xpath
|
||||||
from xml.parsers import expat
|
|
||||||
import string
|
import string
|
||||||
import pooler
|
|
||||||
import psycopg
|
|
||||||
import netsvc
|
import netsvc
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import fields
|
import fields
|
||||||
import ir
|
|
||||||
import tools
|
import tools
|
||||||
|
|
||||||
from tools.config import config
|
from tools.config import config
|
||||||
|
|
||||||
regex_order = re.compile('^([a-zA-Z0-9_]+( desc)?( asc)?,?)+$', re.I)
|
regex_order = re.compile('^([a-zA-Z0-9_]+( desc)?( asc)?,?)+$', re.I)
|
||||||
|
|
||||||
|
|
||||||
def intersect(la, lb):
|
def intersect(la, lb):
|
||||||
return filter(lambda x: x in lb, la)
|
return filter(lambda x: x in lb, la)
|
||||||
|
|
||||||
|
@ -74,6 +71,7 @@ class except_orm(Exception):
|
||||||
self.value = value
|
self.value = value
|
||||||
self.args = (name, value)
|
self.args = (name, value)
|
||||||
|
|
||||||
|
|
||||||
# Readonly python database object browser
|
# Readonly python database object browser
|
||||||
class browse_null(object):
|
class browse_null(object):
|
||||||
|
|
||||||
|
@ -92,6 +90,7 @@ class browse_null(object):
|
||||||
def __nonzero__(self):
|
def __nonzero__(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# TODO: execute an object method on browse_record_list
|
# TODO: execute an object method on browse_record_list
|
||||||
#
|
#
|
||||||
|
@ -131,7 +130,7 @@ class browse_record(object):
|
||||||
def __getitem__(self, name):
|
def __getitem__(self, name):
|
||||||
if name == 'id':
|
if name == 'id':
|
||||||
return self._id
|
return self._id
|
||||||
if not self._data[self._id].has_key(name):
|
if not name in self._data[self._id]:
|
||||||
# build the list of fields we will fetch
|
# build the list of fields we will fetch
|
||||||
|
|
||||||
# fetch the definition of the field which was asked for
|
# fetch the definition of the field which was asked for
|
||||||
|
@ -160,7 +159,7 @@ class browse_record(object):
|
||||||
# otherwise we fetch only that field
|
# otherwise we fetch only that field
|
||||||
else:
|
else:
|
||||||
ffields = [(name, col)]
|
ffields = [(name, col)]
|
||||||
ids = filter(lambda id: not self._data[id].has_key(name), self._data.keys())
|
ids = filter(lambda id: not name in self._data[id], self._data.keys())
|
||||||
# read the data
|
# read the data
|
||||||
fffields = map(lambda x: x[0], ffields)
|
fffields = map(lambda x: x[0], ffields)
|
||||||
datas = self._table.read(self._cr, self._uid, ids, fffields, context=self._context, load="_classic_write")
|
datas = self._table.read(self._cr, self._uid, ids, fffields, context=self._context, load="_classic_write")
|
||||||
|
@ -243,7 +242,7 @@ def get_pg_type(f):
|
||||||
fields.binary: 'bytea',
|
fields.binary: 'bytea',
|
||||||
fields.many2one: 'int4',
|
fields.many2one: 'int4',
|
||||||
}
|
}
|
||||||
if type_dict.has_key(type(f)):
|
if type(f) in type_dict:
|
||||||
f_type = (type_dict[type(f)], type_dict[type(f)])
|
f_type = (type_dict[type(f)], type_dict[type(f)])
|
||||||
elif isinstance(f, fields.float):
|
elif isinstance(f, fields.float):
|
||||||
if f.digits:
|
if f.digits:
|
||||||
|
@ -264,7 +263,7 @@ def get_pg_type(f):
|
||||||
f_type = ('int4', 'INTEGER')
|
f_type = ('int4', 'INTEGER')
|
||||||
else:
|
else:
|
||||||
f_type = ('varchar', 'VARCHAR(%d)' % f_size)
|
f_type = ('varchar', 'VARCHAR(%d)' % f_size)
|
||||||
elif isinstance(f, fields.function) and type_dict.has_key(eval('fields.'+(f._type))):
|
elif isinstance(f, fields.function) and eval('fields.'+(f._type)) in type_dict:
|
||||||
t = eval('fields.'+(f._type))
|
t = eval('fields.'+(f._type))
|
||||||
f_type = (type_dict[t], type_dict[t])
|
f_type = (type_dict[t], type_dict[t])
|
||||||
elif isinstance(f, fields.function) and f._type == 'float':
|
elif isinstance(f, fields.function) and f._type == 'float':
|
||||||
|
@ -277,6 +276,7 @@ def get_pg_type(f):
|
||||||
f_type = None
|
f_type = None
|
||||||
return f_type
|
return f_type
|
||||||
|
|
||||||
|
|
||||||
class orm_template(object):
|
class orm_template(object):
|
||||||
_name = None
|
_name = None
|
||||||
_columns = {}
|
_columns = {}
|
||||||
|
@ -345,7 +345,7 @@ class orm_template(object):
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
for key, val in vals.items():
|
for key, val in vals.items():
|
||||||
if cols[k][key]<>vals[key]:
|
if cols[k][key] != vals[key]:
|
||||||
print 'Different', cols[k][key], vals[key], k, key, self._name
|
print 'Different', cols[k][key], vals[key], k, key, self._name
|
||||||
cr.execute('update ir_model_fields set field_description=%s where model=%s and name=%s', (vals['field_description'], vals['model'], vals['name']))
|
cr.execute('update ir_model_fields set field_description=%s where model=%s and name=%s', (vals['field_description'], vals['model'], vals['name']))
|
||||||
cr.commit()
|
cr.commit()
|
||||||
|
@ -436,6 +436,7 @@ class orm_template(object):
|
||||||
context = {}
|
context = {}
|
||||||
fields = map(lambda x: x.split('/'), fields)
|
fields = map(lambda x: x.split('/'), fields)
|
||||||
logger = netsvc.Logger()
|
logger = netsvc.Logger()
|
||||||
|
|
||||||
def process_liness(self, datas, prefix, fields_def, position=0):
|
def process_liness(self, datas, prefix, fields_def, position=0):
|
||||||
line = datas[position]
|
line = datas[position]
|
||||||
row = {}
|
row = {}
|
||||||
|
@ -448,7 +449,7 @@ class orm_template(object):
|
||||||
#
|
#
|
||||||
for i in range(len(fields)):
|
for i in range(len(fields)):
|
||||||
if i >= len(line):
|
if i >= len(line):
|
||||||
raise Exception, _('Please check that all your lines have %d columns.') % (len(fields),)
|
raise Exception(_('Please check that all your lines have %d columns.') % (len(fields),))
|
||||||
field = fields[i]
|
field = fields[i]
|
||||||
if field == ["id"]:
|
if field == ["id"]:
|
||||||
data_id = line[i]
|
data_id = line[i]
|
||||||
|
@ -762,7 +763,7 @@ class orm_template(object):
|
||||||
groups = None
|
groups = None
|
||||||
group_str = node.getAttribute('groups')
|
group_str = node.getAttribute('groups')
|
||||||
if ',' in group_str:
|
if ',' in group_str:
|
||||||
groups = group_str.split(',');
|
groups = group_str.split(',')
|
||||||
readonly = False
|
readonly = False
|
||||||
access_pool = self.pool.get('ir.model.access')
|
access_pool = self.pool.get('ir.model.access')
|
||||||
for group in groups:
|
for group in groups:
|
||||||
|
@ -849,7 +850,6 @@ class orm_template(object):
|
||||||
fields[field].update(fields_def[field])
|
fields[field].update(fields_def[field])
|
||||||
return arch, fields
|
return arch, fields
|
||||||
|
|
||||||
|
|
||||||
def __get_default_calendar_view(self):
|
def __get_default_calendar_view(self):
|
||||||
"""Generate a default calendar view (For internal use only).
|
"""Generate a default calendar view (For internal use only).
|
||||||
"""
|
"""
|
||||||
|
@ -907,7 +907,8 @@ class orm_template(object):
|
||||||
return node
|
return node
|
||||||
for child in node.childNodes:
|
for child in node.childNodes:
|
||||||
res = _find(child, node2)
|
res = _find(child, node2)
|
||||||
if res: return res
|
if res:
|
||||||
|
return res
|
||||||
return None
|
return None
|
||||||
|
|
||||||
doc_src = dom.minidom.parseString(src)
|
doc_src = dom.minidom.parseString(src)
|
||||||
|
@ -945,7 +946,7 @@ class orm_template(object):
|
||||||
elif pos=='before':
|
elif pos=='before':
|
||||||
node.parentNode.insertBefore(child, node)
|
node.parentNode.insertBefore(child, node)
|
||||||
else:
|
else:
|
||||||
raise AttributeError, _('Unknown position in inherited view %s !') % pos
|
raise AttributeError(_('Unknown position in inherited view %s !') % pos)
|
||||||
else:
|
else:
|
||||||
attrs = ''.join([
|
attrs = ''.join([
|
||||||
' %s="%s"' % (attr, node2.getAttribute(attr))
|
' %s="%s"' % (attr, node2.getAttribute(attr))
|
||||||
|
@ -953,7 +954,7 @@ class orm_template(object):
|
||||||
if attr != 'position'
|
if attr != 'position'
|
||||||
])
|
])
|
||||||
tag = "<%s%s>" % (node2.localName, attrs)
|
tag = "<%s%s>" % (node2.localName, attrs)
|
||||||
raise AttributeError, _("Couldn't find tag '%s' in parent view !") % tag
|
raise AttributeError(_("Couldn't find tag '%s' in parent view !") % tag)
|
||||||
return doc_src.toxml(encoding="utf-8").replace('\t', '')
|
return doc_src.toxml(encoding="utf-8").replace('\t', '')
|
||||||
|
|
||||||
result = {'type': view_type, 'model': self._name}
|
result = {'type': view_type, 'model': self._name}
|
||||||
|
@ -1081,12 +1082,14 @@ class orm_template(object):
|
||||||
def copy(self, cr, uid, id, default=None, context=None):
|
def copy(self, cr, uid, id, default=None, context=None):
|
||||||
raise _('The copy method is not implemented on this object !')
|
raise _('The copy method is not implemented on this object !')
|
||||||
|
|
||||||
|
|
||||||
class orm_memory(orm_template):
|
class orm_memory(orm_template):
|
||||||
_protected = ['read', 'write', 'create', 'default_get', 'perm_read', 'unlink', 'fields_get', 'fields_view_get', 'search', 'name_get', 'distinct_field_get', 'name_search', 'copy', 'import_data', 'search_count']
|
_protected = ['read', 'write', 'create', 'default_get', 'perm_read', 'unlink', 'fields_get', 'fields_view_get', 'search', 'name_get', 'distinct_field_get', 'name_search', 'copy', 'import_data', 'search_count']
|
||||||
_inherit_fields = {}
|
_inherit_fields = {}
|
||||||
_max_count = 200
|
_max_count = 200
|
||||||
_max_hours = 1
|
_max_hours = 1
|
||||||
_check_time = 20
|
_check_time = 20
|
||||||
|
|
||||||
def __init__(self, cr):
|
def __init__(self, cr):
|
||||||
super(orm_memory, self).__init__(cr)
|
super(orm_memory, self).__init__(cr)
|
||||||
self.datas = {}
|
self.datas = {}
|
||||||
|
@ -1354,7 +1357,7 @@ class orm(orm_template):
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
ref = f._obj.replace('.', '_')
|
ref = f._obj.replace('.', '_')
|
||||||
# ir_actions is inherited so foreign key doesn't work on it
|
# ir_actions is inherited so foreign key doesn't work on it
|
||||||
if ref <> 'ir_actions':
|
if ref != 'ir_actions':
|
||||||
cr.execute("ALTER TABLE \"%s\" ADD FOREIGN KEY (\"%s\") REFERENCES \"%s\" ON DELETE %s" % (self._table, k, ref, f.ondelete))
|
cr.execute("ALTER TABLE \"%s\" ADD FOREIGN KEY (\"%s\") REFERENCES \"%s\" ON DELETE %s" % (self._table, k, ref, f.ondelete))
|
||||||
if f.select:
|
if f.select:
|
||||||
cr.execute("CREATE INDEX \"%s_%s_index\" ON \"%s\" (\"%s\")" % (self._table, k, self._table, k))
|
cr.execute("CREATE INDEX \"%s_%s_index\" ON \"%s\" (\"%s\")" % (self._table, k, self._table, k))
|
||||||
|
@ -1396,7 +1399,7 @@ class orm(orm_template):
|
||||||
# if the field is required and hasn't got a NOT NULL constraint
|
# if the field is required and hasn't got a NOT NULL constraint
|
||||||
if f.required and f_pg_notnull == 0:
|
if f.required and f_pg_notnull == 0:
|
||||||
# set the field to the default value if any
|
# set the field to the default value if any
|
||||||
if self._defaults.has_key(k):
|
if k in self._defaults:
|
||||||
default = self._defaults[k](self, cr, 1, {})
|
default = self._defaults[k](self, cr, 1, {})
|
||||||
if not (default is False):
|
if not (default is False):
|
||||||
cr.execute("UPDATE \"%s\" SET \"%s\"='%s' WHERE %s is NULL" % (self._table, k, default, k))
|
cr.execute("UPDATE \"%s\" SET \"%s\"='%s' WHERE %s is NULL" % (self._table, k, default, k))
|
||||||
|
@ -2010,7 +2013,7 @@ class orm(orm_template):
|
||||||
|
|
||||||
self._validate(cr, user, ids, context)
|
self._validate(cr, user, ids, context)
|
||||||
|
|
||||||
if context.has_key('read_delta'):
|
if 'read_delta' in context:
|
||||||
del context['read_delta']
|
del context['read_delta']
|
||||||
|
|
||||||
wf_service = netsvc.LocalService("workflow")
|
wf_service = netsvc.LocalService("workflow")
|
||||||
|
|
2567
bin/osv/osv.py
2567
bin/osv/osv.py
File diff suppressed because it is too large
Load Diff
|
@ -36,6 +36,7 @@ import netsvc
|
||||||
db_dic = {}
|
db_dic = {}
|
||||||
pool_dic = {}
|
pool_dic = {}
|
||||||
|
|
||||||
|
|
||||||
def get_db_and_pool(db_name, force_demo=False, status=None, update_module=False):
|
def get_db_and_pool(db_name, force_demo=False, status=None, update_module=False):
|
||||||
if not status:
|
if not status:
|
||||||
status={}
|
status={}
|
||||||
|
@ -60,11 +61,13 @@ def get_db_and_pool(db_name, force_demo=False, status=None, update_module=False)
|
||||||
pool.get('ir.cron')._poolJobs(db.dbname)
|
pool.get('ir.cron')._poolJobs(db.dbname)
|
||||||
return db, pool
|
return db, pool
|
||||||
|
|
||||||
|
|
||||||
def restart_pool(db_name, force_demo=False, update_module=False):
|
def restart_pool(db_name, force_demo=False, update_module=False):
|
||||||
# del db_dic[db_name]
|
# del db_dic[db_name]
|
||||||
del pool_dic[db_name]
|
del pool_dic[db_name]
|
||||||
return get_db_and_pool(db_name, force_demo, update_module=update_module)
|
return get_db_and_pool(db_name, force_demo, update_module=update_module)
|
||||||
|
|
||||||
|
|
||||||
def close_db(db_name):
|
def close_db(db_name):
|
||||||
if db_name in db_dic:
|
if db_name in db_dic:
|
||||||
db_dic[db_name].truedb.close()
|
db_dic[db_name].truedb.close()
|
||||||
|
@ -72,6 +75,7 @@ def close_db(db_name):
|
||||||
if db_name in pool_dic:
|
if db_name in pool_dic:
|
||||||
del pool_dic[db_name]
|
del pool_dic[db_name]
|
||||||
|
|
||||||
|
|
||||||
def get_db_only(db_name):
|
def get_db_only(db_name):
|
||||||
if db_name in db_dic:
|
if db_name in db_dic:
|
||||||
db = db_dic[db_name]
|
db = db_dic[db_name]
|
||||||
|
@ -80,10 +84,12 @@ def get_db_only(db_name):
|
||||||
db_dic[db_name] = db
|
db_dic[db_name] = db
|
||||||
return db
|
return db
|
||||||
|
|
||||||
|
|
||||||
def get_db(db_name):
|
def get_db(db_name):
|
||||||
# print "get_db", db_name
|
# print "get_db", db_name
|
||||||
return get_db_and_pool(db_name)[0]
|
return get_db_and_pool(db_name)[0]
|
||||||
|
|
||||||
|
|
||||||
def get_pool(db_name, force_demo=False, status=None, update_module=False):
|
def get_pool(db_name, force_demo=False, status=None, update_module=False):
|
||||||
# print "get_pool", db_name
|
# print "get_pool", db_name
|
||||||
pool = get_db_and_pool(db_name, force_demo, status, update_module)[1]
|
pool = get_db_and_pool(db_name, force_demo, status, update_module)[1]
|
||||||
|
@ -94,6 +100,7 @@ def get_pool(db_name, force_demo=False, status=None, update_module=False):
|
||||||
return pool
|
return pool
|
||||||
# return get_db_and_pool(db_name)[1]
|
# return get_db_and_pool(db_name)[1]
|
||||||
|
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
global db
|
global db
|
||||||
# db = get_db_only(tools.config['db_name'])
|
# db = get_db_only(tools.config['db_name'])
|
||||||
|
|
|
@ -246,6 +246,7 @@ if tools.config['netrpc']:
|
||||||
tinySocket = netsvc.TinySocketServerThread(netinterface, netport, False)
|
tinySocket = netsvc.TinySocketServerThread(netinterface, netport, False)
|
||||||
logger.notifyChannel("web-services", netsvc.LOG_INFO, "starting netrpc service, port "+str(netport))
|
logger.notifyChannel("web-services", netsvc.LOG_INFO, "starting netrpc service, port "+str(netport))
|
||||||
|
|
||||||
|
|
||||||
def handler(signum, frame):
|
def handler(signum, frame):
|
||||||
from tools import config
|
from tools import config
|
||||||
if tools.config['netrpc']:
|
if tools.config['netrpc']:
|
||||||
|
|
Loading…
Reference in New Issue