예제 #1
0
	def write(self, cr, uid, ids, vals, context=None):
		result = super(document_file,self).write(cr,uid,ids,vals,context=context)
		try:
			for f in self.browse(cr, uid, ids, context=context):
				if 'datas' not in vals:
					vals['datas']=f.datas
				res = content_index(base64.decodestring(vals['datas']), f.datas_fname, f.file_type or None)
				super(document_file,self).write(cr, uid, ids, {
					'index_content': res
				})
		except:
			pass
		return result
예제 #2
0
    def create(self, cr, uid, vals, context={}):
        vals['title'] = vals['name']
        if vals.get('res_id', False) and vals.get('res_model', False):
            obj_model = self.pool.get(vals['res_model'])
            result = obj_model.browse(cr,
                                      uid, [vals['res_id']],
                                      context=context)
            if len(result):
                vals['title'] = (result[0].name or '')[:60]
                if obj_model._name == 'res.partner':
                    vals['partner_id'] = result[0].id
                elif 'address_id' in result[0]:
                    vals['partner_id'] = result[
                        0].address_id.partner_id.id or False
                else:
                    vals['partner_id'] = 'partner_id' in result[0] and result[
                        0].partner_id.id or False

            if 'parent_id' not in vals:
                obj_directory = self.pool.get('document.directory')
                directory_ids = obj_directory.search(
                    cr, uid, [('ressource_type_id', '=', vals['res_model'])])
                dirs = obj_directory.browse(cr, uid, directory_ids)
                for dir in dirs:
                    if dir.domain:
                        object_ids = obj_model.search(cr, uid,
                                                      eval(dir.domain))
                        if vals['res_id'] in object_ids:
                            vals['parent_id'] = dir.id
        datas = None
        if 'datas' not in vals:
            import urllib
            datas = base64.encodestring(urllib.urlopen(vals['link']).read())
        else:
            datas = vals['datas']
        vals['file_size'] = len(datas)
        result = super(document_file, self).create(cr, uid, vals, context)
        cr.commit()
        try:
            res = content_index(base64.decodestring(datas),
                                vals['datas_fname'],
                                vals.get('content_type', None))
            super(document_file, self).write(cr, uid, [result], {
                'index_content': res,
            })
        except:
            pass
        return result
예제 #3
0
 def write(self, cr, uid, ids, vals, context=None):
     result = super(document_file, self).write(cr,
                                               uid,
                                               ids,
                                               vals,
                                               context=context)
     try:
         for f in self.browse(cr, uid, ids, context=context):
             if 'datas' not in vals:
                 vals['datas'] = f.datas
             res = content_index(base64.decodestring(vals['datas']),
                                 f.datas_fname, f.file_type or None)
             super(document_file, self).write(cr, uid, ids,
                                              {'index_content': res})
     except:
         pass
     return result
예제 #4
0
	def create(self, cr, uid, vals, context={}):
		vals['title']=vals['name']
		if vals.get('res_id', False) and vals.get('res_model',False):
			obj_model=self.pool.get(vals['res_model'])
			result = obj_model.browse(cr, uid, [vals['res_id']], context=context)
			if len(result):
				vals['title'] = (result[0].name or '')[:60]
				if obj_model._name=='res.partner':
					vals['partner_id']=result[0].id
				elif 'address_id' in result[0]:
					vals['partner_id']=result[0].address_id.partner_id.id or False
				else:
					vals['partner_id']='partner_id' in result[0] and result[0].partner_id.id or False

			if 'parent_id' not in vals:
				obj_directory=self.pool.get('document.directory')
				directory_ids=obj_directory.search(cr,uid,[('ressource_type_id','=',vals['res_model'])])
				dirs=obj_directory.browse(cr,uid,directory_ids)
				for dir in dirs:
					if dir.domain:
						object_ids=obj_model.search(cr,uid,eval(dir.domain))
						if vals['res_id'] in object_ids:
							vals['parent_id']=dir.id
		datas=None
		if 'datas' not in vals:
			import urllib
			datas=base64.encodestring(urllib.urlopen(vals['link']).read())
		else:
			datas=vals['datas']
		vals['file_size']= len(datas)
		result = super(document_file,self).create(cr, uid, vals, context)
		cr.commit()
		try:
			res = content_index(base64.decodestring(datas), vals['datas_fname'], vals.get('content_type', None))
			super(document_file,self).write(cr, uid, [result], {
				'index_content': res,
			})
		except:
			pass
		return result