summaryrefslogtreecommitdiff
path: root/addons/document/document_directory.py
diff options
context:
space:
mode:
authorHarry (OpenERP) <hmo@tinyerp.com>2010-07-20 18:35:13 +0530
committerHarry (OpenERP) <hmo@tinyerp.com>2010-07-20 18:35:13 +0530
commit77f62a88a314a905e5ffc73cffd72d68ddfe33db (patch)
treeedc70351000fba9ea5a4ab27a3f680c5844e9e82 /addons/document/document_directory.py
parent90234707dc901a81935570274c52a5327940b66e (diff)
parent1eea693ecadd3829fa729a727a154c23a1df6ab6 (diff)
[MERGE] merged new api of document module
bzr revid: hmo@tinyerp.com-20100720130513-3t2cbyvns3hlj6qn
Diffstat (limited to 'addons/document/document_directory.py')
-rw-r--r--addons/document/document_directory.py54
1 files changed, 36 insertions, 18 deletions
diff --git a/addons/document/document_directory.py b/addons/document/document_directory.py
index fee633b7169..f5b9202fc8e 100644
--- a/addons/document/document_directory.py
+++ b/addons/document/document_directory.py
@@ -39,20 +39,27 @@ class document_directory(osv.osv):
'write_uid': fields.many2one('res.users', 'Last Modification User', readonly=True),
'create_date': fields.datetime('Date Created', readonly=True),
'create_uid': fields.many2one('res.users', 'Creator', readonly=True),
- 'file_type': fields.char('Content Type', size=32),
'domain': fields.char('Domain', size=128, help="Use a domain if you want to apply an automatic filter on visible resources."),
'user_id': fields.many2one('res.users', 'Owner'),
'storage_id': fields.many2one('document.storage', 'Storage'),
'group_ids': fields.many2many('res.groups', 'document_directory_group_rel', 'item_id', 'group_id', 'Groups'),
- 'parent_id': fields.many2one('document.directory', 'Parent Item'),
+ 'parent_id': fields.many2one('document.directory', 'Parent Directory', select=1),
'child_ids': fields.one2many('document.directory', 'parent_id', 'Children'),
'file_ids': fields.one2many('ir.attachment', 'parent_id', 'Files'),
'content_ids': fields.one2many('document.directory.content', 'directory_id', 'Virtual Files'),
- 'type': fields.selection([('directory','Static Directory'),('ressource','Other Resources')], 'Type', required=True),
- 'ressource_type_id': fields.many2one('ir.model', 'Directories Mapped to Objects',
- help="Select an object here and Open ERP will create a mapping for each of these " \
- "objects, using the given domain, when browsing through FTP."),
+ 'type': fields.selection([
+ ('directory','Static Directory'),
+ ('ressource','Folders per resource'),
+ ],
+ 'Type', required=True, select=1,
+ help="Defines directory's behaviour."),
+
+ 'ressource_type_id': fields.many2one('ir.model', 'Resource model',
+ help="Select an object here and there will be one folder per record of that resource."),
'resource_field': fields.many2one('ir.model.fields', 'Name field', help='Field to be used as name on resource directories. If empty, the "name" will be used.'),
+ 'resource_find_all': fields.boolean('Find all resources', required=True,
+ help="If true, all attachments that match this resource will " \
+ " be located. If false, only ones that have this as parent." ),
'ressource_parent_type_id': fields.many2one('ir.model', 'Parent Model',
help="If you put an object here, this directory template will appear bellow all of these objects. " \
"Don't put a parent directory if you select a parent model."),
@@ -60,7 +67,7 @@ class document_directory(osv.osv):
'ressource_tree': fields.boolean('Tree Structure',
help="Check this if you want to use the same tree structure as the object selected in the system."),
'dctx_ids': fields.one2many('document.directory.dctx', 'dir_id', 'Context fields'),
- 'company_id': fields.many2one('res.company', 'Company'),
+ 'company_id': fields.many2one('res.company', 'Company'),
}
@@ -99,10 +106,12 @@ class document_directory(osv.osv):
'type': lambda *args: 'directory',
'ressource_id': lambda *a: 0,
'storage_id': _get_def_storage,
+ 'resource_find_all': True,
}
_sql_constraints = [
('dirname_uniq', 'unique (name,parent_id,ressource_id,ressource_parent_type_id)', 'The directory name must be unique !'),
- ('no_selfparent', 'check(parent_id <> id)', 'Directory cannot be parent of itself!')
+ ('no_selfparent', 'check(parent_id <> id)', 'Directory cannot be parent of itself!'),
+ ('dir_parented', 'check(parent_id IS NOT NULL OR storage_id IS NOT NULL)', 'Directory must have a parent or a storage')
]
def name_get(self, cr, uid, ids, context={}):
res = []
@@ -190,18 +199,25 @@ class document_directory(osv.osv):
"""
if not context:
context = {}
- lang = context.get('lang',False)
- if not lang:
- user = self.pool.get('res.users').browse(cr, uid, uid)
- lang = user.context_lang
- context['lang'] = lang
- try: #just instrumentation
- return nodes.get_node_context(cr, uid, context).get_uri(cr, uri)
- except Exception,e:
- print "exception: ",e
- raise
+ return nodes.get_node_context(cr, uid, context).get_uri(cr, uri)
+ def get_dir_permissions(self, cr, uid, ids ):
+ """Check what permission user 'uid' has on directory 'id'
+ """
+ assert len(ids) == 1
+ id = ids[0]
+
+ cr.execute( "SELECT count(dg.item_id) AS needs, count(ug.uid) AS has " \
+ " FROM document_directory_group_rel dg " \
+ " LEFT OUTER JOIN res_groups_users_rel ug " \
+ " ON (dg.group_id = ug.gid AND ug.uid = %s) " \
+ " WHERE dg.item_id = %s ", (uid, id))
+ needs, has = cr.fetchone()
+ if needs and not has:
+ return 1 # still allow to descend into.
+ else:
+ return 15
def _locate_child(self, cr, uid, root_id, uri,nparent, ncontext):
""" try to locate the node in uri,
@@ -274,6 +290,8 @@ class document_directory(osv.osv):
raise osv.except_osv(_('ValidateError'), _('Directory name contains special characters!'))
return super(document_directory,self).create(cr, uid, vals, context)
+ # TODO def unlink(...
+
document_directory()
class document_directory_dctx(osv.osv):