summaryrefslogtreecommitdiff
path: root/addons/document
diff options
context:
space:
mode:
authorJay (Open ERP) <jvo@tinyerp.com>2009-04-09 15:32:19 +0530
committerJay (Open ERP) <jvo@tinyerp.com>2009-04-09 15:32:19 +0530
commit2d281b5f63848558639df295cdf086a4fe201e4e (patch)
tree23094b5b8b71252f352ee2c14614d0a744a7bff1 /addons/document
parentfe280b98b8506eb255f34f4ccf83946e7f9eb71c (diff)
parent272b3b65c3bb34353119d17dbe3e9fa517a13c28 (diff)
Merged Trunk to addons/5.0
bzr revid: jvo@tinyerp.com-20090409100219-5bo156xq8k24qmru
Diffstat (limited to 'addons/document')
-rw-r--r--addons/document/document.py38
-rw-r--r--addons/document/ftpserver/__init__.py3
-rw-r--r--addons/document/ftpserver/abstracted_fs.py41
3 files changed, 53 insertions, 29 deletions
diff --git a/addons/document/document.py b/addons/document/document.py
index 0cde94a12f7..b06cfbae7df 100644
--- a/addons/document/document.py
+++ b/addons/document/document.py
@@ -136,7 +136,7 @@ class node_class(object):
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)
@@ -153,19 +153,8 @@ class node_class(object):
result +=map(lambda x: node_class(self.cr, self.uid, self.path+'/'+x.name, x, False, 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}) or []
- pool = pooler.get_pool(self.cr.dbname)
+ pool = pooler.get_pool(self.cr.dbname)
obj = pool.get(self.object.ressource_type_id.model)
-
- if self.object.ressource_tree:
- 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))
- else :
- if self.object2:
- return result
- else:
- if self.object2:
- return result
-
name_for = obj._name.split('.')[-1]
if nodename and nodename.find(name_for) == 0 :
id = int(nodename.replace(name_for,''))
@@ -177,6 +166,22 @@ class node_class(object):
if nodename.find(INVALID_CHARS[invalid]) :
nodename=nodename.replace(INVALID_CHARS[invalid],invalid)
where.append(('name','like',nodename))
+
+ if self.object.ressource_tree:
+ 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, self.context)
+ res = obj.browse(self.cr, self.uid, ids,self.context)
+ result+= map(lambda x: node_class(self.cr, self.uid, self.path+'/'+x.name.replace('/','__'), self.object, x, root=x.id), res)
+ return result
+ else :
+ if self.object2:
+ return result
+ else:
+ if self.object2:
+ return result
+
+
ids = obj.search(self.cr, self.uid, where, self.context)
res = obj.browse(self.cr, self.uid, ids,self.context)
for r in res:
@@ -184,10 +189,10 @@ class node_class(object):
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])
- result2 = map(lambda x: node_class(self.cr, self.uid, self.path+'/'+x.name.replace('/','__'), self.object, x, root=r.id), res)
+ 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, root=x.id), res)
if result2:
- result = result2
+ result = result2
return result
def children(self):
@@ -583,6 +588,7 @@ class document_file(osv.osv):
res=self.search(cr,uid,[('id','<>',file.id),('name','=',name),('parent_id','=',parent_id),('res_model','=',res_model),('res_id','=',res_id)])
if len(res):
return False
+
if op=='create':
res=self.search(cr,uid,[('name','=',name),('parent_id','=',parent_id),('res_id','=',res_id),('res_model','=',res_model)])
if len(res):
diff --git a/addons/document/ftpserver/__init__.py b/addons/document/ftpserver/__init__.py
index 35d1107ad81..1d158ccf0a1 100644
--- a/addons/document/ftpserver/__init__.py
+++ b/addons/document/ftpserver/__init__.py
@@ -36,7 +36,7 @@ class ftp_server(threading.Thread):
logger.notifyChannel('FTP', level, message)
def run(self):
- autho = authorizer.authorizer()
+ autho = authorizer.authorizer()
ftpserver.FTPHandler.authorizer = autho
ftpserver.max_cons = 300
ftpserver.max_cons_per_ip = 50
@@ -49,7 +49,6 @@ class ftp_server(threading.Thread):
address = (HOST, PORT)
ftpd = ftpserver.FTPServer(address, ftpserver.FTPHandler)
ftpd.serve_forever()
-
ds = ftp_server()
ds.start()
diff --git a/addons/document/ftpserver/abstracted_fs.py b/addons/document/ftpserver/abstracted_fs.py
index 155c68ae515..4ee50e431bf 100644
--- a/addons/document/ftpserver/abstracted_fs.py
+++ b/addons/document/ftpserver/abstracted_fs.py
@@ -17,6 +17,22 @@ from service import security
def log(message):
logger = netsvc.Logger()
logger.notifyChannel('DMS', netsvc.LOG_ERROR, message)
+
+
+def _get_month_name(month):
+ month=int(month)
+ if month==1:return 'Jan'
+ elif month==2:return 'Feb'
+ elif month==3:return 'Mar'
+ elif month==4:return 'Apr'
+ elif month==5:return 'May'
+ elif month==6:return 'Jun'
+ elif month==7:return 'Jul'
+ elif month==8:return 'Aug'
+ elif month==9:return 'Sep'
+ elif month==10:return 'Oct'
+ elif month==11:return 'Nov'
+ elif month==12:return 'Dec'
class file_wrapper(StringIO.StringIO):
def __init__(self, sstr='', ressource_id=False, dbname=None, uid=1, name=''):
@@ -195,7 +211,7 @@ class abstracted_fs:
cid=False
where=[('name','=',objname)]
- if object and (object.type in ('directory','ressource')) or object2:
+ if object and (object.type in ('directory')) or object2:
where.append(('parent_id','=',object.id))
else:
where.append(('parent_id','=',False))
@@ -214,7 +230,7 @@ class abstracted_fs:
'file_size': 0L,
'file_type': ext,
}
- if object and (object.type in ('directory','ressource')) or not object2:
+ if object and (object.type in ('directory')) or not object2:
val['parent_id']= object and object.id or False
partner = False
if object2:
@@ -322,7 +338,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)
@@ -449,11 +465,12 @@ 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:
- partner_id= dst_basedir.object2.partner_id and dst_basedir.object2.partner_id.id or False
+ 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
ressource_id=False
@@ -463,7 +480,7 @@ class abstracted_fs:
pool.get('document.directory').write(cr, uid, result['directory'], {
'ressource_id': ressource_id,
- 'ressource_parent_type_id': ressource_type_id
+ 'ressource_type_id': ressource_type_id
})
val = {
'res_id': ressource_id,
@@ -499,7 +516,8 @@ class abstracted_fs:
if dst_basedir.object2._name=='res.partner':
val['partner_id']=dst_basedir.object2.id
else:
- val['partner_id']= dst_basedir.object2.partner_id and dst_basedir.object2.partner_id.id or False
+ obj2=pool.get(dst_basedir.object2._name)
+ val['partner_id']= obj2.fields_get(cr,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
# change if one day we decide to improve osv/fields.py
@@ -647,7 +665,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.
@@ -686,10 +704,11 @@ 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:
- mtime = time.strftime("%b %d %H:%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:
- mtime = time.strftime("%b %d %H:%M")
-
+ mname=_get_month_name(time.strftime("%m"))
+ mtime = mname+' '+time.strftime("%d %H:%M")
# formatting is matched with proftpd ls output
yield "%s %3s %-8s %-8s %8s %s %s\r\n" %(perms, nlinks, uname, gname,
size, mtime, file.path.encode('ascii','replace').replace('?','_').split('/')[-1])