[MERGE] trunk
[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             # to remove soon-ish
22             action_id = rpc.RPCProxy('ir.actions.act_window').search(
23                 [('view_id','=',int(view_id))], context=context)
24             if not action_id: return ""
25
26             action_id = action_id[0]
27
28         domain = ast.literal_eval(domain)
29         domain.extend(ast.literal_eval(search_domain))
30
31         scheme, netloc, _, _, _ = urlparse.urlsplit(cherrypy.request.base)
32         share_root_url = urlparse.urlunsplit((
33             scheme, netloc, '/openerp/login',
34             'db=%(dbname)s&user=%(login)s&password=%(password)s', ''))
35
36         context.update(
37             #active_ids=share_wiz_id,
38             #active_id=share_wiz_id[0],
39             _terp_view_name='Share Wizard',
40             share_root_url=share_root_url)
41         Share = rpc.RPCProxy('share.wizard')
42         sharing_view_id = Share.create({
43             'domain': str(domain),
44             'action_id': action_id and int(action_id)
45         }, context)
46         return openerp.controllers.actions.execute(
47             Share.go_step_1([sharing_view_id], context),
48             ids=[sharing_view_id], context=context)