[IMP]:document sql queries to parameterized query
bzr revid: nch@tinyerp.com-20091126123916-0xu24h028ctr9vqz
This commit is contained in:
+27
-27
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
@@ -15,7 +15,7 @@
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
@@ -99,7 +99,7 @@ class node_class(object):
|
||||
if content.include_name:
|
||||
content_name = self.object2.name
|
||||
obj = pool.get(self.object.ressource_type_id.model)
|
||||
name_for = obj._name.split('.')[-1]
|
||||
name_for = obj._name.split('.')[-1]
|
||||
if content_name and content_name.find(name_for) == 0 :
|
||||
content_name = content_name.replace(name_for,'')
|
||||
test_nodename = content_name + (content.suffix or '') + (content.extension or '')
|
||||
@@ -121,17 +121,17 @@ class node_class(object):
|
||||
ids += fobj.search(self.cr, self.uid, where+[ ('parent_id','=',False) ])
|
||||
res = fobj.browse(self.cr, self.uid, ids, context=self.context)
|
||||
return map(lambda x: node_class(self.cr, self.uid, self.path+'/'+eval('x.'+fobj._rec_name), x, False, context=self.context, type='file', root=False), res) + res2
|
||||
|
||||
|
||||
def get_translation(self,value,lang):
|
||||
result = value
|
||||
#TODO : to get translation term
|
||||
return result
|
||||
|
||||
#TODO : to get translation term
|
||||
return result
|
||||
|
||||
def directory_list_for_child(self,nodename,parent=False):
|
||||
pool = pooler.get_pool(self.cr.dbname)
|
||||
where = []
|
||||
if nodename:
|
||||
nodename = self.get_translation(nodename, self.context['lang'])
|
||||
if nodename:
|
||||
nodename = self.get_translation(nodename, self.context['lang'])
|
||||
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))
|
||||
@@ -144,11 +144,11 @@ class node_class(object):
|
||||
|
||||
ids = pool.get('document.directory').search(self.cr, self.uid, where+[('ressource_id','=',0)])
|
||||
if self.object2:
|
||||
ids += pool.get('document.directory').search(self.cr, self.uid, where+[('ressource_id','=',self.object2.id)])
|
||||
ids += pool.get('document.directory').search(self.cr, self.uid, where+[('ressource_id','=',self.object2.id)])
|
||||
res = pool.get('document.directory').browse(self.cr, self.uid, ids, self.context)
|
||||
return res
|
||||
|
||||
def _child_get(self, nodename=False):
|
||||
def _child_get(self, nodename=False):
|
||||
if self.type not in ('collection','database'):
|
||||
return []
|
||||
res = self.directory_list_for_child(nodename)
|
||||
@@ -165,13 +165,13 @@ class node_class(object):
|
||||
result +=map(lambda x: node_class(self.cr, self.uid, self.path+'/'+eval('x.'+fobj._rec_name), x, False, context=self.context, type='file', root=self.root), res)
|
||||
if self.type=='collection' and self.object.type=="ressource":
|
||||
where = self.object.domain and eval(self.object.domain, {'active_id':self.root, 'uid':self.uid}) or []
|
||||
pool = pooler.get_pool(self.cr.dbname)
|
||||
pool = pooler.get_pool(self.cr.dbname)
|
||||
obj = pool.get(self.object.ressource_type_id.model)
|
||||
_dirname_field = obj._rec_name
|
||||
if len(obj.fields_get(self.cr, self.uid, ['dirname'])):
|
||||
_dirname_field = 'dirname'
|
||||
_dirname_field = 'dirname'
|
||||
|
||||
name_for = obj._name.split('.')[-1]
|
||||
name_for = obj._name.split('.')[-1]
|
||||
if nodename and nodename.find(name_for) == 0 :
|
||||
id = int(nodename.replace(name_for,''))
|
||||
where.append(('id','=',id))
|
||||
@@ -185,7 +185,7 @@ class node_class(object):
|
||||
where.append((_dirname_field,'=',nodename))
|
||||
|
||||
if self.object.ressource_tree:
|
||||
if obj._parent_name in obj.fields_get(self.cr,self.uid):
|
||||
if obj._parent_name in obj.fields_get(self.cr,self.uid):
|
||||
where.append((obj._parent_name,'=',self.object2 and self.object2.id or False))
|
||||
ids = obj.search(self.cr, self.uid, where)
|
||||
res = obj.browse(self.cr, self.uid, ids,self.context)
|
||||
@@ -198,25 +198,25 @@ class node_class(object):
|
||||
if self.object2:
|
||||
return result
|
||||
|
||||
|
||||
|
||||
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:
|
||||
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
|
||||
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:
|
||||
result += result2
|
||||
else:
|
||||
result = result2
|
||||
result = result2
|
||||
return result
|
||||
|
||||
def children(self):
|
||||
@@ -301,7 +301,7 @@ class document_directory(osv.osv):
|
||||
def _check_recursion(self, cr, uid, ids):
|
||||
level = 100
|
||||
while len(ids):
|
||||
cr.execute('select distinct parent_id from document_directory where id in ('+','.join(map(str, ids))+')')
|
||||
cr.execute('select distinct parent_id from document_directory where id =ANY(%s)',(ids,))
|
||||
ids = filter(None, map(lambda x:x[0], cr.fetchall()))
|
||||
if not level:
|
||||
return False
|
||||
@@ -336,9 +336,9 @@ class document_directory(osv.osv):
|
||||
object: the object.directory or object.directory.content
|
||||
object2: the other object linked (if object.directory.content)
|
||||
"""
|
||||
def get_object(self, cr, uid, uri, context={}):
|
||||
#TODO : set user's context_lang in context
|
||||
context.update({'lang':False})
|
||||
def get_object(self, cr, uid, uri, context={}):
|
||||
#TODO : set user's context_lang in context
|
||||
context.update({'lang':False})
|
||||
if not uri:
|
||||
return node_class(cr, uid, '', False, context=context, type='database')
|
||||
turi = tuple(uri)
|
||||
@@ -523,7 +523,7 @@ class document_file(osv.osv):
|
||||
|
||||
def _data_get(self, cr, uid, ids, name, arg, context):
|
||||
result = {}
|
||||
cr.execute('select id,store_fname,link from ir_attachment where id in ('+','.join(map(str, ids))+')')
|
||||
cr.execute('select id,store_fname,link from ir_attachment where id =ANY(%s)',(ids,))
|
||||
for id,r,l in cr.fetchall():
|
||||
try:
|
||||
value = file(os.path.join(self._get_filestore(cr), r), 'rb').read()
|
||||
@@ -544,7 +544,7 @@ class document_file(osv.osv):
|
||||
os.unlink(os.path.join(self._get_filestore(cr), filename))
|
||||
except:
|
||||
pass
|
||||
cr.execute('update ir_attachment set store_fname=NULL WHERE id=%s', (id,) )
|
||||
cr.execute('update ir_attachment set store_fname=NULL WHERE id=%s',(id,))
|
||||
return True
|
||||
#if (not context) or context.get('store_method','fs')=='fs':
|
||||
try:
|
||||
@@ -687,7 +687,7 @@ class document_file(osv.osv):
|
||||
datas=base64.encodestring(urllib.urlopen(vals['link']).read())
|
||||
else:
|
||||
datas = vals.get('datas',False)
|
||||
|
||||
|
||||
vals['file_size']= datas and len(datas) or 0
|
||||
if not self._check_duplication(cr,uid,vals):
|
||||
raise except_orm(_('ValidateError'), _('File name must be unique!'))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
@@ -15,7 +15,7 @@
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
@@ -77,9 +77,9 @@ def _to_decode(s):
|
||||
try:
|
||||
return s.decode('ascii')
|
||||
except UnicodeError:
|
||||
return s
|
||||
|
||||
|
||||
return s
|
||||
|
||||
|
||||
class file_wrapper(StringIO.StringIO):
|
||||
def __init__(self, sstr='', ressource_id=False, dbname=None, uid=1, name=''):
|
||||
StringIO.StringIO.__init__(self, sstr)
|
||||
@@ -153,7 +153,7 @@ class abstracted_fs:
|
||||
cr.execute("SELECT 1 FROM pg_class WHERE relkind = 'r' AND relname = 'ir_module_module'")
|
||||
if not cr.fetchone():
|
||||
continue
|
||||
|
||||
|
||||
cr.execute("select id from ir_module_module where name like 'document%' and state='installed' ")
|
||||
res = cr.fetchone()
|
||||
if res and len(res):
|
||||
@@ -165,7 +165,7 @@ class abstracted_fs:
|
||||
if cr is not None:
|
||||
cr.close()
|
||||
#if db is not None:
|
||||
# pooler.close_db(db_name)
|
||||
# pooler.close_db(db_name)
|
||||
return self.db_name_list
|
||||
|
||||
# Ok
|
||||
@@ -210,10 +210,10 @@ class abstracted_fs:
|
||||
def ftp2fs(self, path_orig, data):
|
||||
path = self.ftpnorm(path_orig)
|
||||
if not data or (path and path=='/'):
|
||||
return None
|
||||
return None
|
||||
path2 = filter(None,path.split('/'))[1:]
|
||||
(cr, uid, pool) = data
|
||||
if len(path2):
|
||||
if len(path2):
|
||||
path2[-1]=_to_unicode(path2[-1])
|
||||
res = pool.get('document.directory').get_object(cr, uid, path2[:])
|
||||
if not res:
|
||||
@@ -221,15 +221,15 @@ class abstracted_fs:
|
||||
return res
|
||||
|
||||
# Ok
|
||||
def fs2ftp(self, node):
|
||||
def fs2ftp(self, node):
|
||||
res='/'
|
||||
if node:
|
||||
res=os.path.normpath(node.path)
|
||||
res = res.replace("\\", "/")
|
||||
res = res.replace("\\", "/")
|
||||
while res[:2] == '//':
|
||||
res = res[1:]
|
||||
res='/' + node.cr.dbname + '/' + _to_decode(res)
|
||||
|
||||
res='/' + node.cr.dbname + '/' + _to_decode(res)
|
||||
|
||||
#res = node and ('/' + node.cr.dbname + '/' + _to_decode(self.ftpnorm(node.path))) or '/'
|
||||
return res
|
||||
|
||||
@@ -309,7 +309,7 @@ class abstracted_fs:
|
||||
|
||||
s = file_wrapper('', cid, cr.dbname, uid, )
|
||||
return s
|
||||
except Exception,e:
|
||||
except Exception,e:
|
||||
log(e)
|
||||
raise OSError(1, 'Operation not permited.')
|
||||
|
||||
@@ -372,7 +372,7 @@ class abstracted_fs:
|
||||
|
||||
|
||||
# Ok
|
||||
def chdir(self, path):
|
||||
def chdir(self, path):
|
||||
if not path:
|
||||
self.cwd='/'
|
||||
return None
|
||||
@@ -400,7 +400,7 @@ class abstracted_fs:
|
||||
'ressource_parent_type_id': object and object.ressource_type_id.id or False,
|
||||
'ressource_id': object2 and object2.id or False
|
||||
}
|
||||
if (object and (object.type in ('directory'))) or not object2:
|
||||
if (object and (object.type in ('directory'))) or not object2:
|
||||
val['parent_id'] = object and object.id or False
|
||||
# Check if it alreayd exists !
|
||||
pool.get('document.directory').create(cr, uid, val)
|
||||
@@ -448,8 +448,8 @@ class abstracted_fs:
|
||||
try:
|
||||
uid = security.login(db, self.username, self.password)
|
||||
if uid:
|
||||
result.append(false_node(db))
|
||||
except osv.except_osv:
|
||||
result.append(false_node(db))
|
||||
except osv.except_osv:
|
||||
pass
|
||||
return result
|
||||
return path.children()
|
||||
@@ -535,11 +535,11 @@ class abstracted_fs:
|
||||
ressource_type_id = pool.get('ir.model').search(cr,uid,[('model','=',dst_basedir.object2._name)])[0]
|
||||
ressource_id = dst_basedir.object2.id
|
||||
title = dst_basedir.object2.name
|
||||
ressource_model = dst_basedir.object2._name
|
||||
ressource_model = dst_basedir.object2._name
|
||||
if dst_basedir.object2._name=='res.partner':
|
||||
partner_id=dst_basedir.object2.id
|
||||
else:
|
||||
obj2=pool.get(dst_basedir.object2._name)
|
||||
obj2=pool.get(dst_basedir.object2._name)
|
||||
partner_id= obj2.fields_get(cr,uid,['partner_id']) and dst_basedir.object2.partner_id.id or False
|
||||
else:
|
||||
ressource_type_id = False
|
||||
@@ -560,7 +560,7 @@ class abstracted_fs:
|
||||
}
|
||||
pool.get('ir.attachment').write(cr, uid, result['attachment'], val)
|
||||
if (not val['res_id']) and result['attachment']:
|
||||
dst_basedir.cr.execute('update ir_attachment set res_id=NULL where id in ('+','.join(map(str,result['attachment']))+')')
|
||||
dst_basedir.cr.execute('update ir_attachment set res_id=NULL where id =ANY(%s)',(result['attachment'],))
|
||||
|
||||
cr.commit()
|
||||
elif src.type=='file':
|
||||
@@ -586,7 +586,7 @@ class abstracted_fs:
|
||||
if dst_basedir.object2._name=='res.partner':
|
||||
val['partner_id']=dst_basedir.object2.id
|
||||
else:
|
||||
obj2=pool.get(dst_basedir.object2._name)
|
||||
obj2=pool.get(dst_basedir.object2._name)
|
||||
val['partner_id']= obj2.fields_get(src.cr, src.uid,['partner_id']) and dst_basedir.object2.partner_id.id or False
|
||||
elif src.object.res_id:
|
||||
# I had to do that because writing False to an integer writes 0 instead of NULL
|
||||
@@ -700,7 +700,7 @@ class abstracted_fs:
|
||||
def get_list_dir(self, path):
|
||||
""""Return an iterator object that yields a directory listing
|
||||
in a form suitable for LIST command.
|
||||
"""
|
||||
"""
|
||||
if self.isdir(path):
|
||||
listing = self.listdir(path)
|
||||
#listing.sort()
|
||||
@@ -735,7 +735,7 @@ class abstracted_fs:
|
||||
listing.sort()
|
||||
return self.format_list(basedir, listing)
|
||||
|
||||
# Ok
|
||||
# Ok
|
||||
def format_list(self, basedir, listing, ignore_err=True):
|
||||
"""Return an iterator object that yields the entries of given
|
||||
directory emulating the "/bin/ls -lA" UNIX command output.
|
||||
@@ -774,13 +774,13 @@ class abstracted_fs:
|
||||
# stat.st_mtime could fail (-1) if last mtime is too old
|
||||
# in which case we return the local time as last mtime
|
||||
try:
|
||||
mname=_get_month_name(time.strftime("%m", time.localtime(st.st_mtime)))
|
||||
mname=_get_month_name(time.strftime("%m", time.localtime(st.st_mtime)))
|
||||
mtime = mname+' '+time.strftime("%d %H:%M", time.localtime(st.st_mtime))
|
||||
except ValueError:
|
||||
mname=_get_month_name(time.strftime("%m"))
|
||||
mtime = mname+' '+time.strftime("%d %H:%M")
|
||||
# formatting is matched with proftpd ls output
|
||||
path=_to_decode(file.path) #file.path.encode('ascii','replace').replace('?','_')
|
||||
mtime = mname+' '+time.strftime("%d %H:%M")
|
||||
# formatting is matched with proftpd ls output
|
||||
path=_to_decode(file.path) #file.path.encode('ascii','replace').replace('?','_')
|
||||
yield "%s %3s %-8s %-8s %8s %s %s\r\n" %(perms, nlinks, uname, gname,
|
||||
size, mtime, path.split('/')[-1])
|
||||
|
||||
@@ -818,7 +818,7 @@ class abstracted_fs:
|
||||
if 'd' in perms:
|
||||
permdir += 'p'
|
||||
type = size = perm = modify = create = unique = mode = uid = gid = ""
|
||||
for file in listing:
|
||||
for file in listing:
|
||||
try:
|
||||
st = self.stat(file)
|
||||
except OSError:
|
||||
@@ -828,7 +828,7 @@ class abstracted_fs:
|
||||
# type + perm
|
||||
if stat.S_ISDIR(st.st_mode):
|
||||
if 'type' in facts:
|
||||
type = 'type=dir;'
|
||||
type = 'type=dir;'
|
||||
if 'perm' in facts:
|
||||
perm = 'perm=%s;' %permdir
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user