Skip to content

Commit

Permalink
[IMP] website: set viewid in frontend & save template for dispatch
Browse files Browse the repository at this point in the history
This commit is related to enterprise commit adding crm_track option to @routes.

Before this commit:
1. We could not get template's name after dispatch() had been
called. Indeed, it will remove the template name from the response
(response.flatten()) to make it not considered as 'qweb' anymore (is_qweb()).
We need the template in some case.
Eg: In case of website_crm_score, after the dispatch() we still need the
template's name to retrieve the @route's view being rendered to check if it was
trackable or not.
2. To make an RPC that directly READ or WRITE to a record, we need its ID.
In case of a page with a main object other than ir.ui.view, we would need to
make extra RPC to get the view's id of the page based on the view's name that
we got on the HTML data attributes.

Now:
1. On response's INIT, we store a copy of the template's name.
2. We set the view's ID on HTML data attributes clientside.
  • Loading branch information
rdeodoo committed Oct 18, 2017
1 parent 542b8fd commit 3975065
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions addons/website/views/website_templates.xml
Expand Up @@ -98,6 +98,7 @@
'data-translatable': '1' if translatable else None,
'data-edit_translations': '1' if edit_translations else None,
'data-view-xmlid': xmlid if editable or translatable else None,
'data-viewid': viewid if editable or translatable else None,
'data-main-object': repr(main_object) if editable or translatable else None,
'data-oe-company-name': res_company.name
}"/>
Expand Down
1 change: 1 addition & 0 deletions odoo/addons/base/ir/ir_ui_view.py
Expand Up @@ -1078,6 +1078,7 @@ def _prepare_qcontext(self):
datetime=datetime,
relativedelta=relativedelta,
xmlid=self.key,
viewid=self.id,
)
return qcontext

Expand Down
2 changes: 2 additions & 0 deletions odoo/http.py
Expand Up @@ -1211,13 +1211,15 @@ class Response(werkzeug.wrappers.Response):
default_mimetype = 'text/html'
def __init__(self, *args, **kw):
template = kw.pop('template', None)
copy_template = template
qcontext = kw.pop('qcontext', None)
uid = kw.pop('uid', None)
super(Response, self).__init__(*args, **kw)
self.set_default(template, qcontext, uid)

def set_default(self, template=None, qcontext=None, uid=None):
self.template = template
self.copy_template = template
self.qcontext = qcontext or dict()
self.uid = uid
# Support for Cross-Origin Resource Sharing
Expand Down

0 comments on commit 3975065

Please sign in to comment.