From 7d696bc620e90797ada8bb6d0a07fd92000eb204 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 7 Feb 2014 13:19:21 +0100 Subject: [PATCH 1/7] [IMP] website: server actions: usability improvements - added website_path, the end of the path to access the server action, allowing more custom and short URLs, like website/action/partners instead of website/action/website.action_partners; - added website_url, computed file with the full address of the server action that is displayed on the form view, to ease usability - updated server action contorller: now takes xml_id, id, or website_path bzr revid: tde@openerp.com-20140207121921-7kdpxrf30zlte47l --- addons/website/controllers/main.py | 20 ++++++++++++------- addons/website/models/ir_actions.py | 30 +++++++++++++++++++++++++++++ addons/website/views/ir_actions.xml | 26 +++++++++++++++++++++++-- 3 files changed, 67 insertions(+), 9 deletions(-) diff --git a/addons/website/controllers/main.py b/addons/website/controllers/main.py index e97a3be9d97..cbfab26475f 100644 --- a/addons/website/controllers/main.py +++ b/addons/website/controllers/main.py @@ -369,20 +369,26 @@ class Website(openerp.addons.web.controllers.main.Home): #------------------------------------------------------ # Server actions #------------------------------------------------------ - @http.route(['/website/action/'], type='http', auth="public", website=True) - def actions_server(self, id_or_xml_id, **post): + _server_action_route = '/website/action' + + @http.route('%s/' % _server_action_route, type='http', auth="public", website=True) + def actions_server(self, path_or_xml_id_or_id, **post): cr, uid, context = request.cr, request.uid, request.context res, action_id, action = None, None, None ServerActions = request.registry['ir.actions.server'] - # find the action_id, either an int, an int into a basestring, or an xml_id - if isinstance(id_or_xml_id, basestring) and '.' in id_or_xml_id: - action_id = request.registry['ir.model.data'].xmlid_to_res_id(request.cr, request.uid, id_or_xml_id, raise_if_not_found=False) - else: + # find the action_id: either an xml_id, the path, or an ID + if isinstance(path_or_xml_id_or_id, basestring) and '.' in path_or_xml_id_or_id: + action_id = request.registry['ir.model.data'].xmlid_to_res_id(request.cr, request.uid, path_or_xml_id_or_id, raise_if_not_found=False) + if not action_id: + action_ids = ServerActions.search(cr, uid, [('website_path', '=', path_or_xml_id_or_id), ('website_publihsed', '=', True)], context=context) + action_id = action_ids and action_ids[0] or None + if not action_id: try: - action_id = int(id_or_xml_id) + action_id = int(path_or_xml_id_or_id) except ValueError: pass + # check it effectively exists if action_id: action_ids = ServerActions.exists(cr, uid, [action_id], context=context) diff --git a/addons/website/models/ir_actions.py b/addons/website/models/ir_actions.py index 731ee4c47e6..361191d6835 100644 --- a/addons/website/models/ir_actions.py +++ b/addons/website/models/ir_actions.py @@ -1,6 +1,9 @@ # -*- coding: utf-8 -*- +import urlparse + from openerp.addons.web.http import request +# from openerp.addons.website.controllers.main import Website from openerp.osv import fields, osv @@ -9,7 +12,28 @@ class actions_server(osv.Model): _name = 'ir.actions.server' _inherit = ['ir.actions.server'] + def _compute_website_url(self, cr, uid, id, website_path, xml_id, context=None): + base_url = self.pool['ir.config_parameter'].get_param(cr, uid, 'web.base.url', context=context) + link = website_path or xml_id or (id and '%d' % id) or '' + if base_url and link: + path = '%s/%s' % ('/website/action', link) + return '%s' % urlparse.urljoin(base_url, path) + return '' + + def _get_website_url(self, cr, uid, ids, name, args, context=None): + res = dict.fromkeys(ids, False) + for action in self.browse(cr, uid, ids, context=context): + res[action.id] = self._compute_website_url(cr, uid, action.id, action.website_path, action.xml_id, context=context) + return res + _columns = { + 'xml_id': fields.function( + osv.osv.get_xml_id, type='char', string="External ID", + help="ID of the action if defined in a XML file"), + 'website_url': fields.function( + _get_website_url, type='char', string='Website URL', + help='The full URL to access the server action through the website.'), + 'website_path': fields.char('Website Path'), 'website_published': fields.boolean( 'Available on the Website', help='A code server action can be executed from the website, using a dedicated' @@ -18,6 +42,12 @@ class actions_server(osv.Model): 'set to is False the action cannot be run through the website.'), } + def on_change_website_path(self, cr, uid, ids, website_path, xml_id, context=None): + values = { + 'website_url': self._compute_website_url(cr, uid, ids[0], website_path, xml_id, context=context) + } + return {'value': values} + def _get_eval_context(self, cr, uid, action, context=None): """ Override to add the request object in eval_context. """ eval_context = super(actions_server, self)._get_eval_context(cr, uid, action, context=context) diff --git a/addons/website/views/ir_actions.xml b/addons/website/views/ir_actions.xml index 0b017a43192..5b7f80df2a7 100644 --- a/addons/website/views/ir_actions.xml +++ b/addons/website/views/ir_actions.xml @@ -6,10 +6,32 @@ ir.actions.server.form.website ir.actions.server + + + + + + + + + + + + + + + + ir.actions.server.search.website + ir.actions.server + - + From 21602f92a107ba1ea585354044c65ee140225d00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 7 Feb 2014 13:32:49 +0100 Subject: [PATCH 2/7] [FIX] website: server action: compute website_url only for published code actions bzr revid: tde@openerp.com-20140207123249-yfql78xurblyamze --- addons/website/models/ir_actions.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/website/models/ir_actions.py b/addons/website/models/ir_actions.py index 361191d6835..f6d98bf3632 100644 --- a/addons/website/models/ir_actions.py +++ b/addons/website/models/ir_actions.py @@ -23,7 +23,8 @@ class actions_server(osv.Model): def _get_website_url(self, cr, uid, ids, name, args, context=None): res = dict.fromkeys(ids, False) for action in self.browse(cr, uid, ids, context=context): - res[action.id] = self._compute_website_url(cr, uid, action.id, action.website_path, action.xml_id, context=context) + if action.state == 'code' and action.website_published: + res[action.id] = self._compute_website_url(cr, uid, action.id, action.website_path, action.xml_id, context=context) return res _columns = { From 167ac762ca1dc18fb038520056bcb8416caac3d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 7 Feb 2014 13:33:01 +0100 Subject: [PATCH 3/7] [IMP] website: server action: display website_url in tree view bzr revid: tde@openerp.com-20140207123301-4guyw8ay4e6fghuj --- addons/website/views/ir_actions.xml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/addons/website/views/ir_actions.xml b/addons/website/views/ir_actions.xml index 5b7f80df2a7..0573c87af31 100644 --- a/addons/website/views/ir_actions.xml +++ b/addons/website/views/ir_actions.xml @@ -24,6 +24,17 @@ + + ir.actions.server.tree.website + ir.actions.server + + + + + + + + ir.actions.server.search.website ir.actions.server From c27dfb92ea9240a3b832a7ec2ac99063855db2d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 7 Feb 2014 13:33:55 +0100 Subject: [PATCH 4/7] [IMP] website: server action: demo data now have website_path bzr revid: tde@openerp.com-20140207123355-t3hxvqxjr5p8p0du --- addons/website/data/website_demo.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/addons/website/data/website_demo.xml b/addons/website/data/website_demo.xml index a7fa4d76a07..6f37b871100 100644 --- a/addons/website/data/website_demo.xml +++ b/addons/website/data/website_demo.xml @@ -43,6 +43,7 @@ Website Partner Post and Thanks Demo True + partner_thanks partner_id, partner = False, None @@ -118,6 +119,7 @@ response = request.website.render("website.template_partner_post", values) Website Partners Comment Form True + partner_comment partner_ids = pool['res.partner'].search(cr, uid, [('customer', '=', True)], context=context) From 3c3bff14c099c52d2a77134010ae4b591e613c55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 12 Feb 2014 11:37:53 +0100 Subject: [PATCH 5/7] [CLEAN] website: server action controllers: removed unnecessary variable bzr revid: tde@openerp.com-20140212103753-8fheizloj3minlt6 --- addons/website/controllers/main.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/addons/website/controllers/main.py b/addons/website/controllers/main.py index cbfab26475f..85c17f301b6 100644 --- a/addons/website/controllers/main.py +++ b/addons/website/controllers/main.py @@ -369,9 +369,8 @@ class Website(openerp.addons.web.controllers.main.Home): #------------------------------------------------------ # Server actions #------------------------------------------------------ - _server_action_route = '/website/action' - @http.route('%s/' % _server_action_route, type='http', auth="public", website=True) + @http.route('/website/action/', type='http', auth="public", website=True) def actions_server(self, path_or_xml_id_or_id, **post): cr, uid, context = request.cr, request.uid, request.context res, action_id, action = None, None, None From 4c11416db6269a0f0e4a76e03dfb0f9cb659867b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 12 Feb 2014 11:39:12 +0100 Subject: [PATCH 6/7] [FIX] website: server action controllers: fixed typo in a domain bzr revid: tde@openerp.com-20140212103912-1rhyl3wxa2a084ls --- addons/website/controllers/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/website/controllers/main.py b/addons/website/controllers/main.py index c754fd81e00..5a5226cef81 100644 --- a/addons/website/controllers/main.py +++ b/addons/website/controllers/main.py @@ -389,7 +389,7 @@ class Website(openerp.addons.web.controllers.main.Home): if isinstance(path_or_xml_id_or_id, basestring) and '.' in path_or_xml_id_or_id: action_id = request.registry['ir.model.data'].xmlid_to_res_id(request.cr, request.uid, path_or_xml_id_or_id, raise_if_not_found=False) if not action_id: - action_ids = ServerActions.search(cr, uid, [('website_path', '=', path_or_xml_id_or_id), ('website_publihsed', '=', True)], context=context) + action_ids = ServerActions.search(cr, uid, [('website_path', '=', path_or_xml_id_or_id), ('website_published', '=', True)], context=context) action_id = action_ids and action_ids[0] or None if not action_id: try: From 19d9b7309d8223f3550965d7e29aad1d48c1d41c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 12 Feb 2014 11:42:27 +0100 Subject: [PATCH 7/7] [CLEAN] website: ir_actions: removed commented line + small reordering of columns definition + fixed an help string bzr revid: tde@openerp.com-20140212104227-bd2rsrewqizmxtf3 --- addons/website/models/ir_actions.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/addons/website/models/ir_actions.py b/addons/website/models/ir_actions.py index f6d98bf3632..5f627eec54a 100644 --- a/addons/website/models/ir_actions.py +++ b/addons/website/models/ir_actions.py @@ -3,7 +3,6 @@ import urlparse from openerp.addons.web.http import request -# from openerp.addons.website.controllers.main import Website from openerp.osv import fields, osv @@ -31,14 +30,14 @@ class actions_server(osv.Model): 'xml_id': fields.function( osv.osv.get_xml_id, type='char', string="External ID", help="ID of the action if defined in a XML file"), + 'website_path': fields.char('Website Path'), 'website_url': fields.function( _get_website_url, type='char', string='Website URL', help='The full URL to access the server action through the website.'), - 'website_path': fields.char('Website Path'), 'website_published': fields.boolean( 'Available on the Website', help='A code server action can be executed from the website, using a dedicated' - 'controller. The address is /website/action/.' + 'controller. The address is /website/action/.' 'Set this field as True to allow users to run this action. If it' 'set to is False the action cannot be run through the website.'), }