[FIX] rename ir.actions.url to match action's type
[odoo/odoo.git] / addons / document_ftp / wizard / ftp_browse.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 ##############################################################################
21
22 from osv import osv, fields
23 # from tools.translate import _
24 from .. import ftpserver
25
26 class document_ftp_browse(osv.osv_memory):
27     _name = 'document.ftp.browse'
28     _description = 'Document FTP Browse'
29
30     _columns = {
31         'url' : fields.char('FTP Server', size=64, required=True),
32     }
33
34     def default_get(self, cr, uid, fields, context=None):
35         res = {}
36         if 'url' in fields:
37             user_pool = self.pool.get('res.users')
38             current_user = user_pool.browse(cr, uid, uid, context=context)
39             data_pool = self.pool.get('ir.model.data')
40             aid = data_pool._get_id(cr, uid, 'document_ftp', 'action_document_browse')
41             aid = data_pool.browse(cr, uid, aid, context=context).res_id
42             ftp_url = self.pool.get('ir.actions.act_url').browse(cr, uid, aid, context=context)
43             url = ftp_url.url and ftp_url.url.split('ftp://') or []
44             if url:
45                 url = url[1]
46                 if url[-1] == '/':
47                     url = url[:-1]
48             else:
49                 url = '%s:%s' %(ftpserver.HOST, ftpserver.PORT)
50             res['url'] = 'ftp://%s@%s'%(current_user.login, url)
51         return res
52
53     def browse_ftp(self, cr, uid, ids, context=None):
54         data_id = ids and ids[0] or False
55         data = self.browse(cr, uid, data_id, context=context)
56         final_url = data.url
57         return {
58         'type': 'ir.actions.act_url',
59         'url':final_url,
60         'target': 'new'
61         }
62
63 document_ftp_browse()
64
65 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: