[IMP] Merge bananas and cumcumbers in order to prepare the t-href|t-action removal
bzr revid: fme@openerp.com-20140128201417-1elmttz8qen9q3ws
This commit is contained in:
parent
adac86d0ce
commit
326c35aecd
|
@ -40,27 +40,24 @@ class QWeb(orm.AbstractModel):
|
||||||
URL_ATTRS = {
|
URL_ATTRS = {
|
||||||
'form': 'action',
|
'form': 'action',
|
||||||
'a': 'href',
|
'a': 'href',
|
||||||
'link': 'href',
|
|
||||||
'frame': 'src',
|
|
||||||
'iframe': 'src',
|
|
||||||
'script': 'src',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def add_template(self, into, name, node, context):
|
def add_template(self, qcontext, name, node):
|
||||||
# preprocessing for multilang static urls
|
# preprocessing for multilang static urls
|
||||||
if request and 'url_for' in context:
|
if request.website:
|
||||||
router = request.httprequest.app.get_db_router(request.db).bind('')
|
|
||||||
for tag, attr in self.URL_ATTRS.items():
|
for tag, attr in self.URL_ATTRS.items():
|
||||||
for e in node.getElementsByTagName(tag):
|
for e in node.getElementsByTagName(tag):
|
||||||
url = e.getAttribute(attr)
|
url = e.getAttribute(attr)
|
||||||
if url:
|
if url:
|
||||||
try:
|
e.setAttribute(attr, qcontext.get('url_for')(url))
|
||||||
func = router.match(url)[0]
|
super(QWeb, self).add_template(qcontext, name, node)
|
||||||
if func.multilang:
|
|
||||||
e.setAttribute(attr, context['url_for'](url))
|
def render_att_att(self, element, attribute_name, attribute_value, qwebcontext):
|
||||||
except Exception, e:
|
att, val = super(QWeb, self).render_att_att(element, attribute_name, attribute_value, qwebcontext)
|
||||||
pass
|
|
||||||
super(QWeb, self).add_template(into, name, node, context)
|
if request.website and att == self.URL_ATTRS.get(element.nodeName) and isinstance(val, basestring):
|
||||||
|
val = qwebcontext.get('url_for')(val)
|
||||||
|
return att, val
|
||||||
|
|
||||||
def get_converter_for(self, field_type):
|
def get_converter_for(self, field_type):
|
||||||
return self.pool.get(
|
return self.pool.get(
|
||||||
|
|
|
@ -25,34 +25,44 @@ from openerp.addons.web.http import request, LazyResponse
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
def url_for(path_or_uri, lang=None, keep_query=None):
|
def keep_query(*args, **kw):
|
||||||
|
if not args and not kw:
|
||||||
|
args = ('*',)
|
||||||
|
params = kw.copy()
|
||||||
|
query_params = frozenset(werkzeug.url_decode(request.httprequest.query_string).keys())
|
||||||
|
for keep_param in args:
|
||||||
|
for param in fnmatch.filter(query_params, keep_param):
|
||||||
|
if param not in params and param in request.params:
|
||||||
|
params[param] = request.params[param]
|
||||||
|
return werkzeug.urls.url_encode(params)
|
||||||
|
|
||||||
|
def url_for(path_or_uri, lang=None):
|
||||||
location = path_or_uri.strip()
|
location = path_or_uri.strip()
|
||||||
url = urlparse.urlparse(location)
|
url = urlparse.urlparse(location)
|
||||||
if request and not url.netloc and not url.scheme:
|
if request and not url.netloc and not url.scheme:
|
||||||
location = urlparse.urljoin(request.httprequest.path, location)
|
location = urlparse.urljoin(request.httprequest.path, location)
|
||||||
|
force_lang = lang is not None
|
||||||
lang = lang or request.context.get('lang')
|
lang = lang or request.context.get('lang')
|
||||||
langs = [lg[0] for lg in request.website.get_languages()]
|
langs = [lg[0] for lg in request.website.get_languages()]
|
||||||
if location[0] == '/' and len(langs) > 1 and lang != request.website.default_lang_code:
|
if lang != request.website.default_lang_code and (force_lang or (location[0] == '/' and len(langs) > 1)):
|
||||||
ps = location.split('/')
|
if is_multilang_url(location):
|
||||||
if ps[1] in langs:
|
ps = location.split('/')
|
||||||
ps[1] = lang
|
if ps[1] in langs:
|
||||||
else:
|
ps[1] = lang
|
||||||
ps.insert(1, lang)
|
else:
|
||||||
location = '/'.join(ps)
|
ps.insert(1, lang)
|
||||||
if keep_query:
|
location = '/'.join(ps)
|
||||||
url = urlparse.urlparse(location)
|
|
||||||
location = url.path
|
|
||||||
params = werkzeug.url_decode(url.query)
|
|
||||||
query_params = frozenset(werkzeug.url_decode(request.httprequest.query_string).keys())
|
|
||||||
for kq in keep_query:
|
|
||||||
for param in fnmatch.filter(query_params, kq):
|
|
||||||
params[param] = request.params[param]
|
|
||||||
params = werkzeug.urls.url_encode(params)
|
|
||||||
if params:
|
|
||||||
location += '?%s' % params
|
|
||||||
|
|
||||||
return location
|
return location
|
||||||
|
|
||||||
|
def is_multilang_url(path):
|
||||||
|
try:
|
||||||
|
router = request.httprequest.app.get_db_router(request.db).bind('')
|
||||||
|
func = router.match(path)[0]
|
||||||
|
return func.routing.get('multilang', False)
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
|
|
||||||
def slugify(s, max_length=None):
|
def slugify(s, max_length=None):
|
||||||
if slugify_lib:
|
if slugify_lib:
|
||||||
return slugify_lib.slugify(s, max_length)
|
return slugify_lib.slugify(s, max_length)
|
||||||
|
@ -229,6 +239,7 @@ class website(osv.osv):
|
||||||
json=simplejson,
|
json=simplejson,
|
||||||
website=request.website,
|
website=request.website,
|
||||||
url_for=url_for,
|
url_for=url_for,
|
||||||
|
keep_query=keep_query,
|
||||||
slug=slug,
|
slug=slug,
|
||||||
res_company=request.website.company_id,
|
res_company=request.website.company_id,
|
||||||
user_id=user.browse(cr, uid, uid),
|
user_id=user.browse(cr, uid, uid),
|
||||||
|
|
|
@ -114,7 +114,7 @@
|
||||||
<ul class="dropdown-menu js_usermenu" role="menu">
|
<ul class="dropdown-menu js_usermenu" role="menu">
|
||||||
<li><a href="/web" role="menuitem">Administration</a></li>
|
<li><a href="/web" role="menuitem">Administration</a></li>
|
||||||
<li class="divider"/>
|
<li class="divider"/>
|
||||||
<li><a t-attf-href="/web/session/logout?redirect=#{ quote_plus(url_for('', keep_query='*')) }" role="menuitem">Logout</a></li>
|
<li><a t-attf-href="/web/session/logout?redirect=/" role="menuitem">Logout</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -171,13 +171,13 @@
|
||||||
<t t-set="languages" t-value="website.get_languages()"/>
|
<t t-set="languages" t-value="website.get_languages()"/>
|
||||||
<ul class="list-inline js_language_selector mt16" t-if="(len(languages) > 1 or editable)">
|
<ul class="list-inline js_language_selector mt16" t-if="(len(languages) > 1 or editable)">
|
||||||
<li t-foreach="languages" t-as="lg">
|
<li t-foreach="languages" t-as="lg">
|
||||||
<a t-att-href="url_for('', lang=lg[0], keep_query='*')"
|
<a t-att-href="url_for('', lang=lg[0]) + '?' + keep_query()"
|
||||||
t-att-data-default-lang="editable and 'true' if lg[0] == website.default_lang_code else None">
|
t-att-data-default-lang="editable and 'true' if lg[0] == website.default_lang_code else None">
|
||||||
<t t-esc="lg[1].split('/').pop()"/>
|
<t t-esc="lg[1].split('/').pop()"/>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li groups="base.group_website_publisher">
|
<li groups="base.group_website_publisher">
|
||||||
<t t-set="url_return" t-value="url_for(request.httprequest.path, '[lang]', keep_query='*')"/>
|
<t t-set="url_return" t-value="url_for('', '[lang]') + '?' + keep_query()"/>
|
||||||
<a t-attf-href="/web#action=base.action_view_base_language_install&website_id=#{website.id}&url_return=#{url_return}">
|
<a t-attf-href="/web#action=base.action_view_base_language_install&website_id=#{website.id}&url_return=#{url_return}">
|
||||||
<i class="fa fa-plus-circle"/>
|
<i class="fa fa-plus-circle"/>
|
||||||
Add a language...
|
Add a language...
|
||||||
|
|
|
@ -136,7 +136,7 @@
|
||||||
<ul class="nav nav-pills nav-stacked">
|
<ul class="nav nav-pills nav-stacked">
|
||||||
<t t-foreach="dates" t-as="date">
|
<t t-foreach="dates" t-as="date">
|
||||||
<li t-att-class="searches.get('date') == date[0] and 'active' or ''" t-if="date[3] or (date[0] in ('old','all'))">
|
<li t-att-class="searches.get('date') == date[0] and 'active' or ''" t-if="date[3] or (date[0] in ('old','all'))">
|
||||||
<a t-href="/event/?date=#{ date[0] }" t-keep-query="country,type"><t t-esc="date[1]"/>
|
<a t-href="/event/?{{ keep_query('country', 'type', date=date[0] }}"><t t-esc="date[1]"/>
|
||||||
<span t-if="date[3]" class="badge pull-right"><t t-esc="date[3]"/></span>
|
<span t-if="date[3]" class="badge pull-right"><t t-esc="date[3]"/></span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
@ -151,7 +151,7 @@
|
||||||
<ul class="nav nav-pills nav-stacked mt32">
|
<ul class="nav nav-pills nav-stacked mt32">
|
||||||
<t t-foreach="types">
|
<t t-foreach="types">
|
||||||
<li t-if="type" t-att-class="searches.get('type') == str(type and type[0]) and 'active' or ''">
|
<li t-if="type" t-att-class="searches.get('type') == str(type and type[0]) and 'active' or ''">
|
||||||
<a t-href="/event/?type=#{ type[0] }" t-keep-query="country,date"><t t-esc="type[1]"/>
|
<a t-href="/event/?{{ keep_query('country', 'date', type=type[0] }}"><t t-esc="type[1]"/>
|
||||||
<span class="badge pull-right"><t t-esc="type_count"/></span>
|
<span class="badge pull-right"><t t-esc="type_count"/></span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
@ -164,7 +164,7 @@
|
||||||
<ul class="nav nav-pills nav-stacked mt32">
|
<ul class="nav nav-pills nav-stacked mt32">
|
||||||
<t t-foreach="countries">
|
<t t-foreach="countries">
|
||||||
<li t-if="country_id" t-att-class="searches.get('country') == str(country_id and country_id[0]) and 'active' or ''">
|
<li t-if="country_id" t-att-class="searches.get('country') == str(country_id and country_id[0]) and 'active' or ''">
|
||||||
<a t-href="/event/?country=#{ country_id[0] }" t-keep-query="type,date"><t t-esc="country_id[1]"/>
|
<a t-href="/event/?{{ keep_query('type', 'data', country=country_id[0] }}"><t t-esc="country_id[1]"/>
|
||||||
<span class="badge pull-right"><t t-esc="country_id_count"/></span>
|
<span class="badge pull-right"><t t-esc="country_id_count"/></span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
@ -54,12 +54,12 @@
|
||||||
<div class="ribbon btn btn-danger">Sale</div>
|
<div class="ribbon btn btn-danger">Sale</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="oe_product_image">
|
<div class="oe_product_image">
|
||||||
<a t-href="/shop/product/#{ slug(product) }/" t-keep-query="category,search,filters">
|
<a t-href="/shop/product/{{ slug(product) }}/?{{ keep_query('category', 'search', 'filters') }}">
|
||||||
<span t-field="product.image" t-field-options='{"widget": "image"}'/>
|
<span t-field="product.image" t-field-options='{"widget": "image"}'/>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<section>
|
<section>
|
||||||
<h5><strong><a t-href="/shop/product/#{ slug(product) }/" t-keep-query="category,search,filters" t-field="product.name"/></strong></h5>
|
<h5><strong><a t-href="/shop/product/{{ slug(product) }}/?{{ keep_query('category', 'search', 'filters') }}" t-field="product.name"/></strong></h5>
|
||||||
<div class="product_price" t-if="product.product_variant_ids">
|
<div class="product_price" t-if="product.product_variant_ids">
|
||||||
<b>
|
<b>
|
||||||
<t t-if="abs(product.product_variant_ids[0].lst_price - product.product_variant_ids[0].price) > 0.2">
|
<t t-if="abs(product.product_variant_ids[0].lst_price - product.product_variant_ids[0].price) > 0.2">
|
||||||
|
@ -272,8 +272,8 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-4">
|
<div class="col-sm-4">
|
||||||
<ol class="breadcrumb">
|
<ol class="breadcrumb">
|
||||||
<li><a href="/shop" t-keep-query="search,filters" onclick="history.go(-1); return false;">Products</a></li>
|
<li><a t-attf-href="/shop?{{ keep_query('search', 'filters') }}" onclick="history.go(-1); return false;">Products</a></li>
|
||||||
<li t-if="search.get('category')"><a t-href="/shop/" t-keep-query="category,search,filters"><span t-field="category.name"/></a></li>
|
<li t-if="search.get('category')"><a t-attf-href="/shop/?{{ keep_query('search', 'filters', 'category') }}" t-field="category.name"/></li>
|
||||||
<li class="active"><span t-field="product.name"/></li>
|
<li class="active"><span t-field="product.name"/></li>
|
||||||
</ol>
|
</ol>
|
||||||
</div>
|
</div>
|
||||||
|
@ -580,7 +580,7 @@
|
||||||
|
|
||||||
<template id="products_characteristics" inherit_id="website_sale.products" inherit_option_id="website_sale.products" name="Product Characteristic's Filters" groups="product.group_product_characteristics">
|
<template id="products_characteristics" inherit_id="website_sale.products" inherit_option_id="website_sale.products" name="Product Characteristic's Filters" groups="product.group_product_characteristics">
|
||||||
<xpath expr="//div[@id='products_grid_before']" position="inside">
|
<xpath expr="//div[@id='products_grid_before']" position="inside">
|
||||||
<form t-action="/shop/filters/" class="characteristics" method="post" t-keep-query="category,search">
|
<form t-attf-action="/shop/filters/?{{ keep_query('category', 'search') }}" class="characteristics" method="post">
|
||||||
<ul class="nav nav-pills nav-stacked mt16">
|
<ul class="nav nav-pills nav-stacked mt16">
|
||||||
<t t-set="characteristic_ids" t-value="Ecommerce.get_characteristic_ids()"/>
|
<t t-set="characteristic_ids" t-value="Ecommerce.get_characteristic_ids()"/>
|
||||||
<t t-foreach="characteristic_ids" t-as="characteristic_id">
|
<t t-foreach="characteristic_ids" t-as="characteristic_id">
|
||||||
|
|
Loading…
Reference in New Issue