[MERGE] [IMP] website: server actions: usability improvements
- added website_path, used to compute the full URL allowing to access the server action. This allows more custom and short URLs, like website/action/partners instead of website/action/website.action_partners; - added website_url, computed file with the full URL of the server action that is displayed on the form view, to ease usability. - added a filter for server action, to easily find code and published server actions - updated server action controller: now takes xml_id, id, or website_path bzr revid: tde@openerp.com-20140212111609-55mkck2tu1zkeley
This commit is contained in:
commit
5e0ef7071c
|
@ -378,20 +378,25 @@ class Website(openerp.addons.web.controllers.main.Home):
|
|||
#------------------------------------------------------
|
||||
# Server actions
|
||||
#------------------------------------------------------
|
||||
@http.route(['/website/action/<id_or_xml_id>'], type='http', auth="public", website=True)
|
||||
def actions_server(self, id_or_xml_id, **post):
|
||||
|
||||
@http.route('/website/action/<path_or_xml_id_or_id>', 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_published', '=', 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)
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
<field name="name">Website Partner Post and Thanks Demo</field>
|
||||
<field name="condition">True</field>
|
||||
<field name="website_published" eval="True"/>
|
||||
<field name="website_path">partner_thanks</field>
|
||||
<field name="model_id" ref="base.model_res_partner"/>
|
||||
<field name="code">
|
||||
partner_id, partner = False, None
|
||||
|
@ -118,6 +119,7 @@ response = request.website.render("website.template_partner_post", values)
|
|||
<field name="name">Website Partners Comment Form</field>
|
||||
<field name="condition">True</field>
|
||||
<field name="website_published" eval="True"/>
|
||||
<field name="website_path">partner_comment</field>
|
||||
<field name="model_id" ref="base.model_res_partner"/>
|
||||
<field name="code">
|
||||
partner_ids = pool['res.partner'].search(cr, uid, [('customer', '=', True)], context=context)
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import urlparse
|
||||
|
||||
from openerp.addons.web.http import request
|
||||
from openerp.osv import fields, osv
|
||||
|
||||
|
@ -9,15 +11,43 @@ 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):
|
||||
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 = {
|
||||
'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_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 <base>/website/action/<id_or_xml_id>.'
|
||||
'controller. The address is <base>/website/action/<website_path>.'
|
||||
'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.'),
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
|
@ -6,10 +6,43 @@
|
|||
<field name="name">ir.actions.server.form.website</field>
|
||||
<field name="model">ir.actions.server</field>
|
||||
<field name="inherit_id" ref="base.view_server_action_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<data>
|
||||
<xpath expr="//field[@name='state']" position="after">
|
||||
<field name="website_published"
|
||||
attrs="{'invisible': [('state', '!=', 'code')]}"/>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='sequence']" position="after">
|
||||
<field name="xml_id" invisible="1"/>
|
||||
<field name="website_path"
|
||||
on_change="on_change_website_path(website_path, xml_id, context)"
|
||||
attrs="{'invisible': ['|', ('website_published', '!=', True), ('state', '!=', 'code')]}"/>
|
||||
<field name="website_url" readonly="1"
|
||||
attrs="{'invisible': ['|', ('website_published', '!=', True), ('state', '!=', 'code')]}"/>
|
||||
</xpath>
|
||||
</data>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="view_server_action_tree_website">
|
||||
<field name="name">ir.actions.server.tree.website</field>
|
||||
<field name="model">ir.actions.server</field>
|
||||
<field name="inherit_id" ref="base.view_server_action_tree"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='sequence']" position="after">
|
||||
<field name="website_url"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="view_server_action_search_website">
|
||||
<field name="name">ir.actions.server.search.website</field>
|
||||
<field name="model">ir.actions.server</field>
|
||||
<field name="inherit_id" ref="base.view_server_action_search"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='state']" position="after">
|
||||
<field name="website_published"
|
||||
attrs="{'invisible': [('state', '!=', 'code')]}"/>
|
||||
<filter string="Website" name="website"
|
||||
domain="[('website_published', '=', True), ('state', '=', 'code')]"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
|
Loading…
Reference in New Issue