[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 = {
|
||||
'form': 'action',
|
||||
'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
|
||||
if request and 'url_for' in context:
|
||||
router = request.httprequest.app.get_db_router(request.db).bind('')
|
||||
if request.website:
|
||||
for tag, attr in self.URL_ATTRS.items():
|
||||
for e in node.getElementsByTagName(tag):
|
||||
url = e.getAttribute(attr)
|
||||
if url:
|
||||
try:
|
||||
func = router.match(url)[0]
|
||||
if func.multilang:
|
||||
e.setAttribute(attr, context['url_for'](url))
|
||||
except Exception, e:
|
||||
pass
|
||||
super(QWeb, self).add_template(into, name, node, context)
|
||||
e.setAttribute(attr, qcontext.get('url_for')(url))
|
||||
super(QWeb, self).add_template(qcontext, name, node)
|
||||
|
||||
def render_att_att(self, element, attribute_name, attribute_value, qwebcontext):
|
||||
att, val = super(QWeb, self).render_att_att(element, attribute_name, attribute_value, qwebcontext)
|
||||
|
||||
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):
|
||||
return self.pool.get(
|
||||
|
|
|
@ -25,34 +25,44 @@ from openerp.addons.web.http import request, LazyResponse
|
|||
|
||||
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()
|
||||
url = urlparse.urlparse(location)
|
||||
if request and not url.netloc and not url.scheme:
|
||||
location = urlparse.urljoin(request.httprequest.path, location)
|
||||
force_lang = lang is not None
|
||||
lang = lang or request.context.get('lang')
|
||||
langs = [lg[0] for lg in request.website.get_languages()]
|
||||
if location[0] == '/' and len(langs) > 1 and lang != request.website.default_lang_code:
|
||||
ps = location.split('/')
|
||||
if ps[1] in langs:
|
||||
ps[1] = lang
|
||||
else:
|
||||
ps.insert(1, lang)
|
||||
location = '/'.join(ps)
|
||||
if keep_query:
|
||||
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
|
||||
if lang != request.website.default_lang_code and (force_lang or (location[0] == '/' and len(langs) > 1)):
|
||||
if is_multilang_url(location):
|
||||
ps = location.split('/')
|
||||
if ps[1] in langs:
|
||||
ps[1] = lang
|
||||
else:
|
||||
ps.insert(1, lang)
|
||||
location = '/'.join(ps)
|
||||
|
||||
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):
|
||||
if slugify_lib:
|
||||
return slugify_lib.slugify(s, max_length)
|
||||
|
@ -229,6 +239,7 @@ class website(osv.osv):
|
|||
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),
|
||||
|
|
|
@ -114,7 +114,7 @@
|
|||
<ul class="dropdown-menu js_usermenu" role="menu">
|
||||
<li><a href="/web" role="menuitem">Administration</a></li>
|
||||
<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>
|
||||
</li>
|
||||
</ul>
|
||||
|
@ -171,13 +171,13 @@
|
|||
<t t-set="languages" t-value="website.get_languages()"/>
|
||||
<ul class="list-inline js_language_selector mt16" t-if="(len(languages) > 1 or editable)">
|
||||
<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 t-esc="lg[1].split('/').pop()"/>
|
||||
</a>
|
||||
</li>
|
||||
<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}">
|
||||
<i class="fa fa-plus-circle"/>
|
||||
Add a language...
|
||||
|
|
|
@ -136,7 +136,7 @@
|
|||
<ul class="nav nav-pills nav-stacked">
|
||||
<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'))">
|
||||
<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>
|
||||
</a>
|
||||
</li>
|
||||
|
@ -151,7 +151,7 @@
|
|||
<ul class="nav nav-pills nav-stacked mt32">
|
||||
<t t-foreach="types">
|
||||
<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>
|
||||
</a>
|
||||
</li>
|
||||
|
@ -164,7 +164,7 @@
|
|||
<ul class="nav nav-pills nav-stacked mt32">
|
||||
<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 ''">
|
||||
<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>
|
||||
</a>
|
||||
</li>
|
||||
|
|
|
@ -54,12 +54,12 @@
|
|||
<div class="ribbon btn btn-danger">Sale</div>
|
||||
</div>
|
||||
<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"}'/>
|
||||
</a>
|
||||
</div>
|
||||
<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">
|
||||
<b>
|
||||
<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="col-sm-4">
|
||||
<ol class="breadcrumb">
|
||||
<li><a href="/shop" t-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><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-attf-href="/shop/?{{ keep_query('search', 'filters', 'category') }}" t-field="category.name"/></li>
|
||||
<li class="active"><span t-field="product.name"/></li>
|
||||
</ol>
|
||||
</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">
|
||||
<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">
|
||||
<t t-set="characteristic_ids" t-value="Ecommerce.get_characteristic_ids()"/>
|
||||
<t t-foreach="characteristic_ids" t-as="characteristic_id">
|
||||
|
|
Loading…
Reference in New Issue