Files
odoo_source/addons/website/models/ir_actions.py
T
Raphael Collet 4ddc323139 [FIX] base: fix and complete migration of base/ir
- add or fix decorators on methods
- fix most compute methods (wrong dependencies)
- revert changes in `eval_context` of `ir.actions`
- various code simplifications and improvements
- migrate methods that were not
- ir_qweb: modify `QWebContext` to take an environment instead of `cr`, `uid`, `context`
- ir_qweb: convert `AssetsBundle` to use new API `env`
- ir_ui_view: use decorator `multi` on method `read_combined`
- ir_ui_view: ensure that method `render` is never called with an xml_id
- ir_ui_view: factor out part of the `ormcache` key of method `_read_template`
2016-03-21 13:46:44 +01:00

58 lines
2.6 KiB
Python

# -*- coding: utf-8 -*-
import urlparse
from odoo import api, fields, models
from odoo.http import request
class actions_server(models.Model):
""" Add website option in server actions. """
_name = 'ir.actions.server'
_inherit = 'ir.actions.server'
xml_id = fields.Char(compute='_compute_xml_id', string="External ID",
help="ID of the action if defined in a XML file")
website_path = fields.Char()
website_url = fields.Char(compute='_get_website_url', help='The full URL to access the server action through the website.')
website_published = fields.Boolean(string='Available on the Website', copy=False,
help='A code server action can be executed from the website, using a dedicated '
'controller. The address is <base>/website/action/<website_path>. '
'Set this field as True to allow users to run this action. If it '
'is set to False the action cannot be run through the website.')
def _compute_xml_id(self):
res = self.get_external_id()
for action in self:
action.xml_id = res.get(action.id)
def _compute_website_url(self, website_path, xml_id):
base_url = self.env['ir.config_parameter'].get_param('web.base.url')
link = website_path or xml_id or (self.id and '%d' % self.id) or ''
if base_url and link:
path = '%s/%s' % ('/website/action', link)
return '%s' % urlparse.urljoin(base_url, path)
return ''
@api.depends('state', 'website_published', 'website_path', 'xml_id')
def _get_website_url(self):
for action in self:
if action.state == 'code' and action.website_published:
action.website_url = self._compute_website_url(action.website_path, action.xml_id)
@api.model
def _get_eval_context(self, action):
""" Override to add the request object in eval_context. """
eval_context = super(actions_server, self)._get_eval_context(action)
if action.state == 'code':
eval_context['request'] = request
return eval_context
@api.model
def run_action_code_multi(self, action, eval_context=None):
""" Override to allow returning response the same way action is already
returned by the basic server action behavior. Note that response has
priority over action, avoid using both. """
res = super(actions_server, self).run_action_code_multi(action, eval_context)
return eval_context.get('response', res)