[FIX] share+portal: fix share wizard.
[odoo/odoo.git] / addons / share / web / controllers.py
1 import urlparse
2 import cherrypy
3
4 from openobject import rpc
5 from openobject.tools import expose, ast
6
7 import openerp.controllers
8
9
10
11 class ShareWizardController(openerp.controllers.SecuredController):
12     _cp_path = "/share"
13
14     @expose()
15     def index(self, domain, context, view_id, search_domain='[]', action_id=None):
16         context = ast.literal_eval(context)
17
18         if not action_id:
19             # This should not be needed anymore, but just in case users are
20             # running the module with an older version of the web client...
21
22             # to remove soon-ish
23             action_id = rpc.RPCProxy('ir.actions.act_window').search(
24                 [('view_id','=',int(view_id))], context=context)
25             if not action_id: return ""
26
27             action_id = action_id[0]
28
29         domain = ast.literal_eval(domain)
30         domain.extend(ast.literal_eval(search_domain))
31
32         scheme, netloc, _, _, _ = urlparse.urlsplit(cherrypy.request.base)
33         share_root_url = urlparse.urlunsplit((
34             scheme, netloc, '/openerp/login',
35             'db=%(dbname)s&user=%(login)s&password=%(password)s', ''))
36
37         context.update(
38             #active_ids=share_wiz_id,
39             #active_id=share_wiz_id[0],
40             _terp_view_name='Share Wizard',
41             share_root_url=share_root_url)
42         Share = rpc.RPCProxy('share.wizard')
43         sharing_view_id = Share.create({
44             'domain': str(domain),
45             'action_id': action_id and int(action_id)
46         }, context)
47         return openerp.controllers.actions.execute(
48             Share.go_step_1([sharing_view_id], context),
49             ids=[sharing_view_id], context=context)