Files
odoo_source/addons/website/wizard/base_language_install.py
T
Ravi Gadhia fd09ddb6f3 [MIG] website: migration to new api
Migration of website module to new API.
The tricky phase is ir_http.py : we need to use `request.env`
only when the authenfication phase is done. Normally by
calling `super` of `_dispatch` method, but website module
required it to be done before. This is important since
`env`is a lazy property of `request` object.

Some hack were kept since this commit is a migration ('RequestUID'
in ir.http, ...)

Some docstrings were added.
2016-08-04 12:02:14 +02:00

37 lines
1.3 KiB
Python

# -*- encoding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
class BaseLanguageInstall(models.TransientModel):
_inherit = "base.language.install"
website_ids = fields.Many2many('website', string='Websites to translate')
@api.model
def default_get(self, fields):
defaults = super(BaseLanguageInstall, self).default_get(fields)
website_id = self._context.get('params', {}).get('website_id')
if website_id:
if 'website_ids' not in defaults:
defaults['website_ids'] = []
defaults['website_ids'].append(website_id)
return defaults
@api.multi
def lang_install(self):
action = super(BaseLanguageInstall, self).lang_install()
lang = self.env['res.lang'].search([('code', '=', self.lang)], limit=1)
if self.website_ids and lang:
self.website_ids.write({'language_ids': [(4, lang.id)]})
params = self._context.get('params', {})
if 'url_return' in params:
return {
'url': params['url_return'].replace('[lang]', self.lang),
'type': 'ir.actions.act_url',
'target': 'self'
}
return action