Use name instead of datas_fname for attachment and fix _constraints

inheritance
This commit is contained in:
Cédric Krier committed 2008-02-17 02:18:19 +01:00
1 parent 311ecc3b2b
commit ac5cf79812
4 files changed
+15 -18

No files matched your search

+2 -3
View File
@@ -13,7 +13,6 @@ class Attachment(OSV):
'name': fields.Char('Attachment Name',size=64, required=True),
'datas': fields.Function('datas', fnct_inv='datas_inv',
type='binary', string='Datas'),
'datas_fname': fields.Char('Data Filename',size=64),
'description': fields.Text('Description'),
'res_model': fields.Char('Resource Model',size=64,
readonly=True, required=True),
@@ -29,8 +28,8 @@ class Attachment(OSV):
'collision': lambda *a: 0,
}
_sql_constraints = [
('res_model_res_id_datas_fname',
'UNIQUE (res_model, res_id, datas_fname)',
('res_model_res_id_name',
'UNIQUE (res_model, res_id, name)',
'Error! You can not create attachment with the same name!'),
]
+4 -6
View File
@@ -6,19 +6,17 @@
<field name="type">form</field>
<field name="arch" type="xml">
<![CDATA[
<form string="Attachments" col="6">
<form string="Attachments">
<label name="name"/>
<field name="name"/>
<label name="res_model"/>
<field name="res_model"/>
<label name="res_id"/>
<field name="res_id"/>
<label name="datas_fname"/>
<field name="datas_fname"/>
<label name="datas"/>
<field name="datas" colspan="3"/>
<separator name="description" colspan="6"/>
<field name="description" colspan="6"/>
<field name="datas"/>
<separator name="description" colspan="4"/>
<field name="description" colspan="4"/>
</form>
]]>
</field>
-1
View File
@@ -33,7 +33,6 @@ field,"ir.action,usage",0,Usage,Utilisation,0
field,"ir.action.wizard,action",0,Action,Action,0
field,"ir.action.wizard,wiz_name",0,Wizard name,Nom du wizard,0
field,"ir.attachment,datas",0,Data,Donnée,0
field,"ir.attachment,datas_fname",0,Data Filename,Nom de fichier donnée,0
field,"ir.attachment,description",0,Description,Description,0
field,"ir.attachment,link",0,Link,Lien,0
field,"ir.attachment,name",0,Attachment Name,Nom de l'attachement,0
1 type name res_id src value fuzzy
33 field ir.action.wizard,action 0 Action Action 0
34 field ir.action.wizard,wiz_name 0 Wizard name Nom du wizard 0
35 field ir.attachment,datas 0 Data Donnée 0
field ir.attachment,datas_fname 0 Data Filename Nom de fichier donnée 0
36 field ir.attachment,description 0 Description Description 0
37 field ir.attachment,link 0 Link Lien 0
38 field ir.attachment,name 0 Attachment Name Nom de l'attachement 0
+9 -8
View File
@@ -48,7 +48,7 @@ class Directory(OSV):
])
for attachment in attachment_obj.browse(cursor, user,
attachment_ids):
if attachment.datas_fname == directory.name:
if attachment.name == directory.name:
return False
return True
@@ -75,7 +75,7 @@ class Directory(OSV):
attachment_ids = attachment_obj.search(cursor, user, [
('res_model', '=', object_name),
('res_id', '=', object_id),
('datas_fname', '=', name),
('name', '=', name),
], limit=1, context=context)
if attachment_ids:
object_name = 'ir.attachment'
@@ -91,7 +91,7 @@ class Directory(OSV):
attachment_ids = attachment_obj.search(cursor, user, [
('res_model', '=', object_name),
('res_id', '=', object_id),
('datas_fname', '=', name),
('name', '=', name),
], limit=1, context=context)
if attachment_ids:
object_name = 'ir.attachment'
@@ -139,8 +139,8 @@ class Directory(OSV):
], context=context)
for attachment in attachment_obj.browse(cursor, user, attachment_ids,
context=context):
if attachment.datas_fname and not attachment.link:
res.append(attachment.datas_fname)
if attachment.name and not attachment.link:
res.append(attachment.name)
return res
def get_resourcetype(self, cursor, user, uri, context=None):
@@ -225,7 +225,7 @@ class Directory(OSV):
attachment_obj.create(cursor, user, {
'name': name,
'datas': base64.encodestring(data),
'datas_fname': name,
'name': name,
'res_model': object_name,
'res_id': object_id,
}, context=context)
@@ -301,11 +301,12 @@ class Attachment(OSV):
def __init__(self, pool):
super(Attachment, self).__init__(pool)
self._constraints.append(
self._constraints = self._constraints + [
('check_directory',
'Error! You can not create a attachment \n' \
'on a directory that have the same name \n' \
'than a child directory.', ['datas_fname']))
'than a child directory.', ['name']),
]
def check_directory(self, cursor, user, ids):
directory_obj = self.pool.get('webdav.directory')