Document: cleanup, remove restriction on ressource dirs

The same code is also called when parent_type_id exists, so the assertion
would fire.

bzr revid: p_christ@hol.gr-20101012104015-gnwvni1bx35ntyl5
This commit is contained in:
P. Christeas 2010-10-12 13:40:15 +03:00
parent 4eab25baf3
commit 55d06c6ea1
2 changed files with 11 additions and 5 deletions

View File

@ -28,6 +28,7 @@ import os
import tools
from tools.translate import _
import nodes
import logging
DMS_ROOT_PATH = tools.config.get('document_path', os.path.join(tools.config['root_path'], 'filestore'))
@ -107,7 +108,7 @@ class document_file(osv.osv):
'parent_id': __get_def_directory
}
_sql_constraints = [
('filename_uniq', 'unique (name,parent_id,res_id,res_model)', 'The file name must be unique !')
# filename_uniq is not possible in pure SQL
]
def _check_duplication(self, cr, uid, vals, ids=[], op='create'):
name = vals.get('name', False)
@ -260,6 +261,9 @@ class document_file(osv.osv):
r = stor.prepare_unlink(cr, uid, storage_id, f)
if r:
unres.append(r)
else:
logging.getLogger('document').warning("Unlinking attachment #%s %s that has no storage",
f.id, f.name)
res = super(document_file, self).unlink(cr, uid, ids, context)
stor.do_unlink(cr, uid, unres)
return res

View File

@ -187,8 +187,6 @@ class document_directory(osv.osv):
if dbro.type == 'directory':
return nodes.node_dir
elif dbro.type == 'ressource':
assert not dbro.ressource_parent_type_id, \
"resource and parent_id at #%d: %r" % (dbro.id, dbro.ressource_parent_type_id)
return nodes.node_res_dir
else:
raise ValueError("dir node for %s type", dbro.type)
@ -248,6 +246,7 @@ class document_directory(osv.osv):
name=directory.name
if not parent_id:
parent_id=directory.parent_id and directory.parent_id.id or False
# TODO fix algo
if not ressource_parent_type_id:
ressource_parent_type_id=directory.ressource_parent_type_id and directory.ressource_parent_type_id.id or False
if not ressource_id:
@ -268,8 +267,11 @@ class document_directory(osv.osv):
def create(self, cr, uid, vals, context=None):
if not self._check_duplication(cr, uid, vals):
raise osv.except_osv(_('ValidateError'), _('Directory name must be unique!'))
if vals.get('name',False) and (vals.get('name').find('/')+1 or vals.get('name').find('@')+1 or vals.get('name').find('$')+1 or vals.get('name').find('#')+1) :
raise osv.except_osv(_('ValidateError'), _('Directory name contains special characters!'))
newname = vals.get('name',False)
if newname:
for illeg in ('/', '@', '$', '#'):
if illeg in newname:
raise osv.except_osv(_('ValidateError'), _('Directory name contains special characters!'))
return super(document_directory,self).create(cr, uid, vals, context)
# TODO def unlink(...