From bcfe4215d0c9a4fbd4d8ef6e75280618ec4f000d Mon Sep 17 00:00:00 2001 From: Olivier Laurent Date: Wed, 8 Jul 2009 11:13:02 +0200 Subject: [FIX] document: better ip address detection (especially on win32) bzr revid: olt@tinyerp.com-20090708091302-3zaz9ebjyeufeii4 --- addons/document/document.py | 46 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'addons/document/document.py') diff --git a/addons/document/document.py b/addons/document/document.py index 585031e1fc5..35df84dd1e6 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -66,8 +66,10 @@ def random_name(): # root: if we are at the first directory of a ressource # INVALID_CHARS={'*':str(hash('*')), '|':str(hash('|')) , "\\":str(hash("\\")), '/':'__', ':':str(hash(':')), '"':str(hash('"')), '<':str(hash('<')) , '>':str(hash('>')) , '?':str(hash('?'))} + + class node_class(object): - def __init__(self, cr, uid, path,object,object2=False, context={}, content=False, type='collection', root=False): + def __init__(self, cr, uid, path, object, object2=False, context={}, content=False, type='collection', root=False): self.cr = cr self.uid = uid self.path = path @@ -171,9 +173,9 @@ class node_class(object): pool = pooler.get_pool(self.cr.dbname) obj = pool.get(self.object.ressource_type_id.model) if len(obj.fields_get(self.cr, self.uid, ['dirname'])): - _dirname_field = 'dirname' + _dirname_field = 'dirname' else: - _dirname_field = 'name' + _dirname_field = 'name' name_for = obj._name.split('.')[-1] if nodename and nodename.find(name_for) == 0 : @@ -718,9 +720,45 @@ class document_configuration_wizard(osv.osv_memory): 'host': fields.char('Server Address', size=64, help="Put here the server address or IP. " \ "Keep localhost if you don't know what to write.", required=True) } + + def detect_ip_addr(self, cr, uid, context=None): + def _detect_ip_addr(self, cr, uid, context=None): + from array import array + import socket + from struct import pack, unpack + + try: + import fcntl + except ImportError: + fcntl = None + + if not fcntl: # not UNIX: + host = socket.gethostname() + ip_addr = socket.gethostbyname(host) + else: # UNIX: + # get all interfaces: + nbytes = 128 * 32 + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + names = array('B', '\0' * nbytes) + outbytes = unpack('iL', fcntl.ioctl( s.fileno(), 0x8912, pack('iL', nbytes, names.buffer_info()[0])))[0] + namestr = names.tostring() + ifaces = [namestr[i:i+32].split('\0', 1)[0] for i in range(0, outbytes, 32)] + + for ifname in [iface for iface in ifaces if iface != 'lo']: + ip_addr = socket.inet_ntoa(fcntl.ioctl(s.fileno(), 0x8915, pack('256s', ifname[:15]))[20:24]) + break + return ip_addr + + try: + ip_addr = _detect_ip_addr(self, cr, uid, context) + except: + ip_addr = 'localhost' + return ip_addr + _defaults = { - 'host': lambda *args: 'localhost' + 'host': detect_ip_addr, } + def action_cancel(self,cr,uid,ids,conect=None): return { 'view_type': 'form', -- cgit v1.2.3 From 1ef4bfec1ded630a1d4663031259aa959d8ba296 Mon Sep 17 00:00:00 2001 From: "Harry (Open ERP)" Date: Fri, 17 Jul 2009 12:33:32 +0530 Subject: [FIX] document : use '=' operator instend of 'like' on serach directory nodes into DMS lp bug: https://launchpad.net/bugs/400326 fixed bzr revid: hmo@tinyerp.com-20090717070332-am5mz4t8xfdjl7s5 --- addons/document/document.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'addons/document/document.py') diff --git a/addons/document/document.py b/addons/document/document.py index 35df84dd1e6..f8e7c29bb28 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -94,7 +94,7 @@ class node_class(object): where.append( ('parent_id','=',self.object.id) ) where.append( ('res_id','=',False) ) if nodename: - where.append( (fobj._rec_name,'like',nodename) ) + where.append( (fobj._rec_name,'=',nodename) ) for content in self.object.content_ids: if self.object2 or not content.include_name: if content.include_name: @@ -137,7 +137,7 @@ class node_class(object): where = [] if nodename: nodename = self.get_translation(nodename, self.context['lang']) - where.append(('name','like',nodename)) + where.append(('name','=',nodename)) if (self.object and self.object.type=='directory') or not self.object2: where.append(('parent_id','=',self.object and self.object.id or False)) else: @@ -163,7 +163,7 @@ class node_class(object): fobj = pool.get('ir.attachment') vargs = [('parent_id','=',False),('res_id','=',False)] if nodename: - vargs.append(('name','like',nodename)) + vargs.append(('name','=',nodename)) file_ids=fobj.search(self.cr,self.uid,vargs) res = fobj.browse(self.cr, self.uid, file_ids, context=self.context) @@ -188,7 +188,7 @@ class node_class(object): if nodename.find(INVALID_CHARS[invalid]) : nodename=nodename.replace(INVALID_CHARS[invalid],invalid) nodename = self.get_translation(nodename, self.context['lang']) - where.append((_dirname_field,'like',nodename)) + where.append((_dirname_field,'=',nodename)) if self.object.ressource_tree: if obj._parent_name in obj.fields_get(self.cr,self.uid): @@ -207,14 +207,15 @@ class node_class(object): ids = obj.search(self.cr, self.uid, where) res = obj.browse(self.cr, self.uid, ids,self.context) - for r in res: + for r in res: + r.name = False if len(obj.fields_get(self.cr, self.uid, [_dirname_field])): r.name = eval('r.'+_dirname_field) - else: - r.name = name_for+'%d'%r.id + if not r.name: + r.name = name_for + '%d'%r.id for invalid in INVALID_CHARS: if r.name.find(invalid) : - r.name=r.name.replace(invalid,INVALID_CHARS[invalid]) + r.name = r.name.replace(invalid,INVALID_CHARS[invalid]) result2 = map(lambda x: node_class(self.cr, self.uid, self.path+'/'+x.name.replace('/','__'), self.object, x, context=self.context, root=x.id), res) if result2: if self.object.ressource_tree: @@ -325,7 +326,7 @@ class document_directory(osv.osv): where = [] if nodename: nodename = self.get_translation(nodename, self.context['lang']) - where.append(('name','like',nodename)) + where.append(('name','=',nodename)) if object: where.append(('parent_id','=',object.id)) ids = self.search(cr, uid, where, context) -- cgit v1.2.3 From e279a5a54c07be6bc6c21c441b1cc7ce78c1d5b7 Mon Sep 17 00:00:00 2001 From: "Harry (Open ERP)" Date: Fri, 17 Jul 2009 14:38:33 +0530 Subject: [FIX] document : if name/dirname does not has value, dirname will be display like lp bug: https://launchpad.net/bugs/400326 fixed bzr revid: hmo@tinyerp.com-20090717090833-2bdbliy2fpd2p71f --- addons/document/document.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'addons/document/document.py') diff --git a/addons/document/document.py b/addons/document/document.py index f8e7c29bb28..1a66145a9d8 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -207,10 +207,11 @@ class node_class(object): ids = obj.search(self.cr, self.uid, where) res = obj.browse(self.cr, self.uid, ids,self.context) - for r in res: - r.name = False + for r in res: if len(obj.fields_get(self.cr, self.uid, [_dirname_field])): r.name = eval('r.'+_dirname_field) + else: + r.name = False if not r.name: r.name = name_for + '%d'%r.id for invalid in INVALID_CHARS: -- cgit v1.2.3