Rename webdav directory into collection
This commit is contained in:
+40
-40
@@ -6,31 +6,31 @@ from trytond.osv import fields, OSV
|
||||
from trytond.version import PACKAGE, VERSION, WEBSITE
|
||||
|
||||
|
||||
class Directory(OSV):
|
||||
"Directory"
|
||||
_name = "webdav.directory"
|
||||
class Collection(OSV):
|
||||
"Collection"
|
||||
_name = "webdav.collection"
|
||||
_description = __doc__
|
||||
name = fields.Char('Name', size=128, required=True, select=1)
|
||||
parent = fields.Many2One('webdav.directory', 'Parent',
|
||||
parent = fields.Many2One('webdav.collection', 'Parent',
|
||||
ondelete='restrict')
|
||||
childs = fields.One2Many('webdav.directory', 'parent', 'Childs')
|
||||
childs = fields.One2Many('webdav.collection', 'parent', 'Childs')
|
||||
model = fields.Many2One('ir.model', 'Model')
|
||||
domain = fields.Char('Domain', size=250)
|
||||
_parent_name = 'parent'
|
||||
|
||||
def __init__(self):
|
||||
super(Directory, self).__init__()
|
||||
super(Collection, self).__init__()
|
||||
self._sql_constraints += [
|
||||
('name_parent_uniq', 'UNIQUE (name, parent)',
|
||||
'The directory name must be unique inside a directory!'),
|
||||
'The collection name must be unique inside a collection!'),
|
||||
]
|
||||
self._constraints += [
|
||||
('check_recursion',
|
||||
'Error! You can not create recursive directories.', ['parent']),
|
||||
'Error! You can not create recursive collections.', ['parent']),
|
||||
('check_attachment',
|
||||
'Error! You can not create a directory \n' \
|
||||
'Error! You can not create a collection \n' \
|
||||
'with the same name of an existing file \n' \
|
||||
'inside the same directory.', ['name']),
|
||||
'inside the same collection.', ['name']),
|
||||
]
|
||||
self.ext2mime = {
|
||||
'.png': 'image/png',
|
||||
@@ -41,15 +41,15 @@ class Directory(OSV):
|
||||
|
||||
def check_attachment(self, cursor, user, ids):
|
||||
attachment_obj = self.pool.get('ir.attachment')
|
||||
for directory in self.browse(cursor, user, ids):
|
||||
if directory.parent:
|
||||
for collection in self.browse(cursor, user, ids):
|
||||
if collection.parent:
|
||||
attachment_ids = attachment_obj.search(cursor, user, [
|
||||
('res_model', '=', self._name),
|
||||
('res_id', '=', directory.parent.id),
|
||||
('res_id', '=', collection.parent.id),
|
||||
])
|
||||
for attachment in attachment_obj.browse(cursor, user,
|
||||
attachment_ids):
|
||||
if attachment.name == directory.name:
|
||||
if attachment.name == collection.name:
|
||||
return False
|
||||
return True
|
||||
|
||||
@@ -60,16 +60,16 @@ class Directory(OSV):
|
||||
return self._name, False
|
||||
name, uri = (uri.split('/', 1) + [None])[0:2]
|
||||
if object_name == self._name:
|
||||
directory_ids = self.search(cursor, user, [
|
||||
collection_ids = self.search(cursor, user, [
|
||||
('name', '=', name),
|
||||
('parent', '=', object_id),
|
||||
], limit=1, context=context)
|
||||
if directory_ids:
|
||||
object_id = directory_ids[0]
|
||||
directory = self.browse(cursor, user, object_id,
|
||||
if collection_ids:
|
||||
object_id = collection_ids[0]
|
||||
collection = self.browse(cursor, user, object_id,
|
||||
context=context)
|
||||
if directory.model and uri:
|
||||
object_name = directory.model.model
|
||||
if collection.model and uri:
|
||||
object_name = collection.model.model
|
||||
else:
|
||||
if uri:
|
||||
return None, 0
|
||||
@@ -111,25 +111,25 @@ class Directory(OSV):
|
||||
def get_childs(self, cursor, user, uri, context=None):
|
||||
res = []
|
||||
if not uri:
|
||||
directory_ids = self.search(cursor, user, [
|
||||
collection_ids = self.search(cursor, user, [
|
||||
('parent', '=', False),
|
||||
], context=context)
|
||||
for directory in self.browse(cursor, user, directory_ids,
|
||||
for collection in self.browse(cursor, user, collection_ids,
|
||||
context=context):
|
||||
if '/' in directory.name:
|
||||
if '/' in collection.name:
|
||||
continue
|
||||
res.append(directory.name)
|
||||
res.append(collection.name)
|
||||
return res
|
||||
object_name, object_id = self._uri2object(cursor, user, uri,
|
||||
context=context)
|
||||
if object_name == self._name and object_id:
|
||||
directory = self.browse(cursor, user, object_id, context=context)
|
||||
if directory.model:
|
||||
model_obj = self.pool.get(directory.model.model)
|
||||
collection = self.browse(cursor, user, object_id, context=context)
|
||||
if collection.model:
|
||||
model_obj = self.pool.get(collection.model.model)
|
||||
if not model_obj:
|
||||
return res
|
||||
model_ids = model_obj.search(cursor, user,
|
||||
eval(directory.domain or "[]"), context=context)
|
||||
eval(collection.domain or "[]"), context=context)
|
||||
for child_id, child_name in model_obj.name_get(cursor, user,
|
||||
model_ids, context=context):
|
||||
if '/' in child_name:
|
||||
@@ -137,7 +137,7 @@ class Directory(OSV):
|
||||
res.append(child_name + '-' + str(child_id))
|
||||
return res
|
||||
else:
|
||||
for child in directory.childs:
|
||||
for child in collection.childs:
|
||||
if '/' in child.name:
|
||||
continue
|
||||
res.append(child.name)
|
||||
@@ -259,7 +259,7 @@ class Directory(OSV):
|
||||
uri = uri[:-1]
|
||||
object_name, object_id = self._uri2object(cursor, user,
|
||||
get_uriparentpath(uri), context=context)
|
||||
if object_name != 'webdav.directory':
|
||||
if object_name != 'webdav.collection':
|
||||
raise DAV_Forbidden
|
||||
name = get_urifilename(uri)
|
||||
try:
|
||||
@@ -275,7 +275,7 @@ class Directory(OSV):
|
||||
from DAV.errors import DAV_Forbidden
|
||||
object_name, object_id = self._uri2object(cursor, user, uri,
|
||||
context=context)
|
||||
if object_name != 'webdav.directory' \
|
||||
if object_name != 'webdav.collection' \
|
||||
or not object_id:
|
||||
raise DAV_Forbidden
|
||||
try:
|
||||
@@ -305,7 +305,7 @@ class Directory(OSV):
|
||||
return 1
|
||||
return None
|
||||
|
||||
Directory()
|
||||
Collection()
|
||||
|
||||
|
||||
class Attachment(OSV):
|
||||
@@ -314,19 +314,19 @@ class Attachment(OSV):
|
||||
def __init__(self):
|
||||
super(Attachment, self).__init__()
|
||||
self._constraints += [
|
||||
('check_directory',
|
||||
('check_collection',
|
||||
'Error! You can not create a attachment \n' \
|
||||
'on a directory that have the same name \n' \
|
||||
'than a child directory.', ['name']),
|
||||
'on a collection that have the same name \n' \
|
||||
'than a child collection.', ['name']),
|
||||
]
|
||||
|
||||
def check_directory(self, cursor, user, ids):
|
||||
directory_obj = self.pool.get('webdav.directory')
|
||||
def check_collection(self, cursor, user, ids):
|
||||
collection_obj = self.pool.get('webdav.collection')
|
||||
for attachment in self.browse(cursor, user, ids):
|
||||
if attachment.res_model == 'webdav.directory':
|
||||
directory = directory_obj.browse(cursor, user,
|
||||
if attachment.res_model == 'webdav.collection':
|
||||
collection = collection_obj.browse(cursor, user,
|
||||
attachment.res_id)
|
||||
for child in directory.childs:
|
||||
for child in collection.childs:
|
||||
if child.name == attachment.name:
|
||||
return False
|
||||
return True
|
||||
|
||||
+24
-24
@@ -3,25 +3,25 @@
|
||||
<data>
|
||||
<menuitem name="WebDAV" id="menu_webdav"
|
||||
parent="ir.menu_administration"/>
|
||||
<record model="ir.ui.view" id="directory_view_tree">
|
||||
<field name="model">webdav.directory</field>
|
||||
<record model="ir.ui.view" id="collection_view_tree">
|
||||
<field name="model">webdav.collection</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="field_childs">childs</field>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
<tree string="Directories">
|
||||
<tree string="Collections">
|
||||
<field name="name"/>
|
||||
<field name="model"/>
|
||||
</tree>
|
||||
]]>
|
||||
</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="directory_view_form">
|
||||
<field name="model">webdav.directory</field>
|
||||
<record model="ir.ui.view" id="collection_view_form">
|
||||
<field name="model">webdav.collection</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
<form string="Directory">
|
||||
<form string="Collection">
|
||||
<label name="name"/>
|
||||
<field name="name"/>
|
||||
<label name="parent"/>
|
||||
@@ -34,40 +34,40 @@
|
||||
]]>
|
||||
</field>
|
||||
</record>
|
||||
<record model="ir.action.act_window" id="act_directory_tree">
|
||||
<field name="name">Directories</field>
|
||||
<record model="ir.action.act_window" id="act_collection_tree">
|
||||
<field name="name">Collections</field>
|
||||
<field name="type">ir.action.act_window</field>
|
||||
<field name="res_model">webdav.directory</field>
|
||||
<field name="res_model">webdav.collection</field>
|
||||
<field name="view_type">tree</field>
|
||||
<field name="domain">[('parent', '=', False)]</field>
|
||||
</record>
|
||||
<record model="ir.action.act_window.view"
|
||||
id="act_directory_tree_view1">
|
||||
id="act_collection_tree_view1">
|
||||
<field name="sequence" eval="1"/>
|
||||
<field name="view" ref="directory_view_tree"/>
|
||||
<field name="act_window" ref="act_directory_tree"/>
|
||||
<field name="view" ref="collection_view_tree"/>
|
||||
<field name="act_window" ref="act_collection_tree"/>
|
||||
</record>
|
||||
<menuitem parent="menu_webdav"
|
||||
action="act_directory_tree" id="menu_directory_tree"/>
|
||||
<record model="ir.action.act_window" id="act_directory_form">
|
||||
<field name="name">Directory</field>
|
||||
action="act_collection_tree" id="menu_collection_tree"/>
|
||||
<record model="ir.action.act_window" id="act_collection_form">
|
||||
<field name="name">Collection</field>
|
||||
<field name="type">ir.action.act_window</field>
|
||||
<field name="res_model">webdav.directory</field>
|
||||
<field name="res_model">webdav.collection</field>
|
||||
<field name="view_type">form</field>
|
||||
</record>
|
||||
<record model="ir.action.act_window.view"
|
||||
id="act_directory_form_view1">
|
||||
id="act_collection_form_view1">
|
||||
<field name="sequence" eval="1"/>
|
||||
<field name="view" ref="directory_view_form"/>
|
||||
<field name="act_window" ref="act_directory_form"/>
|
||||
<field name="view" ref="collection_view_form"/>
|
||||
<field name="act_window" ref="act_collection_form"/>
|
||||
</record>
|
||||
<record model="ir.action.act_window.view"
|
||||
id="act_directory_form_view2">
|
||||
id="act_collection_form_view2">
|
||||
<field name="sequence" eval="2"/>
|
||||
<field name="view" ref="directory_view_tree"/>
|
||||
<field name="act_window" ref="act_directory_form"/>
|
||||
<field name="view" ref="collection_view_tree"/>
|
||||
<field name="act_window" ref="act_collection_form"/>
|
||||
</record>
|
||||
<menuitem name="New Directory" parent="menu_directory_tree"
|
||||
action="act_directory_form" id="menu_directory_form"/>
|
||||
<menuitem name="New Collection" parent="menu_collection_tree"
|
||||
action="act_collection_form" id="menu_collection_form"/>
|
||||
</data>
|
||||
</tryton>
|
||||
|
||||
+25
-25
@@ -63,10 +63,10 @@ class TrytonDAVInterface(iface.dav_interface):
|
||||
return res
|
||||
pool = pooler.get_pool(dbname)
|
||||
cursor = pooler.get_db(dbname).cursor()
|
||||
directory_obj = pool.get('webdav.directory')
|
||||
collection_obj = pool.get('webdav.collection')
|
||||
if uri[-1:] != '/':
|
||||
uri += '/'
|
||||
for child in directory_obj.get_childs(cursor, int(USER_ID), dburi):
|
||||
for child in collection_obj.get_childs(cursor, int(USER_ID), dburi):
|
||||
res.append(urlparse.urljoin(self.baseuri, uri + child))
|
||||
cursor.close()
|
||||
return res
|
||||
@@ -82,7 +82,7 @@ class TrytonDAVInterface(iface.dav_interface):
|
||||
% (PACKAGE, dbname or 'root')
|
||||
res += '</head>'
|
||||
res += '<body>'
|
||||
res += '<h2>Directory: %s</h2>' % (get_urifilename(uri) or '/')
|
||||
res += '<h2>Collection: %s</h2>' % (get_urifilename(uri) or '/')
|
||||
res += '<ul>'
|
||||
if dbname:
|
||||
res += '<li><a href="%s">..</a></li>' \
|
||||
@@ -101,9 +101,9 @@ class TrytonDAVInterface(iface.dav_interface):
|
||||
return res
|
||||
pool = pooler.get_pool(dbname)
|
||||
cursor = pooler.get_db(dbname).cursor()
|
||||
directory_obj = pool.get('webdav.directory')
|
||||
collection_obj = pool.get('webdav.collection')
|
||||
try:
|
||||
res = directory_obj.get_data(cursor, int(USER_ID), dburi)
|
||||
res = collection_obj.get_data(cursor, int(USER_ID), dburi)
|
||||
finally:
|
||||
cursor.close()
|
||||
return res
|
||||
@@ -114,10 +114,10 @@ class TrytonDAVInterface(iface.dav_interface):
|
||||
raise DAV_Forbidden
|
||||
pool = pooler.get_pool(dbname)
|
||||
cursor = pooler.get_db(dbname).cursor()
|
||||
directory_obj = pool.get('webdav.directory')
|
||||
collection_obj = pool.get('webdav.collection')
|
||||
try:
|
||||
try:
|
||||
res = directory_obj.put(cursor, int(USER_ID), dburi, data,
|
||||
res = collection_obj.put(cursor, int(USER_ID), dburi, data,
|
||||
content_type)
|
||||
cursor.commit()
|
||||
except:
|
||||
@@ -133,10 +133,10 @@ class TrytonDAVInterface(iface.dav_interface):
|
||||
raise DAV_Forbidden
|
||||
pool = pooler.get_pool(dbname)
|
||||
cursor = pooler.get_db(dbname).cursor()
|
||||
directory_obj = pool.get('webdav.directory')
|
||||
collection_obj = pool.get('webdav.collection')
|
||||
try:
|
||||
try:
|
||||
res = directory_obj.mkcol(cursor, int(USER_ID), dburi)
|
||||
res = collection_obj.mkcol(cursor, int(USER_ID), dburi)
|
||||
cursor.commit()
|
||||
except:
|
||||
cursor.rollback()
|
||||
@@ -151,8 +151,8 @@ class TrytonDAVInterface(iface.dav_interface):
|
||||
return COLLECTION
|
||||
pool = pooler.get_pool(dbname)
|
||||
cursor = pooler.get_db(dbname).cursor()
|
||||
directory_obj = pool.get('webdav.directory')
|
||||
res = directory_obj.get_resourcetype(cursor, int(USER_ID), dburi)
|
||||
collection_obj = pool.get('webdav.collection')
|
||||
res = collection_obj.get_resourcetype(cursor, int(USER_ID), dburi)
|
||||
cursor.close()
|
||||
return res
|
||||
|
||||
@@ -165,8 +165,8 @@ class TrytonDAVInterface(iface.dav_interface):
|
||||
return '0'
|
||||
pool = pooler.get_pool(dbname)
|
||||
cursor = pooler.get_db(dbname).cursor()
|
||||
directory_obj = pool.get('webdav.directory')
|
||||
res = directory_obj.get_contentlength(cursor, int(USER_ID), dburi)
|
||||
collection_obj = pool.get('webdav.collection')
|
||||
res = collection_obj.get_contentlength(cursor, int(USER_ID), dburi)
|
||||
cursor.close()
|
||||
return res
|
||||
|
||||
@@ -176,8 +176,8 @@ class TrytonDAVInterface(iface.dav_interface):
|
||||
return "text/html"
|
||||
pool = pooler.get_pool(dbname)
|
||||
cursor = pooler.get_db(dbname).cursor()
|
||||
directory_obj = pool.get('webdav.directory')
|
||||
res = directory_obj.get_contenttype(cursor, int(USER_ID), dburi)
|
||||
collection_obj = pool.get('webdav.collection')
|
||||
res = collection_obj.get_contenttype(cursor, int(USER_ID), dburi)
|
||||
cursor.close()
|
||||
return res
|
||||
|
||||
@@ -187,8 +187,8 @@ class TrytonDAVInterface(iface.dav_interface):
|
||||
return time.time()
|
||||
pool = pooler.get_pool(dbname)
|
||||
cursor = pooler.get_db(dbname).cursor()
|
||||
directory_obj = pool.get('webdav.directory')
|
||||
res = directory_obj.get_creationdate(cursor, int(USER_ID), dburi)
|
||||
collection_obj = pool.get('webdav.collection')
|
||||
res = collection_obj.get_creationdate(cursor, int(USER_ID), dburi)
|
||||
cursor.close()
|
||||
return res
|
||||
|
||||
@@ -198,8 +198,8 @@ class TrytonDAVInterface(iface.dav_interface):
|
||||
return time.time()
|
||||
pool = pooler.get_pool(dbname)
|
||||
cursor = pooler.get_db(dbname).cursor()
|
||||
directory_obj = pool.get('webdav.directory')
|
||||
res = directory_obj.get_lastmodified(cursor, int(USER_ID), dburi)
|
||||
collection_obj = pool.get('webdav.collection')
|
||||
res = collection_obj.get_lastmodified(cursor, int(USER_ID), dburi)
|
||||
cursor.close()
|
||||
return res
|
||||
|
||||
@@ -209,10 +209,10 @@ class TrytonDAVInterface(iface.dav_interface):
|
||||
raise DAV_Forbidden
|
||||
pool = pooler.get_pool(dbname)
|
||||
cursor = pooler.get_db(dbname).cursor()
|
||||
directory_obj = pool.get('webdav.directory')
|
||||
collection_obj = pool.get('webdav.collection')
|
||||
try:
|
||||
try:
|
||||
res = directory_obj.rmcol(cursor, int(USER_ID), dburi)
|
||||
res = collection_obj.rmcol(cursor, int(USER_ID), dburi)
|
||||
cursor.commit()
|
||||
except:
|
||||
cursor.rollback()
|
||||
@@ -227,10 +227,10 @@ class TrytonDAVInterface(iface.dav_interface):
|
||||
raise DAV_Forbidden
|
||||
pool = pooler.get_pool(dbname)
|
||||
cursor = pooler.get_db(dbname).cursor()
|
||||
directory_obj = pool.get('webdav.directory')
|
||||
collection_obj = pool.get('webdav.collection')
|
||||
try:
|
||||
try:
|
||||
res = directory_obj.rm(cursor, int(USER_ID), dburi)
|
||||
res = collection_obj.rm(cursor, int(USER_ID), dburi)
|
||||
cursor.commit()
|
||||
except:
|
||||
cursor.rollback()
|
||||
@@ -245,8 +245,8 @@ class TrytonDAVInterface(iface.dav_interface):
|
||||
return 1
|
||||
pool = pooler.get_pool(dbname)
|
||||
cursor = pooler.get_db(dbname).cursor()
|
||||
directory_obj = pool.get('webdav.directory')
|
||||
res = directory_obj.exists(cursor, int(USER_ID), dburi)
|
||||
collection_obj = pool.get('webdav.collection')
|
||||
res = collection_obj.exists(cursor, int(USER_ID), dburi)
|
||||
cursor.close()
|
||||
return res
|
||||
|
||||
|
||||
Reference in New Issue
Block a user