[FIX] ir ui view should have rendering context on request.website_enabled

bzr revid: fme@openerp.com-20140206143919-f6vz8rpx9mb4798g
This commit is contained in:
Fabien Meghazi 2014-02-06 15:39:19 +01:00
parent 1e4d99eede
commit b112d5d2f1
2 changed files with 49 additions and 32 deletions

View File

@ -1,8 +1,12 @@
# -*- coding: utf-8 -*-
import copy
import simplejson
import werkzeug
from lxml import etree, html
from openerp.addons.website.models import website
from openerp.http import request
from openerp.osv import osv, fields
class view(osv.osv):
@ -117,6 +121,49 @@ class view(osv.osv):
return arch
def render(self, cr, uid, id_or_xml_id, values=None, engine='ir.qweb', context=None):
if request.website_enabled:
engine='website.qweb'
if isinstance(id_or_xml_id, list):
id_or_xml_id = id_or_xml_id[0]
if isinstance(id_or_xml_id, (int, long)):
id_or_xml_id = self.get_view_xmlid(cr, uid, id_or_xml_id)
if not context:
context = {}
qcontext = context.copy()
qcontext.update(
website=request.website,
url_for=website.url_for,
keep_query=website.keep_query,
slug=website.slug,
res_company=request.website.company_id,
user_id=self.pool.get("res.users").browse(cr, uid, uid),
editable=False,
# TODO: move this in server's ir.ui.view
request=request,
json=simplejson,
quote_plus=werkzeug.url_quote_plus,
)
# add some values
if values:
qcontext.update(values)
# in edit mode ir.ui.view will tag nodes
context['inherit_branding'] = qcontext['editable']
view_obj = request.website.get_template(id_or_xml_id)
if 'main_object' not in qcontext:
qcontext['main_object'] = view_obj
values = qcontext
return super(view, self).render(cr, uid, id_or_xml_id, values=values, engine=engine, context=context)
def save(self, cr, uid, res_id, value, xpath=None, context=None):
""" Update a view section. The view section may embed fields to write

View File

@ -221,7 +221,6 @@ class website(osv.osv):
request.redirect = lambda url: werkzeug.utils.redirect(url_for(url))
request.context.update(
is_master_lang=is_master_lang,
editable=is_website_publisher,
translatable=not is_master_lang,
)
@ -234,37 +233,8 @@ class website(osv.osv):
return self.pool["ir.ui.view"].browse(cr, uid, view_id, context=context)
def _render(self, cr, uid, ids, template, values=None, context=None):
user = self.pool.get("res.users")
if not context:
context = {}
# Take a context
qweb_values = context.copy()
# add some values
if values:
qweb_values.update(values)
# fill some defaults
qweb_values.update(
request=request,
json=simplejson,
website=request.website,
url_for=url_for,
keep_query=keep_query,
slug=slug,
res_company=request.website.company_id,
user_id=user.browse(cr, uid, uid),
quote_plus=werkzeug.url_quote_plus,
)
qweb_values.setdefault('editable', False)
# in edit mode ir.ui.view will tag nodes
context['inherit_branding'] = qweb_values['editable']
view = self.get_template(cr, uid, ids, template)
if 'main_object' not in qweb_values:
qweb_values['main_object'] = view
return view.render(qweb_values, engine='website.qweb', context=context)
# TODO: remove this. (just kept for backward api compatibility for saas-3)
return self.pool['ir.ui.view'].render(cr, uid, template, values=values, context=context)
def render(self, cr, uid, ids, template, values=None, status_code=None, context=None):
def callback(template, values, context):